Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_vaccess.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_CORE_SITE_SET_P_VACCESS_HH
27 # define MLN_CORE_SITE_SET_P_VACCESS_HH
28 
32 
33 # include <utility>
34 # include <mln/core/concept/site_set.hh>
35 # include <mln/core/site_set/p_double.hh>
36 # include <mln/core/internal/site_set_base.hh>
37 # include <mln/core/internal/pseudo_site_base.hh>
38 # include <mln/core/internal/site_set_impl.hh>
39 # include <mln/value/set.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename V, typename S> class p_vaccess;
47 
48 
49 
50  namespace trait
51  {
52 
53  template <typename V, typename S>
54  struct site_set_< p_vaccess<V,S> >
55  {
56  typedef mln_trait_site_set_nsites(S) nsites;
57  typedef mln_trait_site_set_bbox(S) bbox;
58  typedef trait::site_set::contents::growing contents;
59  typedef trait::site_set::arity::multiple arity;
60  };
61 
62  } // end of namespace trait
63 
64 
65 
69  template <typename V, typename S>
70  class p_vaccess : public internal::site_set_base_< mln_site(S),
71  p_vaccess<V,S> >,
72  public internal::site_set_impl< S >
73  {
74  typedef p_vaccess<V,S> self_;
75  public:
76 
78  typedef V value;
79 
82  typedef vset t_eligible_values_set; // FIXME: Required by value set iterators...
83 
85  typedef S pset;
86 
88  typedef p_double_psite<self_, S> psite;
89 
91  typedef p_double_piter<self_, mln_fwd_viter(vset), mln_fwd_piter(S)> fwd_piter;
92 
94  typedef p_double_piter<self_, mln_bkd_viter(vset), mln_bkd_piter(S)> bkd_piter;
95 
97  typedef fwd_piter piter;
98 
99 
101  p_vaccess();
102  p_vaccess(const V& vset);
103 
104 
106  bool has(const psite& p) const;
107 
110  bool has(const V& v, const mln_psite(S)& p) const;
111 
113  bool is_valid() const;
114 
115 
117  typedef mln_element(S) element;
118 
120  typedef std::pair<V, element> i_element;
121 
123  void insert(const i_element& v_e);
124 
126  void insert(const V& v, const element& e);
127 
128 
129  // Clear this set.
130  void clear();
131 
132 
134  const mln::value::set<V>& values() const;
135 
137  const S& operator()(const V& v) const;
138 
139 
141  std::size_t memory_size() const;
142 
143  // Required by p_double-related classes.
144  const mln::value::set<V>& set_1_() const;
145  const S& set_2_(const V& v) const;
146 
147  protected:
148 
149  mln::value::set<V> vs_;
150  std::vector<S> ps_;
151  };
152 
153 
154 
155 
156 # ifndef MLN_INCLUDE_ONLY
157 
158 
159  // p_vaccess<V,S>
160 
161  template <typename V, typename S>
162  inline
164  : vs_(),
165  ps_(vs_.nvalues())
166  {
167  }
168 
169  template <typename V, typename S>
170  inline
171  p_vaccess<V,S>::p_vaccess(const V& vset)
172  : vs_(vset),
173  ps_(vs_.nvalues())
174  {
175  }
176 
177  template <typename V, typename S>
178  inline
179  bool
180  p_vaccess<V,S>::has(const psite&) const
181  {
182  // FIXME
183  return true;
184  }
185 
186  template <typename V, typename S>
187  inline
188  bool
189  p_vaccess<V,S>::has(const V& v, const mln_psite(S)& p) const
190  {
191  return ps_[vs_.index_of(v)].has(p);
192  }
193 
194  template <typename V, typename S>
195  inline
196  bool
198  {
199  // FIXME
200  return true;
201  }
202 
203  template <typename V, typename S>
204  inline
205  void
206  p_vaccess<V,S>::insert(const V& v, const element& e)
207  {
208  ps_[vs_.index_of(v)].insert(e);
209  this->update_nsites_(e);
210  this->update_bbox_(e);
211  }
212 
213  template <typename V, typename S>
214  inline
215  void
216  p_vaccess<V,S>::insert(const i_element& v_e)
217  {
218  insert(v_e.first, v_e.second);
219  }
220 
221  template <typename V, typename S>
222  inline
223  void
225  {
226  const unsigned n = ps_.size();
227  for (unsigned i = 0; i < n; ++i)
228  ps_[i].clear();
229  }
230 
231  template <typename V, typename S>
232  inline
233  const S&
234  p_vaccess<V,S>::operator()(const V& v) const
235  {
236  return ps_[vs_.index_of(v)];
237  }
238 
239  template <typename V, typename S>
240  inline
241  std::size_t
243  {
244  std::size_t mem = 0;
245  const unsigned n = ps_.size();
246  for (unsigned i = 0; i < n; ++i)
247  mem += ps_[i].memory_size();
248  return sizeof(*this) + mem;
249  }
250 
251  template <typename V, typename S>
252  inline
253  const mln::value::set<V>&
255  {
256  return vs_;
257  }
258 
259  template <typename V, typename S>
260  inline
261  const mln::value::set<V>&
262  p_vaccess<V,S>::set_1_() const
263  {
264  return vs_;
265  }
266 
267  template <typename V, typename S>
268  inline
269  const S&
270  p_vaccess<V,S>::set_2_(const V& v) const
271  {
272  return ps_[vs_.index_of(v)];
273  }
274 
275 # endif // ! MLN_INCLUDE_ONLY
276 
277 } // end of namespace mln
278 
279 
280 #endif // ! MLN_CORE_SITE_SET_P_VACCESS_HH