$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
multi_site.hh
1 // Copyright (C) 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_UTIL_MULTI_SITE_HH
27 # define MLN_UTIL_MULTI_SITE_HH
28 
31 
32 # include <cstddef>
33 
34 # include <algorithm>
35 # include <vector>
36 
37 # include <mln/core/concept/object.hh>
38 
39 # include <mln/util/ord.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace util
46  {
47 
48  template <typename P>
49  struct multi_site : public mln::Object< multi_site<P> >
50  {
51  // The type of a single site, called a location.
52  typedef P location;
53  /* FIXME: We should not need to define this typedef
54  (see. mln::internal::image_base's site `coord' typedef). */
55  typedef mln_coord(P) coord;
56 
57  typedef std::vector<P> container;
58  typedef typename container::size_type size_type;
59  typedef typename container::reference reference;
60  typedef typename container::const_reference const_reference;
61 
64  void push_back(const P& p);
65 
66  void reserve(size_type n);
67 
68  size_type size() const;
69 
70  reference operator[](size_type n);
71  const_reference operator[](size_type n) const;
72 
73  const_reference front() const;
74  reference front();
76 
77  container sites;
78  };
79 
80 
81  /* FIXME: Required by an assertion in mln::p_queue_fast<P>::has();
82  shouldn't there be no requirements on sites? */
83  template <typename P>
84  bool
85  operator==(const multi_site<P>& lhs, const multi_site<P>& rhs);
86 
87  /* FIXME: Required (indirectly) by a postcondition in
88  mln::morpho::dilation. */
89  template <typename P>
90  bool
91  operator< (const multi_site<P>& lhs, const multi_site<P>& rhs);
92 
93 
94 
95 # ifndef MLN_INCLUDE_ONLY
96 
97  template <typename P>
98  void
99  multi_site<P>::push_back(const P& p)
100  {
101  sites.push_back(p);
102  }
103 
104  template <typename P>
105  void
106  multi_site<P>::reserve(size_type n)
107  {
108  sites.reserve(n);
109  }
110 
111  template <typename P>
112  typename multi_site<P>::size_type
113  multi_site<P>::size() const
114  {
115  return sites.size();
116  }
117 
118  template <typename P>
119  typename multi_site<P>::reference
120  multi_site<P>::operator[](size_type n)
121  {
122  return sites[n];
123  }
124 
125  template <typename P>
126  typename multi_site<P>::const_reference
127  multi_site<P>::operator[](size_type n) const
128  {
129  return sites[n];
130  }
131 
132  template <typename P>
133  typename multi_site<P>::const_reference
134  multi_site<P>::front() const
135  {
136  mln_precondition(!sites.empty());
137  return sites[0];
138  }
139 
140  template <typename P>
141  typename multi_site<P>::reference
143  {
144  mln_precondition(!sites.empty());
145  return sites[0];
146  }
147 
148 
149  template <typename P>
150  bool
151  operator==(const multi_site<P>& lhs, const multi_site<P>& rhs)
152  {
153  return lhs.sites == rhs.sites;
154  }
155 
156  template <typename P>
157  bool
158  operator< (const multi_site<P>& lhs, const multi_site<P>& rhs)
159  {
160  // FIXME: This comparison is meaningless, since LHS and RHS are
161  // not sorted!
162  return std::lexicographical_compare(lhs.sites.begin(), lhs.sites.end(),
163  rhs.sites.begin(), rhs.sites.end(),
164  util::ord<P>());
165  }
166 
167 # endif // ! MLN_INCLUDE_ONLY
168 
169  } // end of mln::util
170 
171 } // end of mln
172 
173 
174 #endif // ! MLN_UTIL_MULTI_SITE_HH