2
CLAW - a C++ Library Absolutely Wonderful
4
CLAW is a free library without any particular aim but being useful to
7
Copyright (C) 2005-2008 Julien Jorge
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
contact: julien_jorge@yahoo.fr
27
* \brief Some classes for the raw manipulation of the base types.
28
* \author Julien Jorge
30
#include <claw/meta.hpp>
32
#ifndef __CLAW_TYPES_HPP__
33
#define __CLAW_TYPES_HPP__
37
#ifdef CLAW_HAS_LONG_LONG
40
meta::type_list<signed long long int, meta::no_type>
41
non_standard_signed_types;
44
meta::type_list<unsigned long long int, meta::no_type>
45
non_standard_unsigned_types;
47
#else // !def CLAW_HAS_LONG_LONG
49
typedef meta::no_type non_standard_signed_types;
50
typedef meta::no_type non_standard_unsigned_types;
52
#endif // CLAW_HAS_LONG_LONG
54
/** \brief This is the list of c++ signed integer types. */
55
typedef meta::type_list
59
meta::type_list<signed int, non_standard_signed_types>
62
/** \brief This is the list of c++ unsigned integer types. */
63
typedef meta::type_list
67
meta::type_list<unsigned int, non_standard_unsigned_types>
68
> > unsigned_integers;
71
* \brief This meta class finds, in a list of types, the first type stored
72
* exactly with a given number of bits.
74
* \b Template \b parameters
75
* - \a Size The number of bits in the type to find,
76
* - \a TypeList A list of types (see meta::type_list).
78
template<unsigned int Size, typename TypeList>
79
struct find_type_by_size
82
typedef typename TypeList::head_type head_type;
83
typedef typename TypeList::queue_type queue_type;
87
typename meta::if_then_else
88
< sizeof(head_type) * 8 == Size, head_type,
89
typename find_type_by_size<Size, queue_type>::type >::result type;
90
}; // find_type_by_size
92
/** \brief End of the recursion of the find_type_by_size class. */
93
template<unsigned int Size>
94
struct find_type_by_size<Size, meta::no_type>
96
/** \brief This is an incomplete type that should make the compiler to
99
}; // find_type_by_size
102
* \brief Define the type of a signed integer stored with a given number of
104
* \b Template \b parameters
105
* - \a Size The number of bytes in the types.
107
template<unsigned int Size>
108
struct integer_of_size
110
typedef typename find_type_by_size<Size, signed_integers>::type type;
111
}; // struct integer_of_size
114
* \brief Define the type of an unsigned integer stored with a given number of
116
* \b Template \b parameters
117
* - \a Size The number of bytes in the types.
119
template<unsigned int Size>
120
struct unsigned_integer_of_size
122
typedef typename find_type_by_size<Size, unsigned_integers>::type type;
123
}; // struct unsigned_integer_of_size
127
#endif // __CLAW_TYPES_HPP__