Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
integers.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_VALUE_BUILTIN_INTEGERS_HH
27 # define MLN_VALUE_BUILTIN_INTEGERS_HH
28 
32 
33 # include <mln/value/internal/limits.hh>
34 
35 # include <mln/value/concept/built_in.hh>
36 # include <mln/value/concept/integer.hh>
37 # include <mln/trait/value_.hh>
38 
39 # include <mln/metal/int.hh>
40 # include <mln/metal/if.hh>
41 # include <mln/metal/bool.hh>
42 
43 
44 namespace mln
45 {
46 
47  template <> struct category< unsigned char > { typedef value::Built_In< value::Integer<void> > ret; };
48  template <> struct category< signed char > { typedef value::Built_In< value::Integer<void> > ret; };
49  template <> struct category< unsigned short > { typedef value::Built_In< value::Integer<void> > ret; };
50  template <> struct category< signed short > { typedef value::Built_In< value::Integer<void> > ret; };
51  template <> struct category< unsigned int > { typedef value::Built_In< value::Integer<void> > ret; };
52  template <> struct category< signed int > { typedef value::Built_In< value::Integer<void> > ret; };
53  template <> struct category< unsigned long > { typedef value::Built_In< value::Integer<void> > ret; };
54  template <> struct category< signed long > { typedef value::Built_In< value::Integer<void> > ret; };
55 
56 
57  namespace trait
58  {
59 
60  // FIXME: Move the definitions below elsewhere.
61 
62  namespace internal
63  {
64 
65  template <typename E>
66  struct value_integer_
67  {
68  private:
69  enum { n = 8 * sizeof(E) };
70  public:
71 
72  enum {
73  dim = 1,
74  nbits = n,
75  card = mln_value_card_from_(n)
76  };
77 
78  typedef trait::value::nature::integer nature;
79  typedef trait::value::kind::data kind;
80  typedef mln_value_quant_from_(card) quant;
81 
82  static const E min() { return mln::value::internal::limits<E>::min(); }
83  static const E max() { return mln::value::internal::limits<E>::max(); }
84 
85  typedef float sum;
86  };
87 
88  } // end of namespace mln::trait::internal
89 
90 
91  template <> struct value_< unsigned char >
92  : internal::value_integer_< unsigned char >
93  {
94  static const char* name()
95  { return "unsigned char"; }
96  };
97 
98  template <> struct value_< signed char >
99  : internal::value_integer_< signed char >
100  {
101  static const char* name()
102  { return "signed char"; }
103  };
104 
105  template <> struct value_< char >
106  : internal::value_integer_< signed char >
107  {
108  static const char* name()
109  { return "char"; }
110  };
111 
112  template <> struct value_< unsigned short >
113  : internal::value_integer_< unsigned short >
114  {
115  static const char* name()
116  { return "unsigned short"; }
117  };
118 
119  template <> struct value_< signed short >
120  : internal::value_integer_< signed short >
121  {
122  static const char* name()
123  { return "signed short"; }
124  };
125 
126  template <> struct value_< unsigned int >
127  : internal::value_integer_< unsigned int >
128  {
129  static const char* name()
130  { return "unsigned int"; }
131  };
132 
133  template <> struct value_< signed int >
134  : internal::value_integer_< signed int >
135  {
136  static const char* name()
137  { return "signed int"; }
138  };
139 
140  template <> struct value_< unsigned long >
141  : internal::value_integer_< unsigned long >
142  {
143  static const char* name()
144  { return "unsigned long"; }
145  };
146 
147  template <> struct value_< signed long >
148  : internal::value_integer_< signed long >
149  {
150  static const char* name()
151  { return "signed long"; }
152  };
153 
154  } // end of namespace mln::trait
155 
156 } // end of namespace mln
157 
158 
159 #endif // ! MLN_VALUE_BUILTIN_INTEGERS_HH