$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
morpho/attribute/card.hh
1 // Copyright (C) 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_MORPHO_ATTRIBUTE_CARD_HH
27 # define MLN_MORPHO_ATTRIBUTE_CARD_HH
28 
36 
37 # include <mln/accu/internal/base.hh>
38 # include <mln/util/pix.hh>
39 
40 
41 namespace mln
42 {
43 
44 
45  // Forward declaration.
46 
47  namespace morpho {
48  namespace attribute {
49  template <typename I> class card;
50  }
51  }
52 
53 
54  // Traits.
55 
56  namespace trait
57  {
58 
59  template <typename I>
60  struct accumulator_< morpho::attribute::card<I> >
61  {
62  typedef accumulator::has_untake::no has_untake;
63  typedef accumulator::has_set_value::no has_set_value;
64  typedef accumulator::has_stop::no has_stop;
65  typedef accumulator::when_pix::use_none when_pix;
66  };
67 
68  } // end of namespace mln::trait
69 
70 
71  namespace morpho
72  {
73 
74  namespace attribute
75  {
76 
78 
79  template <typename I>
80  class card : public mln::accu::internal::base< unsigned, card<I> >
81  {
83  public:
84 
85  typedef mln_psite(I) argument;
86 
87  card();
88 
91  void init();
92 
93  void take();
94  void take(const argument& s);
95  void take(const util::pix<I>& px);
96  void take(const card<I>& other);
97 
98  void take_as_init(); // Extra version.
99  void take_as_init_(const util::pix<I>& px); // Overload.
101 
103  unsigned to_result() const;
104 
107  bool is_valid() const;
108 
109  protected:
111  unsigned c_;
112  };
113 
114 
115 
116 # ifndef MLN_INCLUDE_ONLY
117 
118  template <typename I>
119  inline
120  card<I>::card()
121  {
122  init();
123  }
124 
125  template <typename I>
126  inline
127  void
128  card<I>::init()
129  {
130  c_ = 0;
131  }
132 
133  // take.
134 
135  template <typename I>
136  inline
137  void
138  card<I>::take()
139  {
140  ++c_;
141  }
142 
143  template <typename I>
144  inline
145  void
146  card<I>::take(const argument&)
147  {
148  take();
149  }
150 
151  template <typename I>
152  inline
153  void
154  card<I>::take(const util::pix<I>&)
155  {
156  take();
157  }
158 
159  template <typename I>
160  inline
161  void
162  card<I>::take(const card<I>& other)
163  {
164  c_ += other.c_;
165  }
166 
167  // take_as_init.
168 
169  template <typename I>
170  inline
171  void
173  {
174  init();
175  take();
176  }
177 
178  template <typename I>
179  inline
180  void
181  card<I>::take_as_init_(const util::pix<I>&)
182  {
183  this->take_as_init();
184  }
185 
186  template <typename I>
187  inline
188  unsigned
189  card<I>::to_result() const
190  {
191  return c_;
192  }
193 
194  template <typename I>
195  inline
196  bool
197  card<I>::is_valid() const
198  {
199  return true;
200  }
201 
202 # endif // ! MLN_INCLUDE_ONLY
203 
204  } // end of namespace mln::morpho::attribute
205 
206  } // end of namespace mln::morpho
207 
208 } // end of namespace mln
209 
210 
211 #endif // ! MLN_MORPHO_ATTRIBUTE_CARD_HH