Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
weighted_window_base.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_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
27 # define MLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
28 
32 
33 # include <mln/core/concept/weighted_window.hh>
34 
35 
36 namespace mln
37 {
38 
39  namespace internal
40  {
41 
45 
46  template <typename W, typename E>
47  struct weighted_window_base : public Weighted_Window<E>
48  {
49 
51  typedef W window;
52 
54  typedef mln_dpsite(W) dpsite;
55 
57  typedef mln_psite(W) psite;
58 
60  typedef mln_site(W) site;
61 
63  bool is_empty() const;
64 
67  unsigned size() const;
68 
72  bool is_centered() const;
73 
77  unsigned delta() const;
78 
82  const mln_dpsite(W)& dp(unsigned i) const;
83 
87  bool has(const mln_dpsite(W)& dp) const;
88 
90  bool is_valid() const;
91 
92  protected:
93  weighted_window_base();
94  };
95 
96 
97 # ifndef MLN_INCLUDE_ONLY
98 
99  template <typename W, typename E>
100  inline
101  weighted_window_base<W,E>::weighted_window_base()
102  {
103  }
104 
105  template <typename W, typename E>
106  inline
107  bool
108  weighted_window_base<W,E>::is_empty() const
109  {
110  return exact(this)->win().is_empty();
111  }
112 
113  template <typename W, typename E>
114  inline
115  unsigned
116  weighted_window_base<W,E>::size() const
117  {
118  mlc_equal(mln_trait_window_size(W),
119  trait::window::size::fixed)::check();
120  return exact(this)->win().size();
121  }
122 
123  template <typename W, typename E>
124  inline
125  bool
126  weighted_window_base<W,E>::is_centered() const
127  {
128  mlc_equal(mln_trait_window_support(W),
129  trait::window::support::regular)::check();
130  mlc_not_equal(mln_trait_window_definition(W),
131  trait::window::definition::varying)::check();
132  return exact(this)->win().is_centered();
133  }
134 
135  template <typename W, typename E>
136  inline
137  unsigned
138  weighted_window_base<W,E>::delta() const
139  {
140  mlc_equal(mln_trait_window_support(W),
141  trait::window::support::regular)::check();
142  mlc_not_equal(mln_trait_window_definition(W),
143  trait::window::definition::varying)::check();
144  return exact(this)->win().delta();
145  }
146 
147  template <typename W, typename E>
148  inline
149  const mln_dpsite(W)&
150  weighted_window_base<W,E>::dp(unsigned i) const
151  {
152  mlc_equal(mln_trait_window_support(W),
153  trait::window::support::regular)::check();
154  mlc_equal(mln_trait_window_definition(W),
155  trait::window::definition::unique)::check();
156  mln_precondition(i < this->size());
157  return exact(this)->win().dp(i);
158  }
159 
160  template <typename W, typename E>
161  inline
162  bool
163  weighted_window_base<W,E>::has(const mln_dpsite(W)& dp) const
164  {
165  mlc_equal(mln_trait_window_support(W),
166  trait::window::support::regular)::check();
167  mlc_equal(mln_trait_window_definition(W),
168  trait::window::definition::unique)::check();
169  return exact(this)->win().has(dp);
170  }
171 
172  template <typename W, typename E>
173  inline
174  bool
175  weighted_window_base<W,E>::is_valid() const
176  {
177  return true;
178  }
179 
180 # endif // ! MLN_INCLUDE_ONLY
181 
182  } // end of namespace mln::internal
183 
184 } // end of namespace mln
185 
186 
187 #endif // ! MLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH