Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_CORE_SITE_SET_P_IF_HH 00027 # define MLN_CORE_SITE_SET_P_IF_HH 00028 00035 00036 # include <mln/core/internal/site_set_base.hh> 00037 # include <mln/core/concept/function.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 // Forward declarations. 00044 template <typename S, typename F> class p_if; 00045 template <typename Pi, typename S, typename F> struct p_if_piter_; 00046 00047 00048 namespace trait 00049 { 00050 00051 template <typename S, typename F> 00052 struct site_set_< p_if<S,F> > 00053 { 00054 typedef trait::site_set::nsites::unknown nsites; 00055 typedef trait::site_set::bbox::unknown bbox; 00056 typedef trait::site_set::contents::fixed contents; 00057 typedef mln_trait_site_set_arity(S) arity; 00058 }; 00059 00060 } // end of namespace trait 00061 00062 00069 template <typename S, typename F> 00070 p_if<S, F> 00071 operator | (const Site_Set<S>& s, const Function_v2b<F>& f); 00072 00073 00074 00078 00082 template <typename S, typename F> 00083 class p_if : public internal::site_set_base_< mln_psite(S), p_if<S,F> > 00084 { 00085 typedef p_if<S,F> self_; 00086 typedef internal::site_set_base_<mln_psite(S), self_> super_; 00087 public: 00088 00090 typedef mln_element(S) element; 00091 00092 00094 typedef mln_psite(S) psite; 00095 00097 typedef p_if_piter_<mln_fwd_piter(S), S, F> fwd_piter; 00098 00100 typedef p_if_piter_<mln_bkd_piter(S), S, F> bkd_piter; 00101 00103 typedef fwd_piter piter; 00104 00105 00107 p_if(const S& s, const F& f); 00108 00110 p_if(); 00111 00112 00114 bool is_valid() const; 00115 00116 00118 bool has(const psite& p) const; 00119 00121 const S& overset() const; 00122 00124 bool pred(const psite& p) const; 00125 00127 const F& predicate() const; 00128 00129 00131 std::size_t memory_size() const; 00132 00133 protected: 00134 00135 S s_; 00136 F f_; 00137 }; 00138 00139 00140 00141 # ifndef MLN_INCLUDE_ONLY 00142 00143 00144 template <typename S, typename F> 00145 inline 00146 p_if<S, F> 00147 operator | (const Site_Set<S>& s, const Function_v2b<F>& f) 00148 { 00149 p_if<S, F> tmp(exact(s), exact(f)); 00150 return tmp; 00151 } 00152 00153 00154 // p_if<S,F> 00155 00156 template <typename S, typename F> 00157 inline 00158 bool 00159 p_if<S,F>::has(const psite& p) const 00160 { 00161 return s_.has(p) && f_(p) == true; 00162 } 00163 00164 template <typename S, typename F> 00165 inline 00166 bool 00167 p_if<S,F>::is_valid() const 00168 { 00169 return s_.is_valid(); 00170 } 00171 00172 template <typename S, typename F> 00173 inline 00174 const S& 00175 p_if<S,F>::overset() const 00176 { 00177 return s_; 00178 } 00179 00180 template <typename S, typename F> 00181 inline 00182 bool 00183 p_if<S,F>::pred(const psite& p) const 00184 { 00185 return f_(p); 00186 } 00187 00188 template <typename S, typename F> 00189 inline 00190 p_if<S,F>::p_if(const S& s, const F& f) 00191 : s_(s), 00192 f_(f) 00193 { 00194 } 00195 00196 template <typename S, typename F> 00197 inline 00198 p_if<S,F>::p_if() 00199 { 00200 } 00201 00202 template <typename S, typename F> 00203 inline 00204 const F& 00205 p_if<S,F>::predicate() const 00206 { 00207 return f_; 00208 } 00209 00210 template <typename S, typename F> 00211 inline 00212 std::size_t 00213 p_if<S,F>::memory_size() const 00214 { 00215 return s_.memory_size() + sizeof(f_); 00216 } 00217 00218 # endif // ! MLN_INCLUDE_ONLY 00219 00220 } // end of namespace mln 00221 00222 00223 00224 # include <mln/core/site_set/p_if_piter.hh> 00225 00226 00227 00228 #endif // ! MLN_CORE_SITE_SET_P_IF_HH