|
Sierra Toolkit
Version of the Day
|
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_transformations.h 00031 // Written and maintained by Paul Pedriana - 2005 00033 00034 00035 #ifndef EASTL_INTERNAL_TYPE_TRANFORMATIONS_H 00036 #define EASTL_INTERNAL_TYPE_TRANFORMATIONS_H 00037 00038 00039 namespace eastl 00040 { 00041 00042 00043 // The following transformations are defined here. If the given item 00044 // is missing then it simply hasn't been implemented, at least not yet. 00045 // add_unsigned 00046 // add_signed 00047 // remove_const 00048 // remove_volatile 00049 // remove_cv 00050 // add_const 00051 // add_volatile 00052 // add_cv 00053 // remove_reference 00054 // add_reference 00055 // remove_extent 00056 // remove_all_extents 00057 // remove_pointer 00058 // add_pointer 00059 // aligned_storage 00060 00061 00063 // add_signed 00064 // 00065 // Adds signed-ness to the given type. 00066 // Modifies only integral values; has no effect on others. 00067 // add_signed<int>::type is int 00068 // add_signed<unsigned int>::type is int 00069 // 00071 00072 template<class T> 00073 struct add_signed 00074 { typedef T type; }; 00075 00076 template<> 00077 struct add_signed<unsigned char> 00078 { typedef signed char type; }; 00079 00080 #if (defined(CHAR_MAX) && defined(UCHAR_MAX) && (CHAR_MAX == UCHAR_MAX)) // If char is unsigned (which is usually not the case)... 00081 template<> 00082 struct add_signed<char> 00083 { typedef signed char type; }; 00084 #endif 00085 00086 template<> 00087 struct add_signed<unsigned short> 00088 { typedef short type; }; 00089 00090 template<> 00091 struct add_signed<unsigned int> 00092 { typedef int type; }; 00093 00094 template<> 00095 struct add_signed<unsigned long> 00096 { typedef long type; }; 00097 00098 template<> 00099 struct add_signed<unsigned long long> 00100 { typedef long long type; }; 00101 00102 #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 00103 #if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 4294967295U)) // If wchar_t is a 32 bit unsigned value... 00104 template<> 00105 struct add_signed<wchar_t> 00106 { typedef int32_t type; }; 00107 #elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 65535)) // If wchar_t is a 16 bit unsigned value... 00108 template<> 00109 struct add_signed<wchar_t> 00110 { typedef int16_t type; }; 00111 #endif 00112 #endif 00113 00114 00115 00117 // add_unsigned 00118 // 00119 // Adds unsigned-ness to the given type. 00120 // Modifies only integral values; has no effect on others. 00121 // add_unsigned<int>::type is unsigned int 00122 // add_unsigned<unsigned int>::type is unsigned int 00123 // 00125 00126 template<class T> 00127 struct add_unsigned 00128 { typedef T type; }; 00129 00130 template<> 00131 struct add_unsigned<signed char> 00132 { typedef unsigned char type; }; 00133 00134 #if (defined(CHAR_MAX) && defined(SCHAR_MAX) && (CHAR_MAX == SCHAR_MAX)) // If char is signed (which is usually so)... 00135 template<> 00136 struct add_unsigned<char> 00137 { typedef unsigned char type; }; 00138 #endif 00139 00140 template<> 00141 struct add_unsigned<short> 00142 { typedef unsigned short type; }; 00143 00144 template<> 00145 struct add_unsigned<int> 00146 { typedef unsigned int type; }; 00147 00148 template<> 00149 struct add_unsigned<long> 00150 { typedef unsigned long type; }; 00151 00152 template<> 00153 struct add_unsigned<long long> 00154 { typedef unsigned long long type; }; 00155 00156 #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 00157 #if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 2147483647)) // If wchar_t is a 32 bit signed value... 00158 template<> 00159 struct add_unsigned<wchar_t> 00160 { typedef uint32_t type; }; 00161 #elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 32767)) // If wchar_t is a 16 bit signed value... 00162 template<> 00163 struct add_unsigned<wchar_t> 00164 { typedef uint16_t type; }; 00165 #endif 00166 #endif 00167 00169 // remove_cv 00170 // 00171 // Remove const and volatile from a type. 00172 // 00173 // The remove_cv transformation trait removes top-level const and/or volatile 00174 // qualification (if any) from the type to which it is applied. For a given type T, 00175 // remove_cv<T const volatile>::type is equivalent to T. For example, 00176 // remove_cv<char* volatile>::type is equivalent to char*, while remove_cv<const char*>::type 00177 // is equivalent to const char*. In the latter case, the const qualifier modifies 00178 // char, not *, and is therefore not at the top level. 00179 // 00181 template <typename T> struct remove_cv_imp{}; 00182 template <typename T> struct remove_cv_imp<T*> { typedef T unqualified_type; }; 00183 template <typename T> struct remove_cv_imp<const T*> { typedef T unqualified_type; }; 00184 template <typename T> struct remove_cv_imp<volatile T*> { typedef T unqualified_type; }; 00185 template <typename T> struct remove_cv_imp<const volatile T*> { typedef T unqualified_type; }; 00186 00187 template <typename T> struct remove_cv{ typedef typename remove_cv_imp<T*>::unqualified_type type; }; 00188 template <typename T> struct remove_cv<T&>{ typedef T& type; }; // References are automatically not const nor volatile. See section 8.3.2p1 of the C++ standard. 00189 00190 template <typename T, size_t N> struct remove_cv<T const[N]> { typedef T type[N]; }; 00191 template <typename T, size_t N> struct remove_cv<T volatile[N]> { typedef T type[N]; }; 00192 template <typename T, size_t N> struct remove_cv<T const volatile[N]>{ typedef T type[N]; }; 00193 00194 00195 00197 // add_reference 00198 // 00199 // Add reference to a type. 00200 // 00201 // The add_reference transformation trait adds a level of indirection 00202 // by reference to the type to which it is applied. For a given type T, 00203 // add_reference<T>::type is equivalent to T& if is_reference<T>::value == false, 00204 // and T otherwise. 00205 // 00207 template <typename T> 00208 struct add_reference_impl{ typedef T& type; }; 00209 00210 template <typename T> 00211 struct add_reference_impl<T&>{ typedef T& type; }; 00212 00213 template <> 00214 struct add_reference_impl<void>{ typedef void type; }; 00215 00216 template <typename T> 00217 struct add_reference { typedef typename add_reference_impl<T>::type type; }; 00218 00219 00220 } // namespace eastl 00221 00222 00223 #endif // Header include guard