$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/logic/lor.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_LOR_HH
27 # define MLN_ACCU_LOGIC_LOR_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 lor;
46  }
47  }
48 
49 
50  // Traits.
51 
52  namespace trait
53  {
54 
55  template <>
56  struct accumulator_< accu::logic::lor >
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 
73  namespace logic
74  {
76  struct lor : public Meta_Accumulator< lor >
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  namespace logic
89  {
90 
94  //
95  struct lor : public mln::accu::internal::base< bool, lor >
96  {
97  typedef bool argument;
98 
99  lor();
100 
103  void init();
104  void take_as_init_(const argument& t);
105 
106  void take(const argument& t);
107  void take(const lor& other);
108 
109  void untake(const argument& t);
110  void untake(const lor& other);
112 
114  bool to_result() const;
115 
118  bool is_valid() const;
119 
120  protected:
121  unsigned ntrue_;
122  };
123 
124 # ifndef MLN_INCLUDE_ONLY
125 
126  inline
127  lor::lor()
128  {
129  init();
130  }
131 
132  inline
133  void
134  lor::init()
135  {
136  ntrue_ = 0;
137  }
138 
139  inline
140  void lor::take_as_init_(const argument& t)
141  {
142  ntrue_ = t ? 1 : 0;
143  }
144 
145  inline
146  void lor::take(const argument& t)
147  {
148  if (t == true)
149  ++ntrue_;
150  }
151 
152  inline
153  void
154  lor::take(const lor& other)
155  {
156  ntrue_ += other.ntrue_;
157  }
158 
159  inline
160  void lor::untake(const argument& t)
161  {
162  if (t == true)
163  --ntrue_;
164  }
165 
166  inline
167  void
168  lor::untake(const lor& other)
169  {
170  mln_precondition(other.ntrue_ <= ntrue_);
171  ntrue_ -= other.ntrue_;
172  }
173 
174  inline
175  bool
176  lor::to_result() const
177  {
178  return ntrue_ != 0;
179  }
180 
181  inline
182  bool
183  lor::is_valid() const
184  {
185  return true;
186  }
187 
188 # endif // ! MLN_INCLUDE_ONLY
189 
190  } // end of namespace mln::accu::logic
191  } // end of namespace mln::accu
192 } // end of namespace mln
193 
194 
195 #endif // ! MLN_ACCU_LOGIC_LOR_HH