Claw 1.7.0
types.hpp
Go to the documentation of this file.
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:
00088     typedef
00089     typename meta::if_then_else
00090     < sizeof(head_type) * 8 == Size, head_type,
00091       typename find_type_by_size<Size, queue_type>::type >::result type;
00092 
00093   }; // find_type_by_size
00094 
00096   template<std::size_t Size>
00097   struct find_type_by_size<Size, meta::no_type>
00098   {
00101     struct type;
00102   }; // find_type_by_size
00103 
00110   template<std::size_t Size>
00111   struct integer_of_size
00112   {
00113     typedef typename find_type_by_size<Size, signed_integers>::type type;
00114   }; // struct integer_of_size
00115 
00122   template<std::size_t Size>
00123   struct unsigned_integer_of_size
00124   {
00125     typedef typename find_type_by_size<Size, unsigned_integers>::type type;
00126   }; // struct unsigned_integer_of_size
00127 
00128   typedef unsigned_integer_of_size<8>::type u_int_8;
00129   typedef unsigned_integer_of_size<16>::type u_int_16;
00130   typedef unsigned_integer_of_size<32>::type u_int_32;
00131 
00132   typedef integer_of_size<8>::type int_8;
00133   typedef integer_of_size<16>::type int_16;
00134   typedef integer_of_size<32>::type int_32;
00135 
00136 } // namespace claw
00137 
00138 #endif // __CLAW_TYPES_HPP__