$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
value/sign.hh
1 // Copyright (C) 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_SIGN_HH
27 # define MLN_VALUE_SIGN_HH
28 
33 # include <mln/value/internal/integer.hh>
34 # include <mln/trait/value_.hh>
35 # include <mln/literal/zero.hh>
36 # include <mln/literal/one.hh>
37 # include <mln/debug/format.hh>
38 
39 namespace mln
40 {
41 
42  namespace value
43  {
49  class sign : public internal::Integer<sign>
50  {
51  public:
53 
55  typedef int enc;
56 
58  typedef int equiv;
59 
60 
62  sign();
63 
65  sign(int i);
66 
68  sign(const mln::literal::zero_t&);
70  sign(const mln::literal::one_t&);
73 
75  operator int() const;
76 
78  int val_() const;
79 
81  sign& operator=(int i);
82 
83 
85  static const sign zero;
86 
88  static const sign one;
89 
90  protected:
91 
93  int v_;
94  };
95 
103  std::ostream& operator<<(std::ostream& ostr, const sign& i);
104 
106  bool operator==(const sign& lhs, const sign& rhs);
107  bool operator<(const sign& lhs, const sign& rhs);
108 
109 # ifndef MLN_INCLUDE_ONLY
110 
111 # ifndef MLN_WO_GLOBAL_VARS
112 
113  const sign sign::zero = 0;
114  const sign sign::one = 1;
115 
116 # endif // !MLN_WO_GLOBAL_VARS
117 
118  inline
119  sign::sign()
120  {
121  }
122 
123  inline
124  sign::operator int() const
125  {
126  return this->v_;
127  }
128 
129  inline
130  int
131  sign::val_() const
132  {
133  return this->v_;
134  }
135 
136  inline
137  sign::sign(int i)
138  {
139  mln_precondition(i >= -1);
140  mln_precondition(i <= 1);
141  this->v_ = i;
142  }
143 
144  inline
145  sign&
146  sign::operator=(int i)
147  {
148  mln_precondition(i >= -1);
149  mln_precondition(i <= 1);
150  this->v_ = i;
151  return *this;
152  }
153 
154  inline
156  {
157  this->v_ = 0;
158  }
159 
160  inline
161  sign&
163  {
164  this->v_ = 0;
165  return *this;
166  }
167 
168  inline
170  {
171  this->v_ = 1;
172  }
173 
174  inline
175  sign&
177  {
178  this->v_ = 1;
179  return *this;
180  }
181 
182 
183  inline
184  std::ostream& operator<<(std::ostream& ostr, const sign& i)
185  {
186  return ostr << debug::format(i.val_());
187  }
188 
189  inline
190  bool operator==(const sign& lhs, const sign& rhs)
191  {
192  return lhs.val_() == rhs.val_();
193  }
194 
195  inline
196  bool operator<(const sign& lhs, const sign& rhs)
197  {
198  return lhs.val_() == rhs.val_();
199  }
200 
201 # endif // ! MLN_INCLUDE_ONLY
202 
203  } // end of namespace value
204 
205  namespace trait
206  {
207 
208  template <>
209  struct value_<mln::value::sign>
210  {
211 
212  enum {
213  dim = 1,
214  nbits = 2,
215  card = 3
216  };
217 
218  typedef trait::value::nature::integer nature;
219  typedef trait::value::kind::gray kind;
220  typedef trait::value::quant::low quant;
221 
222  static mln::value::sign min() { return -1; }
223  static mln::value::sign max() { return 1; }
224  static mln::value::sign epsilon() { return 0; }
225 
226  typedef int comp;
227 
228  typedef int sum;
229  };
230 
231  } // end of namespace trait
232 
233 } // end of namespace mln
234 
235 
236 #endif // ! MLN_VALUE_SIGN_HH