Sierra Toolkit  Version of the Day
type_properties_eastl.h
1 /*
2 Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 
8 1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of
14  its contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
30 // EASTL/internal/type_properties.h
31 // Written and maintained by Paul Pedriana - 2005.
33 
34 
35 #ifndef EASTL_INTERNAL_TYPE_PROPERTIES_H
36 #define EASTL_INTERNAL_TYPE_PROPERTIES_H
37 
38 
39 #include <limits.h>
40 
41 
42 namespace eastl
43 {
44 
45  // The following properties or relations are defined here. If the given
46  // item is missing then it simply hasn't been implemented, at least not yet.
47 
49  // is_const
50  //
51  // is_const<T>::value == true if and only if T has const-qualification.
52  //
54  template <typename T> struct is_const_value : public false_type{};
55  template <typename T> struct is_const_value<const T*> : public true_type{};
56  template <typename T> struct is_const_value<const volatile T*> : public true_type{};
57 
58  template <typename T> struct is_const : public is_const_value<T*>{};
59  template <typename T> struct is_const<T&> : public false_type{}; // Note here that T is const, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard.
60 
61 
62 
64  // is_volatile
65  //
66  // is_volatile<T>::value == true if and only if T has volatile-qualification.
67  //
69 
70  template <typename T> struct is_volatile_value : public false_type{};
71  template <typename T> struct is_volatile_value<volatile T*> : public true_type{};
72  template <typename T> struct is_volatile_value<const volatile T*> : public true_type{};
73 
74  template <typename T> struct is_volatile : public is_volatile_value<T*>{};
75  template <typename T> struct is_volatile<T&> : public false_type{}; // Note here that T is volatile, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard.
76 
77 
78 
80  // is_abstract
81  //
82  // is_abstract<T>::value == true if and only if T is a class or struct
83  // that has at least one pure virtual function. is_abstract may only
84  // be applied to complete types.
85  //
87 
88  // Not implemented yet.
89 
90 
91 
93  // is_signed
94  //
95  // is_signed<T>::value == true if and only if T is one of the following types:
96  // [const] [volatile] char (maybe)
97  // [const] [volatile] signed char
98  // [const] [volatile] short
99  // [const] [volatile] int
100  // [const] [volatile] long
101  // [const] [volatile] long long
102  //
103  // Used to determine if a integral type is signed or unsigned.
104  // Given that there are some user-made classes which emulate integral
105  // types, we provide the EASTL_DECLARE_SIGNED macro to allow you to
106  // set a given class to be identified as a signed type.
108  template <typename T> struct is_signed : public false_type{};
109 
110  template <> struct is_signed<signed char> : public true_type{};
111  template <> struct is_signed<const signed char> : public true_type{};
112  template <> struct is_signed<signed short> : public true_type{};
113  template <> struct is_signed<const signed short> : public true_type{};
114  template <> struct is_signed<signed int> : public true_type{};
115  template <> struct is_signed<const signed int> : public true_type{};
116  template <> struct is_signed<signed long> : public true_type{};
117  template <> struct is_signed<const signed long> : public true_type{};
118  template <> struct is_signed<signed long long> : public true_type{};
119  template <> struct is_signed<const signed long long> : public true_type{};
120 
121  #if (CHAR_MAX == SCHAR_MAX)
122  template <> struct is_signed<char> : public true_type{};
123  template <> struct is_signed<const char> : public true_type{};
124  #endif
125  #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
126  #if defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 2147483647) || (__WCHAR_MAX__ == 32767)) // GCC defines __WCHAR_MAX__ for most platforms.
127  template <> struct is_signed<wchar_t> : public true_type{};
128  template <> struct is_signed<const wchar_t> : public true_type{};
129  #endif
130  #endif
131 
132  #define EASTL_DECLARE_SIGNED(T) namespace eastl{ template <> struct is_signed<T> : public true_type{}; template <> struct is_signed<const T> : public true_type{}; }
133 
134 
135 
137  // is_unsigned
138  //
139  // is_unsigned<T>::value == true if and only if T is one of the following types:
140  // [const] [volatile] char (maybe)
141  // [const] [volatile] unsigned char
142  // [const] [volatile] unsigned short
143  // [const] [volatile] unsigned int
144  // [const] [volatile] unsigned long
145  // [const] [volatile] unsigned long long
146  //
147  // Used to determine if a integral type is signed or unsigned.
148  // Given that there are some user-made classes which emulate integral
149  // types, we provide the EASTL_DECLARE_UNSIGNED macro to allow you to
150  // set a given class to be identified as an unsigned type.
152  template <typename T> struct is_unsigned : public false_type{};
153 
154  template <> struct is_unsigned<unsigned char> : public true_type{};
155  template <> struct is_unsigned<const unsigned char> : public true_type{};
156  template <> struct is_unsigned<unsigned short> : public true_type{};
157  template <> struct is_unsigned<const unsigned short> : public true_type{};
158  template <> struct is_unsigned<unsigned int> : public true_type{};
159  template <> struct is_unsigned<const unsigned int> : public true_type{};
160  template <> struct is_unsigned<unsigned long> : public true_type{};
161  template <> struct is_unsigned<const unsigned long> : public true_type{};
162  template <> struct is_unsigned<unsigned long long> : public true_type{};
163  template <> struct is_unsigned<const unsigned long long> : public true_type{};
164 
165  #if (CHAR_MAX == UCHAR_MAX)
166  template <> struct is_unsigned<char> : public true_type{};
167  template <> struct is_unsigned<const char> : public true_type{};
168  #endif
169  #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
170  #if defined(_MSC_VER) || (defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 4294967295U) || (__WCHAR_MAX__ == 65535))) // GCC defines __WCHAR_MAX__ for most platforms.
171  template <> struct is_unsigned<wchar_t> : public true_type{};
172  template <> struct is_unsigned<const wchar_t> : public true_type{};
173  #endif
174  #endif
175 
176  #define EASTL_DECLARE_UNSIGNED(T) namespace eastl{ template <> struct is_unsigned<T> : public true_type{}; template <> struct is_unsigned<const T> : public true_type{}; }
177 
178 
179 
181  // alignment_of
182  //
183  // alignment_of<T>::value is an integral value representing, in bytes,
184  // the memory alignment of objects of type T.
185  //
186  // alignment_of may only be applied to complete types.
187  //
189  template <typename T>
190  struct alignment_of_value{ static const size_t value = EASTL_ALIGN_OF(T); };
191 
192  template <typename T>
193  struct alignment_of : public integral_constant<size_t, alignment_of_value<T>::value>{};
194 
195 
196 
198  // is_aligned
199  //
200  // Defined as true if the type has alignment requirements greater
201  // than default alignment, which is taken to be 8. This allows for
202  // doing specialized object allocation and placement for such types.
204  template <typename T>
205  struct is_aligned_value{ static const bool value = (EASTL_ALIGN_OF(T) > 8); };
206 
207  template <typename T>
208  struct is_aligned : public integral_constant<bool, is_aligned_value<T>::value>{};
209 
210 
211 
213  // rank
214  //
215  // rank<T>::value is an integral value representing the number of
216  // dimensions possessed by an array type. For example, given a
217  // multi-dimensional array type T[M][N], std::tr1::rank<T[M][N]>::value == 2.
218  // For a given non-array type T, std::tr1::rank<T>::value == 0.
219  //
221 
222  // Not implemented yet.
223 
224 
225 
227  // extent
228  //
229  // extent<T, I>::value is an integral type representing the number of
230  // elements in the Ith dimension of array type T.
231  //
232  // For a given array type T[N], std::tr1::extent<T[N]>::value == N.
233  // For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 0>::value == N.
234  // For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 1>::value == M.
235  // For a given array type T and a given dimension I where I >= rank<T>::value, std::tr1::extent<T, I>::value == 0.
236  // For a given array type of unknown extent T[], std::tr1::extent<T[], 0>::value == 0.
237  // For a given non-array type T and an arbitrary dimension I, std::tr1::extent<T, I>::value == 0.
238  //
240 
241  // Not implemented yet.
242 
243 
244 
246  // is_base_of
247  //
248  // Given two (possibly identical) types Base and Derived, is_base_of<Base, Derived>::value == true
249  // if and only if Base is a direct or indirect base class of Derived,
250  // or Base and Derived are the same type.
251  //
252  // is_base_of may only be applied to complete types.
253  //
255 
256  // Not implemented yet.
257 
258 
259 
260 } // namespace eastl
261 
262 
263 #endif // Header include guard
EA Standard Template Library.