types.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#include <claw/meta/type_list.hpp>
#include <claw/meta/conditional.hpp>
#ifndef __CLAW_TYPES_HPP__
#define __CLAW_TYPES_HPP__
namespace claw
{
#ifdef CLAW_HAS_LONG_LONG
typedef
meta::type_list<signed long long int, meta::no_type>
non_standard_signed_types;
typedef
meta::type_list<unsigned long long int, meta::no_type>
non_standard_unsigned_types;
#else // !def CLAW_HAS_LONG_LONG
typedef meta::no_type non_standard_signed_types;
typedef meta::no_type non_standard_unsigned_types;
#endif // CLAW_HAS_LONG_LONG
typedef meta::type_list
< signed char,
meta::type_list
< signed short,
meta::type_list<signed int, non_standard_signed_types>
> > signed_integers;
typedef meta::type_list
< unsigned char,
meta::type_list
< unsigned short,
meta::type_list<unsigned int, non_standard_unsigned_types>
> > unsigned_integers;
template<std::size_t Size, typename TypeList>
struct find_type_by_size
{
private:
typedef typename TypeList::head_type head_type;
typedef typename TypeList::queue_type queue_type;
public:
typedef
typename meta::if_then_else
< sizeof(head_type) * 8 == Size, head_type,
typename find_type_by_size<Size, queue_type>::type >::result type;
}; // find_type_by_size
template<std::size_t Size>
struct find_type_by_size<Size, meta::no_type>
{
struct type;
}; // find_type_by_size
template<std::size_t Size>
struct integer_of_size
{
typedef typename find_type_by_size<Size, signed_integers>::type type;
}; // struct integer_of_size
template<std::size_t Size>
struct unsigned_integer_of_size
{
typedef typename find_type_by_size<Size, unsigned_integers>::type type;
}; // struct unsigned_integer_of_size
typedef unsigned_integer_of_size<8>::type u_int_8;
typedef unsigned_integer_of_size<16>::type u_int_16;
typedef unsigned_integer_of_size<32>::type u_int_32;
typedef integer_of_size<8>::type int_8;
typedef integer_of_size<16>::type int_16;
typedef integer_of_size<32>::type int_32;
} // namespace claw
#endif // __CLAW_TYPES_HPP__
claw::integer_of_size
Define the type of a signed integer stored with a given number of bits. Template parameters.
Definition: types.hpp:113
claw::find_type_by_size
This meta class finds, in a list of types, the first type stored exactly with a given number of bits...
Definition: types.hpp:81
claw::u_int_32
unsigned_integer_of_size< 32 >::type u_int_32
An unsigned integer on 32 bits.
Definition: types.hpp:141
claw::unsigned_integer_of_size
Define the type of an unsigned integer stored with a given number of bits. Template parameters...
Definition: types.hpp:127
claw::integer_of_size::type
find_type_by_size< Size, signed_integers >::type type
The integer type that matches the given size.
Definition: types.hpp:116
conditional.hpp
Structures for meta-programming.
claw::u_int_8
unsigned_integer_of_size< 8 >::type u_int_8
An unsigned integer on 8 bits.
Definition: types.hpp:135
claw::find_type_by_size::type
meta::if_then_else< sizeof(head_type) *8==Size, head_type, typename find_type_by_size< Size, queue_type >::type >::result type
If the size of head_type matches the desired one, then the result is head_type, otherwise we search t...
Definition: types.hpp:93
claw::signed_integers
meta::type_list< signed char, meta::type_list< signed short, meta::type_list< signed int, non_standard_signed_types > > > signed_integers
This is the list of c++ signed integer types.
Definition: types.hpp:62
claw::unsigned_integers
meta::type_list< unsigned char, meta::type_list< unsigned short, meta::type_list< unsigned int, non_standard_unsigned_types > > > unsigned_integers
This is the list of c++ unsigned integer types.
Definition: types.hpp:70
type_list.hpp
Template classes for lists of types.
claw::u_int_16
unsigned_integer_of_size< 16 >::type u_int_16
An unsigned integer on 16 bits.
Definition: types.hpp:138
claw::int_32
integer_of_size< 32 >::type int_32
An integer on 32 bits.
Definition: types.hpp:150
claw::unsigned_integer_of_size::type
find_type_by_size< Size, unsigned_integers >::type type
The integer type that matches the given size.
Definition: types.hpp:130
claw::meta::type_list
Use this class to make a list of types.
Definition: type_list.hpp:59
claw::int_16
integer_of_size< 16 >::type int_16
An integer on 16 bits.
Definition: types.hpp:147
claw::meta::if_then_else
This structure allows to do conditional typing.
Definition: conditional.hpp:50
claw::int_8
integer_of_size< 8 >::type int_8
An integer on 8 bits.
Definition: types.hpp:144
claw
This is the main namespace.
Definition: algorithm.hpp:33