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