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-2008 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@yahoo.fr
00024 */
00030 #include <claw/meta.hpp>
00031 
00032 #ifndef __CLAW_TYPES_HPP__
00033 #define __CLAW_TYPES_HPP__
00034 
00035 namespace claw
00036 {
00037 #ifdef CLAW_HAS_LONG_LONG
00038 
00039   typedef
00040   meta::type_list<signed long long int, meta::no_type>
00041   non_standard_signed_types;
00042 
00043   typedef
00044   meta::type_list<unsigned long long int, meta::no_type>
00045   non_standard_unsigned_types;
00046 
00047 #else // !def CLAW_HAS_LONG_LONG
00048 
00049   typedef meta::no_type non_standard_signed_types;
00050   typedef meta::no_type non_standard_unsigned_types;
00051 
00052 #endif // CLAW_HAS_LONG_LONG
00053 
00055   typedef meta::type_list
00056   < signed char,
00057     meta::type_list
00058     < signed short,
00059       meta::type_list<signed int, non_standard_signed_types>
00060   > > signed_integers;
00061 
00063   typedef meta::type_list
00064   < unsigned char,
00065     meta::type_list
00066     < unsigned short,
00067       meta::type_list<unsigned int, non_standard_unsigned_types>
00068   > > unsigned_integers;
00069 
00078   template<unsigned int Size, typename TypeList>
00079   struct find_type_by_size
00080   {
00081   private:
00082     typedef typename TypeList::head_type head_type;
00083     typedef typename TypeList::queue_type queue_type;
00084 
00085   public:
00086     typedef
00087     typename meta::if_then_else
00088     < sizeof(head_type) * 8 == Size, head_type,
00089       typename find_type_by_size<Size, queue_type>::type >::result type;
00090   }; // find_type_by_size
00091 
00093   template<unsigned int Size>
00094   struct find_type_by_size<Size, meta::no_type>
00095   {
00098     struct type;
00099   }; // find_type_by_size
00100 
00107   template<unsigned int Size>
00108   struct integer_of_size
00109   {
00110     typedef typename find_type_by_size<Size, signed_integers>::type type;
00111   }; // struct integer_of_size
00112 
00119   template<unsigned int Size>
00120   struct unsigned_integer_of_size
00121   {
00122     typedef typename find_type_by_size<Size, unsigned_integers>::type type;
00123   }; // struct unsigned_integer_of_size
00124 
00125 } // namespace claw
00126 
00127 #endif // __CLAW_TYPES_HPP__

Generated on Mon Nov 9 05:07:10 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.4.7