$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_if.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 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_IF_HH
28 # define MLN_CORE_SITE_SET_P_IF_HH
29 
36 
37 # include <mln/core/internal/site_set_base.hh>
38 # include <mln/core/concept/function.hh>
39 
40 
41 namespace mln
42 {
43 
44  // Forward declarations.
45  template <typename S, typename F> class p_if;
46  template <typename Pi, typename S, typename F> struct p_if_piter_;
47 
48 
49  namespace trait
50  {
51 
52  template <typename S, typename F>
53  struct site_set_< p_if<S,F> >
54  {
55  typedef trait::site_set::nsites::unknown nsites;
56  typedef trait::site_set::bbox::unknown bbox;
57  typedef trait::site_set::contents::fixed contents;
58  typedef mln_trait_site_set_arity(S) arity;
59  };
60 
61  } // end of namespace trait
62 
63 
72  template <typename S, typename F>
73  p_if<S, F>
74  operator | (const Site_Set<S>& s, const Function_v2b<F>& f);
75 
76 
77 
81 
85  template <typename S, typename F>
86  class p_if : public internal::site_set_base_< mln_psite(S), p_if<S,F> >
87  {
88  typedef p_if<S,F> self_;
90  public:
91 
93  typedef mln_element(S) element;
94 
95 
97  typedef mln_psite(S) psite;
98 
100  typedef p_if_piter_<mln_fwd_piter(S), S, F> fwd_piter;
101 
103  typedef p_if_piter_<mln_bkd_piter(S), S, F> bkd_piter;
104 
106  typedef fwd_piter piter;
107 
108 
110  p_if(const S& s, const F& f);
111 
113  p_if();
114 
115 
117  bool is_valid() const;
118 
119 
121  bool has(const psite& p) const;
122 
124  const S& overset() const;
125 
127  bool pred(const psite& p) const;
128 
130  const F& predicate() const;
131 
132 
134  std::size_t memory_size() const;
135 
136  protected:
137 
138  S s_;
139  F f_;
140  };
141 
142 
143 
144 # ifndef MLN_INCLUDE_ONLY
145 
146 
147  template <typename S, typename F>
148  inline
149  p_if<S, F>
150  operator | (const Site_Set<S>& s, const Function_v2b<F>& f)
151  {
152  p_if<S, F> tmp(exact(s), exact(f));
153  return tmp;
154  }
155 
156 
157  // p_if<S,F>
158 
159  template <typename S, typename F>
160  inline
161  bool
162  p_if<S,F>::has(const psite& p) const
163  {
164  return s_.has(p) && f_(p) == true;
165  }
166 
167  template <typename S, typename F>
168  inline
169  bool
170  p_if<S,F>::is_valid() const
171  {
172  return s_.is_valid();
173  }
174 
175  template <typename S, typename F>
176  inline
177  const S&
178  p_if<S,F>::overset() const
179  {
180  return s_;
181  }
182 
183  template <typename S, typename F>
184  inline
185  bool
186  p_if<S,F>::pred(const psite& p) const
187  {
188  return f_(p);
189  }
190 
191  template <typename S, typename F>
192  inline
193  p_if<S,F>::p_if(const S& s, const F& f)
194  : s_(s),
195  f_(f)
196  {
197  }
198 
199  template <typename S, typename F>
200  inline
202  {
203  }
204 
205  template <typename S, typename F>
206  inline
207  const F&
208  p_if<S,F>::predicate() const
209  {
210  return f_;
211  }
212 
213  template <typename S, typename F>
214  inline
215  std::size_t
216  p_if<S,F>::memory_size() const
217  {
218  return s_.memory_size() + sizeof(f_);
219  }
220 
221 # endif // ! MLN_INCLUDE_ONLY
222 
223 } // end of namespace mln
224 
225 
226 
227 # include <mln/core/site_set/p_if_piter.hh>
228 
229 
230 
231 #endif // ! MLN_CORE_SITE_SET_P_IF_HH