$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_vaccess.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development 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_VACCESS_HH
28 # define MLN_CORE_SITE_SET_P_VACCESS_HH
29 
33 
34 # include <utility>
35 # include <vector>
36 # include <mln/core/concept/site_set.hh>
37 # include <mln/core/site_set/p_double.hh>
38 # include <mln/core/internal/site_set_base.hh>
39 # include <mln/core/internal/pseudo_site_base.hh>
40 # include <mln/core/internal/site_set_impl.hh>
41 # include <mln/value/set.hh>
42 
43 
44 namespace mln
45 {
46 
47  // Forward declaration.
48  template <typename V, typename S> class p_vaccess;
49 
50 
51 
52  namespace trait
53  {
54 
55  template <typename V, typename S>
56  struct site_set_< p_vaccess<V,S> >
57  {
58  typedef mln_trait_site_set_nsites(S) nsites;
59  typedef mln_trait_site_set_bbox(S) bbox;
60  typedef trait::site_set::contents::growing contents;
61  typedef trait::site_set::arity::multiple arity;
62  };
63 
64  } // end of namespace trait
65 
66 
67 
71  template <typename V, typename S>
72  class p_vaccess : public internal::site_set_base_< mln_site(S),
73  p_vaccess<V,S> >,
74  public internal::site_set_impl< S >
75  {
76  typedef p_vaccess<V,S> self_;
77  public:
78 
80  typedef V value;
81 
84  typedef vset t_eligible_values_set; // FIXME: Required by value set iterators...
85 
87  typedef S pset;
88 
91 
94 
97 
99  typedef fwd_piter piter;
100 
101 
103  p_vaccess();
104  p_vaccess(const V& vset);
105 
106 
108  bool has(const psite& p) const;
109 
112  bool has(const V& v, const mln_psite(S)& p) const;
113 
115  bool is_valid() const;
116 
117 
119  typedef mln_element(S) element;
120 
122  typedef std::pair<V, element> i_element;
123 
125  void insert(const i_element& v_e);
126 
128  void insert(const V& v, const element& e);
129 
130 
131  // Clear this set.
132  void clear();
133 
134 
136  const mln::value::set<V>& values() const;
137 
139  const S& operator()(const V& v) const;
140 
141 
143  std::size_t memory_size() const;
144 
146  // Required by p_double-related classes.
147  const mln::value::set<V>& set_1_() const;
148  const S& set_2_(const V& v) const;
150 
151  protected:
152 
153  mln::value::set<V> vs_;
154  std::vector<S> ps_;
155  };
156 
157 
158 
159 
160 # ifndef MLN_INCLUDE_ONLY
161 
162 
163  // p_vaccess<V,S>
164 
165  template <typename V, typename S>
166  inline
168  : vs_(),
169  ps_(vs_.nvalues())
170  {
171  }
172 
173  template <typename V, typename S>
174  inline
175  p_vaccess<V,S>::p_vaccess(const V& vset)
176  : vs_(vset),
177  ps_(vs_.nvalues())
178  {
179  }
180 
181  template <typename V, typename S>
182  inline
183  bool
184  p_vaccess<V,S>::has(const psite&) const
185  {
186  // FIXME
187  return true;
188  }
189 
190  template <typename V, typename S>
191  inline
192  bool
193  p_vaccess<V,S>::has(const V& v, const mln_psite(S)& p) const
194  {
195  return ps_[vs_.index_of(v)].has(p);
196  }
197 
198  template <typename V, typename S>
199  inline
200  bool
202  {
203  // FIXME
204  return true;
205  }
206 
207  template <typename V, typename S>
208  inline
209  void
210  p_vaccess<V,S>::insert(const V& v, const element& e)
211  {
212  ps_[vs_.index_of(v)].insert(e);
213  this->update_nsites_(e);
214  this->update_bbox_(e);
215  }
216 
217  template <typename V, typename S>
218  inline
219  void
220  p_vaccess<V,S>::insert(const i_element& v_e)
221  {
222  insert(v_e.first, v_e.second);
223  }
224 
225  template <typename V, typename S>
226  inline
227  void
229  {
230  const unsigned n = ps_.size();
231  for (unsigned i = 0; i < n; ++i)
232  ps_[i].clear();
233  }
234 
235  template <typename V, typename S>
236  inline
237  const S&
238  p_vaccess<V,S>::operator()(const V& v) const
239  {
240  return ps_[vs_.index_of(v)];
241  }
242 
243  template <typename V, typename S>
244  inline
245  std::size_t
247  {
248  std::size_t mem = 0;
249  const unsigned n = ps_.size();
250  for (unsigned i = 0; i < n; ++i)
251  mem += ps_[i].memory_size();
252  return sizeof(*this) + mem;
253  }
254 
255  template <typename V, typename S>
256  inline
257  const mln::value::set<V>&
258  p_vaccess<V,S>::values() const
259  {
260  return vs_;
261  }
262 
263  template <typename V, typename S>
264  inline
265  const mln::value::set<V>&
266  p_vaccess<V,S>::set_1_() const
267  {
268  return vs_;
269  }
270 
271  template <typename V, typename S>
272  inline
273  const S&
274  p_vaccess<V,S>::set_2_(const V& v) const
275  {
276  return ps_[vs_.index_of(v)];
277  }
278 
279 # endif // ! MLN_INCLUDE_ONLY
280 
281 } // end of namespace mln
282 
283 
284 #endif // ! MLN_CORE_SITE_SET_P_VACCESS_HH