~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to claw/types.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2008-05-17 15:36:57 UTC
  • Revision ID: james.westby@ubuntu.com-20080517153657-0b1204j754ykoz48
Tags: upstream-1.5.2b
ImportĀ upstreamĀ versionĀ 1.5.2b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  CLAW - a C++ Library Absolutely Wonderful
 
3
 
 
4
  CLAW is a free library without any particular aim but being useful to 
 
5
  anyone.
 
6
 
 
7
  Copyright (C) 2005-2008 Julien Jorge
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
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
 
22
 
 
23
  contact: julien_jorge@yahoo.fr
 
24
*/
 
25
/**
 
26
 * \file types.hpp
 
27
 * \brief Some classes for the raw manipulation of the base types.
 
28
 * \author Julien Jorge
 
29
 */
 
30
#include <claw/meta.hpp>
 
31
 
 
32
#ifndef __CLAW_TYPES_HPP__
 
33
#define __CLAW_TYPES_HPP__
 
34
 
 
35
namespace claw
 
36
{
 
37
#ifdef CLAW_HAS_LONG_LONG
 
38
 
 
39
  typedef
 
40
  meta::type_list<signed long long int, meta::no_type>
 
41
  non_standard_signed_types;
 
42
 
 
43
  typedef
 
44
  meta::type_list<unsigned long long int, meta::no_type>
 
45
  non_standard_unsigned_types;
 
46
 
 
47
#else // !def CLAW_HAS_LONG_LONG
 
48
 
 
49
  typedef meta::no_type non_standard_signed_types;
 
50
  typedef meta::no_type non_standard_unsigned_types;
 
51
 
 
52
#endif // CLAW_HAS_LONG_LONG
 
53
 
 
54
  /** \brief This is the list of c++ signed integer types. */
 
55
  typedef meta::type_list
 
56
  < signed char,
 
57
    meta::type_list
 
58
    < signed short,
 
59
      meta::type_list<signed int, non_standard_signed_types>
 
60
  > > signed_integers;
 
61
 
 
62
  /** \brief This is the list of c++ unsigned integer types. */
 
63
  typedef meta::type_list
 
64
  < unsigned char,
 
65
    meta::type_list
 
66
    < unsigned short,
 
67
      meta::type_list<unsigned int, non_standard_unsigned_types>
 
68
  > > unsigned_integers;
 
69
 
 
70
  /**
 
71
   * \brief This meta class finds, in a list of types, the first type stored
 
72
   *        exactly with a given number of bits.
 
73
   *
 
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).
 
77
   */
 
78
  template<unsigned int Size, typename TypeList>
 
79
  struct find_type_by_size
 
80
  {
 
81
  private:
 
82
    typedef typename TypeList::head_type head_type;
 
83
    typedef typename TypeList::queue_type queue_type;
 
84
 
 
85
  public:
 
86
    typedef
 
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
 
91
 
 
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>
 
95
  {
 
96
    /** \brief This is an incomplete type that should make the compiler to
 
97
        fail. */
 
98
    struct type;
 
99
  }; // find_type_by_size
 
100
 
 
101
  /**
 
102
   * \brief Define the type of a signed integer stored with a given number of
 
103
   *        bits.
 
104
   * \b Template \b parameters
 
105
   *  - \a Size The number of bytes in the types.
 
106
   */
 
107
  template<unsigned int Size>
 
108
  struct integer_of_size
 
109
  {
 
110
    typedef typename find_type_by_size<Size, signed_integers>::type type;
 
111
  }; // struct integer_of_size
 
112
 
 
113
  /**
 
114
   * \brief Define the type of an unsigned integer stored with a given number of
 
115
   *        bits.
 
116
   * \b Template \b parameters
 
117
   *  - \a Size The number of bytes in the types.
 
118
   */
 
119
  template<unsigned int Size>
 
120
  struct unsigned_integer_of_size
 
121
  {
 
122
    typedef typename find_type_by_size<Size, unsigned_integers>::type type;
 
123
  }; // struct unsigned_integer_of_size
 
124
 
 
125
} // namespace claw
 
126
 
 
127
#endif // __CLAW_TYPES_HPP__