$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
int_u.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2012, 2013 EPITA Research and
2 // Development 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_INT_U_HH
28 # define MLN_VALUE_INT_U_HH
29 
34 
35 # include <mln/value/ops.hh>
36 
37 # include <mln/metal/math/pow.hh>
38 # include <mln/value/internal/value_like.hh>
39 # include <mln/value/internal/encoding.hh>
40 # include <mln/value/concept/integer.hh>
41 # include <mln/trait/value_.hh>
42 
43 # include <mln/value/internal/make_generic_name.hh>
44 
45 
46 namespace mln
47 {
48 
51  namespace value
52  {
53  template <unsigned n> struct int_u;
54  template <unsigned n> struct rgb;
55 
56  namespace qt
57  {
58  struct rgb32;
59  }
60  }
61 
62  namespace literal
63  {
64  struct zero_t;
65  struct one_t;
66  }
68 
69 
70  namespace trait
71  {
72 
73  template <unsigned n>
74  struct set_precise_unary_< op::uminus, mln::value::int_u<n> >
75  {
76  typedef int ret;
77  };
78 
79 
80  template <unsigned n>
81  struct value_< mln::value::int_u<n> >
82  {
83  private:
84  typedef mln::value::int_u<n> self_;
86  public:
87 
88  enum constants_ {
89  dim = 1,
90  nbits = n,
91  card = mln_value_card_from_(n)
92  };
93 
94  typedef trait::value::nature::integer nature;
95  typedef trait::value::kind::data kind;
96  typedef mln_value_quant_from_(card) quant;
97 
98  static const self_ min() { return 0; }
99  static const self_ max() { return mlc_pow_int(2, n) - 1; }
100  static const self_ epsilon() { return 0; }
101 
102  typedef unsigned comp;
103 
104  typedef float sum;
105 
106  static const char* name()
107  {
108  static std::string
110  return s.c_str();
111  }
112 
113  };
114 
115  } // end of namespace mln::trait
116 
117 
118  namespace value
119  {
120 
128  template <unsigned n>
129  struct int_u
130  :
131  public Integer< int_u<n> >,
132 
133  public internal::value_like_< unsigned, // Equivalent.
134  typename internal::encoding_unsigned_<n>::ret, // Enc.
135  int, // Interoperation.
136  int_u<n> > // Exact.
137  {
138  protected:
141 
142  public:
143 
145  int_u();
146 
148  int_u(int i);
149 
151  int_u(const mln::literal::zero_t&);
153  int_u(const mln::literal::one_t&);
156 
158  operator unsigned() const;
159 
161  int operator-() const;
162 
164  int_u<n>& operator=(int i);
165 
167  int_u<n> next() const;
168  };
169 
170 
171  // Safety.
172  template <> struct int_u<0>;
173  template <> struct int_u<1>;
174 
175 
176 
183  template <unsigned n>
184  std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i);
185 
193  template <unsigned n>
194  std::istream& operator>>(std::istream& istr, int_u<n>& i);
195 
196 
197 
198  // Conversions
199 
201  template <unsigned n>
202  void from_to_(const int_u<n>& from, unsigned& to_);
203 
205  template <unsigned n>
206  void from_to_(const int_u<n>& from, bool& to_);
207 
209  template <unsigned n>
210  void from_to_(const int_u<n>& from, float& to_);
211 
213  template <unsigned n>
214  void from_to_(const int_u<n>& from, double& to_);
215 
217  template <unsigned m>
218  void from_to_(const int_u<m>& from, qt::rgb32& to);
219 
221  template <unsigned m>
222  void from_to_(const int_u<m>& from, rgb<m>& to);
223 
224  } // end of namespace mln::value
225 
226 } // end of namespace mln
227 
228 
229 // Required by mln::values::int_u's from_to_ routines.
230 # include <mln/value/rgb.hh>
231 # include <mln/value/qt/rgb32.hh>
232 
233 
234 # ifndef MLN_INCLUDE_ONLY
235 # include <mln/value/int_u.hxx>
236 # endif // ! MLN_INCLUDE_ONLY
237 
238 
239 #endif // ! MLN_VALUE_INT_U_HH