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