$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/logic/land.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_ACCU_LOGIC_LAND_HH
27 # define MLN_ACCU_LOGIC_LAND_HH
28 
34 
35 # include <mln/core/concept/meta_accumulator.hh>
36 # include <mln/accu/internal/base.hh>
37 
38 
39 namespace mln
40 {
41 
42  // Forward declaration.
43  namespace accu {
44  namespace logic {
45  struct land;
46  }
47  }
48 
49 
50  // Traits.
51 
52  namespace trait
53  {
54 
55  template <>
56  struct accumulator_< accu::logic::land >
57  {
58  typedef accumulator::has_untake::yes has_untake;
59  typedef accumulator::has_set_value::no has_set_value;
60  typedef accumulator::has_stop::no has_stop;
61  typedef accumulator::when_pix::use_v when_pix;
62  };
63 
64  } // end of namespace mln::trait
65 
66 
67  namespace accu
68  {
69 
70  namespace meta
71  {
72  namespace logic
73  {
74 
76  struct land : public Meta_Accumulator< land >
77  {
78  template <typename T>
79  struct with
80  {
82  };
83  };
84 
85  } // end of namespace mln::accu::meta::logic
86  } // end of namespace mln::accu::meta
87 
88 
89  namespace logic
90  {
91 
95  //
96  struct land : public mln::accu::internal::base< bool, land >
97  {
98  typedef bool argument;
99 
100  land();
101 
104  void init();
105  void take_as_init_(const argument& t);
106 
107  void take(const argument& t);
108  void take(const land& other);
109 
110  void untake(const argument& t);
111  void untake(const land& other);
113 
115  bool to_result() const;
116 
119  bool is_valid() const;
120 
121  protected:
122  unsigned nfalse_;
123  };
124 
125 
126 # ifndef MLN_INCLUDE_ONLY
127 
128  inline
129  land::land()
130  {
131  init();
132  }
133 
134  inline
135  void
136  land::init()
137  {
138  nfalse_ = 0;
139  }
140 
141  inline
142  void land::take_as_init_(const argument& t)
143  {
144  nfalse_ = t ? 0 : 1;
145  }
146 
147  inline
148  void land::take(const argument& t)
149  {
150  if (t == false)
151  ++nfalse_;
152  }
153 
154  inline
155  void
156  land::take(const land& other)
157  {
158  nfalse_ += other.nfalse_;
159  }
160 
161  inline
162  void land::untake(const argument& t)
163  {
164  if (t == false)
165  --nfalse_;
166  }
167 
168  inline
169  void
170  land::untake(const land& other)
171  {
172  mln_precondition(other.nfalse_ <= nfalse_);
173  nfalse_ -= other.nfalse_;
174  }
175 
176  inline
177  bool
178  land::to_result() const
179  {
180  return nfalse_ == 0;
181  }
182 
183  inline
184  bool
185  land::is_valid() const
186  {
187  return true;
188  }
189 
190 # endif // ! MLN_INCLUDE_ONLY
191 
192  } // end of namespace mln::accu::logic
193  } // end of namespace mln::accu
194 } // end of namespace mln
195 
196 #endif // ! MLN_ACCU_LOGIC_LAND_HH