00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: stlsoft/util/sign_traits.hpp 00003 * 00004 * Purpose: sign_traits classes. 00005 * 00006 * Created: 16th January 2002 00007 * Updated: 10th August 2009 00008 * 00009 * Home: http://stlsoft.org/ 00010 * 00011 * Copyright (c) 2002-2009, Matthew Wilson and Synesis Software 00012 * All rights reserved. 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions are met: 00016 * 00017 * - Redistributions of source code must retain the above copyright notice, this 00018 * list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of 00023 * any contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 * POSSIBILITY OF SUCH DAMAGE. 00037 * 00038 * ////////////////////////////////////////////////////////////////////// */ 00039 00040 00047 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_SIGN_TRAITS 00048 #define STLSOFT_INCL_STLSOFT_UTIL_HPP_SIGN_TRAITS 00049 00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00051 # define STLSOFT_VER_STLSOFT_UTIL_HPP_SIGN_TRAITS_MAJOR 4 00052 # define STLSOFT_VER_STLSOFT_UTIL_HPP_SIGN_TRAITS_MINOR 1 00053 # define STLSOFT_VER_STLSOFT_UTIL_HPP_SIGN_TRAITS_REVISION 2 00054 # define STLSOFT_VER_STLSOFT_UTIL_HPP_SIGN_TRAITS_EDIT 46 00055 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00056 00057 /* ///////////////////////////////////////////////////////////////////////// 00058 * Includes 00059 */ 00060 00061 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT 00062 # include <stlsoft/stlsoft.h> 00063 #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */ 00064 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_SIZE_TRAITS 00065 # include <stlsoft/util/size_traits.hpp> 00066 #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_SIZE_TRAITS */ 00067 00068 /* ///////////////////////////////////////////////////////////////////////// 00069 * Namespace 00070 */ 00071 00072 #ifndef _STLSOFT_NO_NAMESPACE 00073 namespace stlsoft 00074 { 00075 #endif /* _STLSOFT_NO_NAMESPACE */ 00076 00077 /* ///////////////////////////////////////////////////////////////////////// 00078 * Classes 00079 */ 00080 00081 // struct sign_traits 00082 00083 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION 00084 00100 template <ss_typename_param_k T> 00101 struct sign_traits 00102 { 00103 enum 00104 { 00105 bytes = 0 00106 }; 00107 enum 00108 { 00109 bits = 0 00110 }; 00111 00112 typedef T type; 00113 typedef signed T signed_type; 00114 typedef unsigned T unsigned_type; 00115 typedef unsigned T alt_sign_type; 00116 }; 00117 00118 #else 00119 00120 template <ss_typename_param_k T> 00121 struct sign_traits; 00122 00123 /* char */ 00124 STLSOFT_TEMPLATE_SPECIALISATION 00125 struct sign_traits<ss_char_a_t> 00126 { 00127 enum { bytes = 1 }; 00128 enum { bits = 8 * bytes }; 00129 00130 typedef ss_char_a_t type; 00131 typedef ss_uint8_t signed_type; 00132 typedef ss_uint8_t unsigned_type; 00133 // typedef ss_uint8_t alt_sign_type; 00134 }; 00135 00136 #ifdef STLSOFT_CF_NATIVE_WCHAR_T_SUPPORT 00137 STLSOFT_TEMPLATE_SPECIALISATION 00138 struct sign_traits<ss_char_w_t> 00139 { 00140 enum { bytes = int(sizeof(ss_char_w_t)) }; 00141 enum { bits = 8 * bytes }; 00142 00143 typedef ss_char_w_t type; 00144 typedef int_size_traits<bytes>::signed_type signed_type; 00145 typedef int_size_traits<bytes>::unsigned_type unsigned_type; 00146 }; 00147 #endif /* STLSOFT_CF_NATIVE_WCHAR_T_SUPPORT */ 00148 00149 /* s/uint8 */ 00150 STLSOFT_TEMPLATE_SPECIALISATION 00151 struct sign_traits<ss_sint8_t> 00152 { 00153 enum { bytes = 1 }; 00154 enum { bits = 8 * bytes }; 00155 00156 typedef ss_sint8_t type; 00157 typedef ss_sint8_t signed_type; 00158 typedef ss_uint8_t unsigned_type; 00159 typedef ss_uint8_t alt_sign_type; 00160 }; 00161 00162 STLSOFT_TEMPLATE_SPECIALISATION 00163 struct sign_traits<ss_uint8_t> 00164 { 00165 enum { bytes = 1 }; 00166 enum { bits = 8 * bytes }; 00167 00168 typedef ss_uint8_t type; 00169 typedef ss_sint8_t signed_type; 00170 typedef ss_uint8_t unsigned_type; 00171 typedef ss_sint8_t alt_sign_type; 00172 }; 00173 00174 /* s/uint16 */ 00175 STLSOFT_TEMPLATE_SPECIALISATION 00176 struct sign_traits<ss_sint16_t> 00177 { 00178 enum { bytes = 2 }; 00179 enum { bits = 8 * bytes }; 00180 00181 typedef ss_sint16_t type; 00182 typedef ss_sint16_t signed_type; 00183 typedef ss_uint16_t unsigned_type; 00184 typedef ss_uint16_t alt_sign_type; 00185 }; 00186 00187 STLSOFT_TEMPLATE_SPECIALISATION 00188 struct sign_traits<ss_uint16_t> 00189 { 00190 enum { bytes = 2 }; 00191 enum { bits = 8 * bytes }; 00192 00193 typedef ss_uint16_t type; 00194 typedef ss_sint16_t signed_type; 00195 typedef ss_uint16_t unsigned_type; 00196 typedef ss_sint16_t alt_sign_type; 00197 }; 00198 00199 /* s/uint32 */ 00200 STLSOFT_TEMPLATE_SPECIALISATION 00201 struct sign_traits<ss_sint32_t> 00202 { 00203 enum { bytes = 4 }; 00204 enum { bits = 8 * bytes }; 00205 00206 typedef ss_sint32_t type; 00207 typedef ss_sint32_t signed_type; 00208 typedef ss_uint32_t unsigned_type; 00209 typedef ss_uint32_t alt_sign_type; 00210 }; 00211 00212 STLSOFT_TEMPLATE_SPECIALISATION 00213 struct sign_traits<ss_uint32_t> 00214 { 00215 enum { bytes = 4 }; 00216 enum { bits = 8 * bytes }; 00217 00218 typedef ss_uint32_t type; 00219 typedef ss_sint32_t signed_type; 00220 typedef ss_uint32_t unsigned_type; 00221 typedef ss_sint32_t alt_sign_type; 00222 }; 00223 00224 #ifdef STLSOFT_CF_64BIT_INT_SUPPORT 00225 /* s/uint64 */ 00226 STLSOFT_TEMPLATE_SPECIALISATION 00227 struct sign_traits<ss_sint64_t> 00228 { 00229 enum { bytes = 8 }; 00230 enum { bits = 8 * bytes }; 00231 00232 typedef ss_sint64_t type; 00233 typedef ss_sint64_t signed_type; 00234 typedef ss_uint64_t unsigned_type; 00235 typedef ss_uint64_t alt_sign_type; 00236 }; 00237 00238 STLSOFT_TEMPLATE_SPECIALISATION 00239 struct sign_traits<ss_uint64_t> 00240 { 00241 enum { bytes = 8 }; 00242 enum { bits = 8 * bytes }; 00243 00244 typedef ss_uint64_t type; 00245 typedef ss_sint64_t signed_type; 00246 typedef ss_uint64_t unsigned_type; 00247 typedef ss_sint64_t alt_sign_type; 00248 }; 00249 #endif /* !STLSOFT_CF_64BIT_INT_SUPPORT */ 00250 00251 #ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE 00252 00253 STLSOFT_TEMPLATE_SPECIALISATION 00254 struct sign_traits<int> 00255 { 00256 enum { bytes = sizeof(int) }; 00257 enum { bits = 8 * bytes }; 00258 00259 typedef int type; 00260 typedef int signed_type; 00261 typedef unsigned unsigned_type; 00262 typedef unsigned alt_sign_type; 00263 }; 00264 00265 STLSOFT_TEMPLATE_SPECIALISATION 00266 struct sign_traits<unsigned> 00267 { 00268 enum { bytes = sizeof(unsigned) }; 00269 enum { bits = 8 * bytes }; 00270 00271 typedef unsigned type; 00272 typedef int signed_type; 00273 typedef unsigned unsigned_type; 00274 typedef int alt_sign_type; 00275 }; 00276 00277 #endif /* !STLSOFT_CF_INT_DISTINCT_INT_TYPE */ 00278 00279 #ifdef STLSOFT_CF_LONG_DISTINCT_INT_TYPE 00280 00281 STLSOFT_TEMPLATE_SPECIALISATION 00282 struct sign_traits<long> 00283 { 00284 enum { bytes = int(sizeof(long)) }; 00285 enum { bits = 8 * bytes }; 00286 00287 typedef long type; 00288 typedef long signed_type; 00289 typedef unsigned long unsigned_type; 00290 typedef unsigned long alt_sign_type; 00291 }; 00292 00293 STLSOFT_TEMPLATE_SPECIALISATION 00294 struct sign_traits<unsigned long> 00295 { 00296 enum { bytes = int(sizeof(unsigned long)) }; 00297 enum { bits = 8 * bytes }; 00298 00299 typedef unsigned long type; 00300 typedef long signed_type; 00301 typedef unsigned long unsigned_type; 00302 typedef long alt_sign_type; 00303 }; 00304 00305 #endif /* !STLSOFT_CF_LONG_DISTINCT_INT_TYPE */ 00306 00307 00308 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00309 00310 /* ////////////////////////////////////////////////////////////////////// */ 00311 00312 #ifndef _STLSOFT_NO_NAMESPACE 00313 } // namespace stlsoft 00314 #endif /* _STLSOFT_NO_NAMESPACE */ 00315 00316 /* ////////////////////////////////////////////////////////////////////// */ 00317 00318 #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_SIGN_TRAITS */ 00319 00320 /* ///////////////////////////// end of file //////////////////////////// */