|
Sierra Toolkit
Version of the Day
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright 2006 Sandia Corporation. */ 00003 /* Under the terms of Contract DE-AC04-94AL85000, there is a */ 00004 /* non-exclusive license for use of this work by or on behalf */ 00005 /* of the U.S. Government. Export of this program may require */ 00006 /* a license from the United States Government. */ 00007 /*--------------------------------------------------------------------*/ 00016 #ifndef STK_UTIL_UTIL_TypeUtil_hpp 00017 #define STK_UTIL_UTIL_TypeUtil_hpp 00018 00024 namespace sierra { 00025 00026 //----------------------------------- 00027 00028 template<typename T> struct IsFundamentalType ; 00029 00030 template<> struct IsFundamentalType< char> { enum { value = true }; }; 00031 template<> struct IsFundamentalType<unsigned char> { enum { value = true }; }; 00032 template<> struct IsFundamentalType<signed char> { enum { value = true }; }; 00033 00034 template<> struct IsFundamentalType<short> { enum { value = true }; }; 00035 template<> struct IsFundamentalType<int> { enum { value = true }; }; 00036 template<> struct IsFundamentalType<long> { enum { value = true }; }; 00037 00038 template<> struct IsFundamentalType<unsigned short> { enum { value = true }; }; 00039 template<> struct IsFundamentalType<unsigned int> { enum { value = true }; }; 00040 template<> struct IsFundamentalType<unsigned long> { enum { value = true }; }; 00041 00042 template<> struct IsFundamentalType<float> { enum { value = true }; }; 00043 template<> struct IsFundamentalType<double> { enum { value = true }; }; 00044 00045 template<typename T> struct IsFundamentalType { enum { value = false }; }; 00046 00047 //----------------------------------- 00048 00049 template<typename T> 00050 class TypeTraits 00051 { 00052 public: //private: 00053 template <class U> struct Traits 00054 { 00055 enum {is_pointer = false}; 00056 enum {is_reference = false}; 00057 typedef U Type; 00058 }; 00059 00060 template <class U> struct Traits<U*> 00061 { 00062 enum {is_pointer = true}; 00063 enum {is_reference = false}; 00064 typedef U Type; 00065 }; 00066 00067 template <class U> struct Traits<U&> 00068 { 00069 enum {is_pointer = false}; 00070 enum {is_reference = true}; 00071 typedef U Type; 00072 }; 00073 00074 template <class U> struct ConstTraits 00075 { 00076 enum {is_const = false}; 00077 typedef U Type; 00078 }; 00079 00080 template <class U> struct ConstTraits<const U> 00081 { 00082 enum {is_const = true}; 00083 typedef U Type; 00084 }; 00085 00086 public: 00087 enum {isPointer = Traits<T>::is_pointer}; 00088 enum {isReference = Traits<T>::is_reference}; 00089 enum {isConst = ConstTraits<T>::is_const}; 00090 typedef typename Traits<T>::Type BaseType; 00091 }; 00092 00093 } // namespace sierra 00094 00095 #endif // STK_UTIL_UTIL_TypeUtil_hpp