Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
classical_window_base.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_INTERNAL_CLASSICAL_WINDOW_BASE_HH
27 # define MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH
28 
39 # include <mln/core/window.hh>
40 # include <mln/core/dpsites_piter.hh>
41 
42 
43 
44 namespace mln
45 {
46 
47  namespace internal
48  {
49 
53  template <typename D, typename E>
54  class classical_window_base : public window_base<D, E>
55  {
56  public:
57 
58 
60  typedef window<D> regular;
61 
62 
64  typedef dpsites_fwd_piter<E> fwd_qiter;
65 
67  typedef dpsites_fwd_piter<E> bkd_qiter;
68 
70  typedef fwd_qiter qiter;
71 
72 
74  unsigned size() const;
75 
77  bool is_empty() const;
78 
79 
81  bool is_centered() const;
82 
84  bool is_symmetric() const;
85 
87  void sym();
88 
89 
92  unsigned delta() const;
93 
94 
96  bool has(const D& dp) const;
97 
99  const D& dp(unsigned i) const;
100 
102  const std::vector<D>& vect() const;
103 
105  const std::vector<D>& std_vector() const;
106 
108  void print(std::ostream& ostr) const;
109 
110  protected:
111 
112  classical_window_base();
113 
114  void insert(const D& d);
115  unsigned delta_() const; // Default implementation based on win_.
116  void print_(std::ostream& ostr) const; // Default implementation based on win_.
117 
118  mln::window<D> win_;
119  };
120 
121 
122 
123 # ifndef MLN_INCLUDE_ONLY
124 
125  template <typename D, typename E>
126  inline
127  classical_window_base<D,E>::classical_window_base()
128  {
129  }
130 
131  template <typename D, typename E>
132  inline
133  unsigned
134  classical_window_base<D,E>::size() const
135  {
136  return win_.size();
137  }
138 
139  template <typename D, typename E>
140  inline
141  bool
142  classical_window_base<D,E>::is_empty() const
143  {
144  return win_.is_empty();
145  }
146 
147  template <typename D, typename E>
148  inline
149  bool
150  classical_window_base<D,E>::is_centered() const
151  {
152  mln_invariant(win_.is_centered());
153  return true;
154  }
155 
156  template <typename D, typename E>
157  inline
158  bool
159  classical_window_base<D,E>::is_symmetric() const
160  {
161  mln_invariant(win_.is_symmetric());
162  return true;
163  }
164 
165  template <typename D, typename E>
166  inline
167  void
168  classical_window_base<D,E>::sym()
169  {
170  mln_invariant(win_.is_symmetric());
171  // No-op.
172  }
173 
174  template <typename D, typename E>
175  inline
176  unsigned
177  classical_window_base<D,E>::delta() const
178  {
179  // void *v = (void*)(& classical_window_base<D,E>::delta_);
180  // void *w = (void*)(& E::delta_);
181  // std::cout << v << ' ' << w << std::endl;
182  return exact(this)->delta_();
183  }
184 
185  template <typename D, typename E>
186  inline
187  unsigned
188  classical_window_base<D,E>::delta_() const
189  {
190  return win_.delta();
191  }
192 
193  template <typename D, typename E>
194  inline
195  const D&
196  classical_window_base<D,E>::dp(unsigned i) const
197  {
198  mln_precondition(i < size());
199  return win_.dp(i);
200  }
201 
202  template <typename D, typename E>
203  inline
204  const std::vector<D>&
205  classical_window_base<D,E>::std_vector() const
206  {
207  return win_.std_vector();
208  }
209 
210  template <typename D, typename E>
211  inline
212  const std::vector<D>&
213  classical_window_base<D,E>::vect() const
214  {
215  return std_vector();
216  }
217 
218  template <typename D, typename E>
219  inline
220  bool
221  classical_window_base<D,E>::has(const D& dp) const
222  {
223  return win_.has(dp);
224  }
225 
226  template <typename D, typename E>
227  inline
228  void
229  classical_window_base<D,E>::insert(const D& d)
230  {
231  win_.insert(d);
232  }
233 
234  template <typename D, typename E>
235  inline
236  void
237  classical_window_base<D,E>::print(std::ostream& ostr) const
238  {
239  exact(this)->print_(ostr);
240  }
241 
242  template <typename D, typename E>
243  inline
244  void
245  classical_window_base<D,E>::print_(std::ostream& ostr) const
246  {
247  ostr << win_;
248  }
249 
250 # endif // ! MLN_INCLUDE_ONLY
251 
252  } // end of namespace internal
253 
254 } // end of namespace mln
255 
256 
257 #endif // ! MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH