Sierra Toolkit  Version of the Day
TypeUtil.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2006 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
16 #ifndef STK_UTIL_UTIL_TypeUtil_hpp
17 #define STK_UTIL_UTIL_TypeUtil_hpp
18 
24 namespace sierra {
25 
26 //-----------------------------------
27 
28 template<typename T> struct IsFundamentalType ;
29 
30 template<> struct IsFundamentalType< char> { enum { value = true }; };
31 template<> struct IsFundamentalType<unsigned char> { enum { value = true }; };
32 template<> struct IsFundamentalType<signed char> { enum { value = true }; };
33 
34 template<> struct IsFundamentalType<short> { enum { value = true }; };
35 template<> struct IsFundamentalType<int> { enum { value = true }; };
36 template<> struct IsFundamentalType<long> { enum { value = true }; };
37 
38 template<> struct IsFundamentalType<unsigned short> { enum { value = true }; };
39 template<> struct IsFundamentalType<unsigned int> { enum { value = true }; };
40 template<> struct IsFundamentalType<unsigned long> { enum { value = true }; };
41 
42 template<> struct IsFundamentalType<float> { enum { value = true }; };
43 template<> struct IsFundamentalType<double> { enum { value = true }; };
44 
45 template<typename T> struct IsFundamentalType { enum { value = false }; };
46 
47 //-----------------------------------
48 
49 template<typename T>
50 class TypeTraits
51 {
52 public: //private:
53  template <class U> struct Traits
54  {
55  enum {is_pointer = false};
56  enum {is_reference = false};
57  typedef U Type;
58  };
59 
60  template <class U> struct Traits<U*>
61  {
62  enum {is_pointer = true};
63  enum {is_reference = false};
64  typedef U Type;
65  };
66 
67  template <class U> struct Traits<U&>
68  {
69  enum {is_pointer = false};
70  enum {is_reference = true};
71  typedef U Type;
72  };
73 
74  template <class U> struct ConstTraits
75  {
76  enum {is_const = false};
77  typedef U Type;
78  };
79 
80  template <class U> struct ConstTraits<const U>
81  {
82  enum {is_const = true};
83  typedef U Type;
84  };
85 
86 public:
87  enum {isPointer = Traits<T>::is_pointer};
88  enum {isReference = Traits<T>::is_reference};
89  enum {isConst = ConstTraits<T>::is_const};
90  typedef typename Traits<T>::Type BaseType;
91 };
92 
93 } // namespace sierra
94 
95 #endif // STK_UTIL_UTIL_TypeUtil_hpp
Definition: Env.cpp:53