$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
float01_f.hh
1 // Copyright (C) 2006, 2007, 2008, 2009, 2011 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_FLOAT01_F_HH
28 # define MLN_VALUE_FLOAT01_F_HH
29 
35 # include <iostream>
36 # include <mln/value/internal/value_like.hh>
37 # include <mln/value/concept/floating.hh>
38 # include <mln/value/builtin/floatings.hh>
39 # include <mln/trait/value_.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Fwd decls.
46  namespace value {
47  class float01;
48  struct float01_f;
49  }
50 
51 
52  namespace trait
53  {
54 
55  template <>
56  struct value_< mln::value::float01_f >
57  {
58  typedef trait::value::nature::floating nature;
59  typedef trait::value::kind::data kind;
60  typedef trait::value::quant::high quant;
61 
62  enum {
63  dim = 1,
64  nbits = 8 * sizeof(float),
65  card = 0
66  };
67 
68  static float min() { return 0; }
69  static float max() { return 1; }
70  static float epsilon() { return mln_epsilon(float); }
71 
72  typedef float comp;
73 
74  typedef float sum;
75  };
76 
77  } // end of namespace trait
78 
79 
80 
81  namespace value
82  {
83 
85  struct float01_f
86  :
87  public Floating< float01_f >,
88 
89  public internal::value_like_< float, // Equivalent.
90  float, // Encoding.
91  float, // Interoperation.
92  float01_f > // Exact.
93  {
95  float01_f();
96 
98  float01_f(float val);
99 
101  float01_f& operator=(const float val);
102 
104  float value() const;
105 
107  operator float() const;
108  };
109 
110 
111 # ifndef MLN_INCLUDE_ONLY
112 
113  // Float01_F.
114 
115  inline
117  {
118  }
119 
120  inline
121  float01_f::float01_f(float val)
122  {
123  mln_precondition(val >= 0);
124  mln_precondition(val <= 1);
125  this->v_ = val;
126  }
127 
128  inline
129  float
130  float01_f::value() const
131  {
132  return this->v_;
133  }
134 
135  inline
136  float01_f&
137  float01_f::operator=(float val)
138  {
139  mln_precondition(val >= 0);
140  mln_precondition(val <= 1);
141  this->v_ = val;
142  return *this;
143  }
144 
145  inline
146  float01_f::operator float() const
147  {
148  return this->v_;
149  }
150 
151 # endif // ! MLN_INCLUDE_ONLY
152 
153  } // end of namespace mln::value
154 
155 } // end of namespace mln
156 
157 
158 #endif // ! MLN_VALUE_FLOAT01_F_HH