Claw
1.7.3
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2011 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien.jorge@gamned.org 00024 */ 00031 #include <claw/meta/type_list.hpp> 00032 #include <claw/meta/conditional.hpp> 00033 00034 #ifndef __CLAW_TYPES_HPP__ 00035 #define __CLAW_TYPES_HPP__ 00036 00037 namespace claw 00038 { 00039 #ifdef CLAW_HAS_LONG_LONG 00040 00041 typedef 00042 meta::type_list<signed long long int, meta::no_type> 00043 non_standard_signed_types; 00044 00045 typedef 00046 meta::type_list<unsigned long long int, meta::no_type> 00047 non_standard_unsigned_types; 00048 00049 #else // !def CLAW_HAS_LONG_LONG 00050 00051 typedef meta::no_type non_standard_signed_types; 00052 typedef meta::no_type non_standard_unsigned_types; 00053 00054 #endif // CLAW_HAS_LONG_LONG 00055 00057 typedef meta::type_list 00058 < signed char, 00059 meta::type_list 00060 < signed short, 00061 meta::type_list<signed int, non_standard_signed_types> 00062 > > signed_integers; 00063 00065 typedef meta::type_list 00066 < unsigned char, 00067 meta::type_list 00068 < unsigned short, 00069 meta::type_list<unsigned int, non_standard_unsigned_types> 00070 > > unsigned_integers; 00071 00080 template<std::size_t Size, typename TypeList> 00081 struct find_type_by_size 00082 { 00083 private: 00084 typedef typename TypeList::head_type head_type; 00085 typedef typename TypeList::queue_type queue_type; 00086 00087 public: 00090 typedef 00091 typename meta::if_then_else 00092 < sizeof(head_type) * 8 == Size, head_type, 00093 typename find_type_by_size<Size, queue_type>::type >::result type; 00094 00095 }; // find_type_by_size 00096 00098 template<std::size_t Size> 00099 struct find_type_by_size<Size, meta::no_type> 00100 { 00103 struct type; 00104 }; // find_type_by_size 00105 00112 template<std::size_t Size> 00113 struct integer_of_size 00114 { 00116 typedef typename find_type_by_size<Size, signed_integers>::type type; 00117 00118 }; // struct integer_of_size 00119 00126 template<std::size_t Size> 00127 struct unsigned_integer_of_size 00128 { 00130 typedef typename find_type_by_size<Size, unsigned_integers>::type type; 00131 00132 }; // struct unsigned_integer_of_size 00133 00135 typedef unsigned_integer_of_size<8>::type u_int_8; 00136 00138 typedef unsigned_integer_of_size<16>::type u_int_16; 00139 00141 typedef unsigned_integer_of_size<32>::type u_int_32; 00142 00144 typedef integer_of_size<8>::type int_8; 00145 00147 typedef integer_of_size<16>::type int_16; 00148 00150 typedef integer_of_size<32>::type int_32; 00151 00152 } // namespace claw 00153 00154 #endif // __CLAW_TYPES_HPP__