Sierra Toolkit Version of the Day
type_properties_eastl.h
00001 /*
00002 Copyright (C) 2005,2009-2010 Electronic Arts, Inc.  All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions
00006 are met:
00007 
00008 1.  Redistributions of source code must retain the above copyright
00009     notice, this list of conditions and the following disclaimer.
00010 2.  Redistributions in binary form must reproduce the above copyright
00011     notice, this list of conditions and the following disclaimer in the
00012     documentation and/or other materials provided with the distribution.
00013 3.  Neither the name of Electronic Arts, Inc. ("EA") nor the names of
00014     its contributors may be used to endorse or promote products derived
00015     from this software without specific prior written permission.
00016 
00017 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
00018 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 */
00028 
00030 // EASTL/internal/type_properties.h
00031 // Written and maintained by Paul Pedriana - 2005.
00033 
00034 
00035 #ifndef EASTL_INTERNAL_TYPE_PROPERTIES_H
00036 #define EASTL_INTERNAL_TYPE_PROPERTIES_H
00037 
00038 
00039 #include <limits.h>
00040 
00041 
00042 namespace eastl
00043 {
00044 
00045     // The following properties or relations are defined here. If the given
00046     // item is missing then it simply hasn't been implemented, at least not yet.
00047 
00049     // is_const
00050     //
00051     // is_const<T>::value == true if and only if T has const-qualification.
00052     //
00054     template <typename T> struct is_const_value                    : public false_type{};
00055     template <typename T> struct is_const_value<const T*>          : public true_type{};
00056     template <typename T> struct is_const_value<const volatile T*> : public true_type{};
00057 
00058     template <typename T> struct is_const : public is_const_value<T*>{};
00059     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.
00060 
00061 
00062 
00064     // is_volatile
00065     //
00066     // is_volatile<T>::value == true  if and only if T has volatile-qualification.
00067     //
00069 
00070     template <typename T> struct is_volatile_value                    : public false_type{};
00071     template <typename T> struct is_volatile_value<volatile T*>       : public true_type{};
00072     template <typename T> struct is_volatile_value<const volatile T*> : public true_type{};
00073 
00074     template <typename T> struct is_volatile : public is_volatile_value<T*>{};
00075     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.
00076 
00077 
00078 
00080     // is_abstract
00081     //
00082     // is_abstract<T>::value == true if and only if T is a class or struct
00083     // that has at least one pure virtual function. is_abstract may only
00084     // be applied to complete types.
00085     //
00087 
00088     // Not implemented yet.
00089 
00090 
00091 
00093     // is_signed
00094     //
00095     // is_signed<T>::value == true if and only if T is one of the following types:
00096     //    [const] [volatile] char (maybe)
00097     //    [const] [volatile] signed char
00098     //    [const] [volatile] short
00099     //    [const] [volatile] int
00100     //    [const] [volatile] long
00101     //    [const] [volatile] long long
00102     //
00103     // Used to determine if a integral type is signed or unsigned.
00104     // Given that there are some user-made classes which emulate integral
00105     // types, we provide the EASTL_DECLARE_SIGNED macro to allow you to
00106     // set a given class to be identified as a signed type.
00108     template <typename T> struct is_signed : public false_type{};
00109 
00110     template <> struct is_signed<signed char>              : public true_type{};
00111     template <> struct is_signed<const signed char>        : public true_type{};
00112     template <> struct is_signed<signed short>             : public true_type{};
00113     template <> struct is_signed<const signed short>       : public true_type{};
00114     template <> struct is_signed<signed int>               : public true_type{};
00115     template <> struct is_signed<const signed int>         : public true_type{};
00116     template <> struct is_signed<signed long>              : public true_type{};
00117     template <> struct is_signed<const signed long>        : public true_type{};
00118     template <> struct is_signed<signed long long>         : public true_type{};
00119     template <> struct is_signed<const signed long long>   : public true_type{};
00120 
00121     #if (CHAR_MAX == SCHAR_MAX)
00122         template <> struct is_signed<char>            : public true_type{};
00123         template <> struct is_signed<const char>      : public true_type{};
00124     #endif
00125     #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
00126         #if defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 2147483647) || (__WCHAR_MAX__ == 32767)) // GCC defines __WCHAR_MAX__ for most platforms.
00127             template <> struct is_signed<wchar_t>         : public true_type{};
00128             template <> struct is_signed<const wchar_t>   : public true_type{};
00129         #endif
00130     #endif
00131 
00132     #define EASTL_DECLARE_SIGNED(T) namespace eastl{ template <> struct is_signed<T> : public true_type{}; template <> struct is_signed<const T> : public true_type{}; }
00133 
00134 
00135 
00137     // is_unsigned
00138     //
00139     // is_unsigned<T>::value == true if and only if T is one of the following types:
00140     //    [const] [volatile] char (maybe)
00141     //    [const] [volatile] unsigned char
00142     //    [const] [volatile] unsigned short
00143     //    [const] [volatile] unsigned int
00144     //    [const] [volatile] unsigned long
00145     //    [const] [volatile] unsigned long long
00146     //
00147     // Used to determine if a integral type is signed or unsigned.
00148     // Given that there are some user-made classes which emulate integral
00149     // types, we provide the EASTL_DECLARE_UNSIGNED macro to allow you to
00150     // set a given class to be identified as an unsigned type.
00152     template <typename T> struct is_unsigned : public false_type{};
00153 
00154     template <> struct is_unsigned<unsigned char>              : public true_type{};
00155     template <> struct is_unsigned<const unsigned char>        : public true_type{};
00156     template <> struct is_unsigned<unsigned short>             : public true_type{};
00157     template <> struct is_unsigned<const unsigned short>       : public true_type{};
00158     template <> struct is_unsigned<unsigned int>               : public true_type{};
00159     template <> struct is_unsigned<const unsigned int>         : public true_type{};
00160     template <> struct is_unsigned<unsigned long>              : public true_type{};
00161     template <> struct is_unsigned<const unsigned long>        : public true_type{};
00162     template <> struct is_unsigned<unsigned long long>         : public true_type{};
00163     template <> struct is_unsigned<const unsigned long long>   : public true_type{};
00164 
00165     #if (CHAR_MAX == UCHAR_MAX)
00166         template <> struct is_unsigned<char>            : public true_type{};
00167         template <> struct is_unsigned<const char>      : public true_type{};
00168     #endif
00169     #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type...
00170         #if defined(_MSC_VER) || (defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 4294967295U) || (__WCHAR_MAX__ == 65535))) // GCC defines __WCHAR_MAX__ for most platforms.
00171             template <> struct is_unsigned<wchar_t>         : public true_type{};
00172             template <> struct is_unsigned<const wchar_t>   : public true_type{};
00173         #endif
00174     #endif
00175 
00176     #define EASTL_DECLARE_UNSIGNED(T) namespace eastl{ template <> struct is_unsigned<T> : public true_type{}; template <> struct is_unsigned<const T> : public true_type{}; }
00177 
00178 
00179 
00181     // alignment_of
00182     //
00183     // alignment_of<T>::value is an integral value representing, in bytes,
00184     // the memory alignment of objects of type T.
00185     //
00186     // alignment_of may only be applied to complete types.
00187     //
00189     template <typename T>
00190     struct alignment_of_value{ static const size_t value = EASTL_ALIGN_OF(T); };
00191 
00192     template <typename T>
00193     struct alignment_of : public integral_constant<size_t, alignment_of_value<T>::value>{};
00194 
00195 
00196 
00198     // is_aligned
00199     //
00200     // Defined as true if the type has alignment requirements greater
00201     // than default alignment, which is taken to be 8. This allows for
00202     // doing specialized object allocation and placement for such types.
00204     template <typename T>
00205     struct is_aligned_value{ static const bool value = (EASTL_ALIGN_OF(T) > 8); };
00206 
00207     template <typename T>
00208     struct is_aligned : public integral_constant<bool, is_aligned_value<T>::value>{};
00209 
00210 
00211 
00213     // rank
00214     //
00215     // rank<T>::value is an integral value representing the number of
00216     // dimensions possessed by an array type. For example, given a
00217     // multi-dimensional array type T[M][N], std::tr1::rank<T[M][N]>::value == 2.
00218     // For a given non-array type T, std::tr1::rank<T>::value == 0.
00219     //
00221 
00222     // Not implemented yet.
00223 
00224 
00225 
00227     // extent
00228     //
00229     // extent<T, I>::value is an integral type representing the number of
00230     // elements in the Ith dimension of array type T.
00231     //
00232     // For a given array type T[N], std::tr1::extent<T[N]>::value == N.
00233     // For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 0>::value == N.
00234     // For a given multi-dimensional array type T[M][N], std::tr1::extent<T[M][N], 1>::value == M.
00235     // For a given array type T and a given dimension I where I >= rank<T>::value, std::tr1::extent<T, I>::value == 0.
00236     // For a given array type of unknown extent T[], std::tr1::extent<T[], 0>::value == 0.
00237     // For a given non-array type T and an arbitrary dimension I, std::tr1::extent<T, I>::value == 0.
00238     //
00240 
00241     // Not implemented yet.
00242 
00243 
00244 
00246     // is_base_of
00247     //
00248     // Given two (possibly identical) types Base and Derived, is_base_of<Base, Derived>::value == true
00249     // if and only if Base is a direct or indirect base class of Derived,
00250     // or Base and Derived are the same type.
00251     //
00252     // is_base_of may only be applied to complete types.
00253     //
00255 
00256     // Not implemented yet.
00257 
00258 
00259 
00260 } // namespace eastl
00261 
00262 
00263 #endif // Header include guard
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines