$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_set.hh
1 // Copyright (C) 2007, 2008, 2009, 2010 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_HH
28 # define MLN_CORE_SITE_SET_P_SET_HH
29 
34 
35 # include <mln/core/site_set/p_array.hh>
36 # include <mln/util/set.hh>
37 
38 
39 namespace mln
40 {
41 
42  // Forward declaration.
43  template <typename P> class p_set;
44 
45 
46  namespace trait
47  {
48 
49  template <typename P>
50  struct site_set_< p_set<P> >
51  {
52  typedef trait::site_set::nsites::known nsites;
53  typedef trait::site_set::bbox::unknown bbox;
54  typedef trait::site_set::contents::free contents;
55  typedef trait::site_set::arity::unique arity;
56  };
57 
58  } // end of namespace trait
59 
60 
61 
65 
70  template <typename P>
71  class p_set : public internal::site_set_base_< P, p_set<P> >
72  {
73  typedef p_set<P> self_;
74  public:
75 
77  typedef P element;
78 
81 
84 
87 
89  typedef fwd_piter piter;
90 
91 
93  p_set();
94 
95 
97  bool has(const psite& p) const;
98 
100  bool has(const P& p) const;
101 
103  bool has(const util::index& i) const;
104 
106  bool is_valid() const;
107 
108 
110  unsigned nsites() const;
111 
113  bool is_empty() const;
114 
115 
117  typedef P i_element;
118 
120  void insert(const P& p);
121 
123  typedef P r_element;
124 
126  void remove(const P& p);
127 
129  void clear();
130 
131 
133  const P& operator[](unsigned i) const;
134 
135 
137  std::size_t memory_size() const;
138 
140  const std::vector<P>& std_vector() const;
141 
143  const util::set<P>& util_set() const;
144 
145  protected:
146 
148  };
149 
150 
151 
152 # ifndef MLN_INCLUDE_ONLY
153 
154  template <typename P>
155  inline
157  {
158  }
159 
160  template <typename P>
161  inline
162  bool
163  p_set<P>::has(const P& p) const
164  {
165  return s_.has(p);
166  }
167 
168  template <typename P>
169  inline
170  bool
171  p_set<P>::has(const psite& p) const
172  {
173  mln_precondition(p.target_() == this); // FIXME: Refine.
174  if (! has(p.index()))
175  return false;
176  mln_invariant(p.to_site() == (*this)[p.index()]);
177  return true;
178  }
179 
180  template <typename P>
181  inline
182  bool
183  p_set<P>::has(const util::index& i) const
184  {
185  return i >= 0 && unsigned(i) < nsites();
186  }
187 
188  template <typename P>
189  inline
190  bool
191  p_set<P>::is_valid() const
192  {
193  return true;
194  }
195 
196  template <typename P>
197  inline
198  unsigned
199  p_set<P>::nsites() const
200  {
201  return s_.nelements();
202  }
203 
204  template <typename P>
205  inline
206  bool
207  p_set<P>::is_empty() const
208  {
209  return s_.is_empty();
210  }
211 
212  template <typename P>
213  inline
214  void
215  p_set<P>::insert(const P& p)
216  {
217  s_.insert(p);
218  }
219 
220  template <typename P>
221  inline
222  void
223  p_set<P>::remove(const P& p)
224  {
225  s_.remove(p);
226  }
227 
228  template <typename P>
229  inline
230  void
232  {
233  s_.clear();
234  }
235 
236  template <typename P>
237  inline
238  const P&
239  p_set<P>::operator[](unsigned i) const
240  {
241  mln_precondition(i < nsites());
242  return s_[i];
243  }
244 
245  template <typename P>
246  inline
247  std::size_t
248  p_set<P>::memory_size() const
249  {
250  return s_.memory_size();
251  }
252 
253  template <typename P>
254  inline
255  const std::vector<P>&
256  p_set<P>::std_vector() const
257  {
258  return s_.std_vector();
259  }
260 
261  template <typename P>
262  inline
263  const util::set<P>&
264  p_set<P>::util_set() const
265  {
266  return s_;
267  }
268 
269 # endif // ! MLN_INCLUDE_ONLY
270 
271 } // end of namespace mln
272 
273 
274 #endif // ! MLN_CORE_SITE_SET_P_SET_HH