$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_set_of.hh
1 // Copyright (C) 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (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_CORE_SITE_SET_P_SET_OF_HH
28 # define MLN_CORE_SITE_SET_P_SET_OF_HH
29 
37 # include <mln/core/site_set/p_double.hh>
38 # include <mln/core/internal/site_set_base.hh>
39 # include <mln/core/internal/site_set_impl.hh>
40 # include <mln/util/set.hh>
41 
42 
43 
44 namespace mln
45 {
46 
47  // Forward declaration.
48  template <typename S> class p_set_of;
49 
50 
51  namespace trait
52  {
53 
54  template <typename S>
55  struct site_set_< p_set_of<S> >
56  {
57  typedef mln_trait_site_set_nsites(S) nsites;
58  typedef mln_trait_site_set_bbox(S) bbox;
59  typedef trait::site_set::contents::growing contents;
60  typedef trait::site_set::arity::multiple arity;
61  };
62 
63  } // end of namespace trait
64 
65 
66 
71  template <typename S>
72  class p_set_of : public internal::site_set_base_< mln_site(S),
73  p_set_of<S> >,
74  public internal::site_set_impl<S>,
75  private mlc_is_a(S, Site_Set)::check_t
76  {
77  typedef p_set_of<S> self_;
78  typedef util::set<S> set_;
79  public:
80 
82  typedef S element;
83 
84 
87 
89  typedef p_double_piter<self_,
90  mln_fwd_eiter(set_),
91  mln_fwd_piter(S)> fwd_piter;
92 
94  typedef p_double_piter<self_,
95  mln_bkd_eiter(set_),
96  mln_bkd_piter(S)> bkd_piter;
97 
99  typedef fwd_piter piter;
100 
101 
103  p_set_of();
104 
105 
107  bool has(const psite& p) const;
108 
110  bool is_valid() const;
111 
112 
114  typedef S i_element;
115 
117  void insert(const S& s);
118 
119 
121  const S& operator[](unsigned i) const;
122 
124  unsigned nelements() const;
125 
126 
128  void clear();
129 
130 
132  std::size_t memory_size() const;
133 
135  const util::set<S>& set_hook_() const;
136 
137 
139  // Required by p_double-related classes.
140  const util::set<S>& set_1_() const;
141  template <typename I>
142  const S& set_2_(const I& it) const;
144 
145  protected:
146 
149  };
150 
151 
153  template <typename S>
154  std::ostream& operator<<(std::ostream& ostr, const p_set_of<S>& s);
155 
156 
157 
158 
159 # ifndef MLN_INCLUDE_ONLY
160 
161  template <typename S>
162  inline
164  {
165  }
166 
167  template <typename S>
168  inline
169  bool
170  p_set_of<S>::has(const psite& p) const
171  {
172  return p.index() < s_.nelements() && s_[p.index()].has(p.p());
173  }
174 
175  template <typename S>
176  inline
177  bool
178  p_set_of<S>::is_valid() const
179  {
180  return true;
181  }
182 
183  template <typename S>
184  inline
185  void
186  p_set_of<S>::insert(const S& s)
187  {
188  mln_precondition(s.is_valid());
189  s_.insert(s);
190  this->update_nsites_(s);
191  this->update_bbox_(s);
192  }
193 
194  template <typename S>
195  inline
196  const S&
197  p_set_of<S>::operator[](unsigned i) const
198  {
199  mln_precondition(i < s_.nelements());
200  return s_[i];
201  }
202 
203  template <typename S>
204  inline
205  unsigned
206  p_set_of<S>::nelements() const
207  {
208  return s_.nelements();
209  }
210 
211  template <typename S>
212  inline
213  void
214  p_set_of<S>::clear()
215  {
216  s_.clear();
217  mln_postcondition(this->is_empty());
218  }
219 
220  template <typename S>
221  inline
222  std::size_t
223  p_set_of<S>::memory_size() const
224  {
225  return s_.memory_size();
226  }
227 
228  template <typename S>
229  inline
230  const util::set<S>&
231  p_set_of<S>::set_hook_() const
232  {
233  return s_;
234  }
235 
236  template <typename S>
237  inline
238  const util::set<S>&
239  p_set_of<S>::set_1_() const
240  {
241  return s_;
242  }
243 
244  template <typename S>
245  template <typename I>
246  inline
247  const S&
248  p_set_of<S>::set_2_(const I& it) const
249  {
250  return it.element();
251  }
252 
253 
254  template <typename S>
255  std::ostream& operator<<(std::ostream& ostr, const p_set_of<S>& s)
256  {
257  return ostr << s.set_hook_();
258  }
259 
260 # endif // ! MLN_INCLUDE_ONLY
261 
262 } // end of namespace mln
263 
264 
265 #endif // ! MLN_CORE_SITE_SET_P_SET_OF_HH