$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
label_used.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (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_ACCU_LABEL_USED_HH
28 # define MLN_ACCU_LABEL_USED_HH
29 
33 
34 # include <mln/accu/internal/base.hh>
35 # include <mln/core/concept/meta_accumulator.hh>
36 # include <mln/math/max.hh>
37 # include <mln/value/next.hh>
38 # include <mln/fun/i2v/array.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace accu
45  {
46 
51  //
52  template <typename L>
53  struct label_used : public mln::accu::internal::base< const fun::i2v::array<bool>& , label_used<L> >
54  {
55  typedef L argument;
56 
57  label_used();
58 
60  void init();
61 
64  void take(const argument&);
65  void take(const label_used<L>& other);
67 
69  const fun::i2v::array<bool>& to_result() const;
70 
73  bool is_valid() const;
74 
75  protected:
78  };
79 
80 
81  namespace meta
82  {
83 
85  struct label_used : public Meta_Accumulator< label_used >
86  {
87  template <typename L>
88  struct with
89  {
91  };
92  };
93 
94  } // end of namespace mln::accu::meta
95 
96 
97 
98 # ifndef MLN_INCLUDE_ONLY
99 
100  template <typename L>
101  inline
103  {
104  init();
105  }
106 
107  template <typename L>
108  inline
109  void
111  {
112  label_used_.resize(1, true);
113  }
114 
115  template <typename L>
116  inline
117  void
118  label_used<L>::take(const argument& l)
119  {
120  if (label_used_.size() <= l)
121  label_used_.resize(value::next(l), false);
122 
123  label_used_(l) = true;
124  }
125 
126  template <typename L>
127  inline
128  void
129  label_used<L>::take(const label_used<L>& other)
130  {
131  unsigned
132  max_size = mln::math::max(other.to_result().size(), label_used_.size());
133 
134  label_used_.resize(max_size, false);
135  for (unsigned i = 1; i < label_used_.size(); ++i)
136  label_used_(i) = label_used_(i) || other.to_result()(i);
137  }
138 
139  template <typename L>
140  inline
141  const fun::i2v::array<bool>&
143  {
144  return label_used_;
145  }
146 
147  template <typename L>
148  inline
149  bool
151  {
152  return true;
153  }
154 
155 # endif // ! MLN_INCLUDE_ONLY
156 
157  } // end of namespace mln::accu
158 
159 } // end of namespace mln
160 
161 
162 #endif // ! MLN_ACCU_LABEL_USED_HH