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_IMAGE_DMORPH_IMAGE_IF_HH 00027 # define MLN_CORE_IMAGE_DMORPH_IMAGE_IF_HH 00028 00033 00034 # include <mln/core/internal/image_domain_morpher.hh> 00035 # include <mln/core/site_set/p_if.hh> 00036 # include <mln/pw/all.hh> 00037 # include <mln/convert/to_fun.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 // Forward declaration. 00044 template <typename I, typename F> struct image_if; 00045 00046 00047 namespace internal 00048 { 00049 00051 template <typename I, typename F> 00052 struct data< image_if<I,F> > 00053 { 00054 data(I& ima, const F& f); 00055 00056 I ima_; 00057 p_if<mln_domain(I), F> domain_; 00058 }; 00059 00060 } // end of namespace mln::internal 00061 00062 00063 namespace trait 00064 { 00065 00066 template <typename I, typename F> 00067 struct image_< image_if<I,F> > : default_image_morpher< I, 00068 mln_value(I), 00069 image_if<I,F> > 00070 { 00071 typedef trait::image::category::domain_morpher category; 00072 00073 typedef trait::image::ext_domain::none ext_domain; // No extension of domain. 00074 typedef trait::image::ext_value::irrelevant ext_value; 00075 typedef trait::image::ext_io::irrelevant ext_io; 00076 00077 typedef trait::image::vw_io::none vw_io; 00078 typedef trait::image::vw_set::none vw_set; 00079 typedef trait::image::value_alignment::not_aligned value_alignment; 00080 typedef trait::image::value_storage::disrupted value_storage; 00081 }; 00082 00083 } // end of namespace mln::trait 00084 00085 00086 00091 // 00092 template <typename I, typename F> 00093 struct image_if : public internal::image_domain_morpher< I, 00094 p_if<mln_domain(I), F>, 00095 image_if<I, F> > 00096 { 00098 typedef image_if< tag::image_<I>, tag::function_<F> > skeleton; 00099 00101 image_if(); 00102 00104 image_if(I& ima, const F& f); 00105 00106 void init_(I& ima, const F& f); 00107 00109 const p_if<mln_domain(I), F>& domain() const; 00110 00112 operator image_if<const I, F>() const; 00113 }; 00114 00115 00116 00117 // Operators. 00118 00119 00120 // Image | Function_v2b. 00121 00124 // 00125 template <typename I, typename F> 00126 image_if<I,F> 00127 operator | (Image<I>& ima, const Function_v2b<F>& f); 00128 00131 // 00132 template <typename I, typename F> 00133 image_if<const I,F> 00134 operator | (const Image<I>& ima, const Function_v2b<F>& f); 00135 00136 00137 00138 template <typename I, typename A> 00139 image_if< const I, fun::C<bool(*)(A)> > 00140 operator | (const Image<I>& ima, bool (*f)(A) ); 00141 00142 template <typename I, typename A> 00143 image_if< I, fun::C<bool(*)(A)> > 00144 operator | (Image<I>& ima, bool (*f)(A) ); 00145 00146 00147 00148 # ifndef MLN_INCLUDE_ONLY 00149 00150 // init_. 00151 00152 template <typename I, typename F> 00153 void init_(tag::function_t, F& f, const image_if<I,F>& model) 00154 { 00155 f = model.domain().predicate(); 00156 } 00157 00158 template <typename I, typename F, typename J> 00159 void init_(tag::image_t, image_if<I,F>& target, const J& model) 00160 { 00161 I ima; 00162 init_(tag::image, ima, exact(model)); 00163 F f; 00164 init_(tag::function, f, exact(model)); 00165 target.init_(ima, f); 00166 } 00167 00168 // internal::data< image_if<I,F> > 00169 00170 namespace internal 00171 { 00172 00173 template <typename I, typename F> 00174 inline 00175 data< image_if<I,F> >::data(I& ima, const F& f) 00176 : ima_(ima), 00177 domain_(ima.domain() | f) 00178 { 00179 } 00180 00181 } 00182 00183 00184 // image_if<I,F> 00185 00186 template <typename I, typename F> 00187 inline 00188 image_if<I,F>::image_if() 00189 { 00190 } 00191 00192 template <typename I, typename F> 00193 inline 00194 image_if<I,F>::image_if(I& ima, const F& f) 00195 { 00196 init_(ima, f); 00197 } 00198 00199 template <typename I, typename F> 00200 inline 00201 void 00202 image_if<I,F>::init_(I& ima, const F& f) 00203 { 00204 mln_precondition(! this->is_valid()); 00205 this->data_ = new internal::data< image_if<I,F> >(ima, f); 00206 } 00207 00208 template <typename I, typename F> 00209 inline 00210 const p_if<mln_domain(I), F>& 00211 image_if<I,F>::domain() const 00212 { 00213 mln_precondition(this->is_valid()); 00214 return this->data_->domain_; 00215 } 00216 00217 template <typename I, typename F> 00218 inline 00219 image_if<I,F>::operator image_if<const I,F>() const 00220 { 00221 mln_precondition(this->is_valid()); 00222 image_if<const I,F> tmp(this->data_->ima_, 00223 this->data_->domain_.predicate()); 00224 return tmp; 00225 } 00226 00227 00228 // Operators. 00229 00230 template <typename I, typename F> 00231 inline 00232 image_if<I,F> 00233 operator | (Image<I>& ima, const Function_v2b<F>& f) 00234 { 00235 image_if<I,F> tmp(exact(ima), exact(f)); 00236 return tmp; 00237 } 00238 00239 template <typename I, typename F> 00240 inline 00241 image_if<const I, F> 00242 operator | (const Image<I>& ima, const Function_v2b<F>& f) 00243 { 00244 image_if<const I, F> tmp(exact(ima), exact(f)); 00245 return tmp; 00246 } 00247 00248 00249 template <typename I, typename A> 00250 image_if< const I, fun::C<bool(*)(A)> > 00251 operator | (const Image<I>& ima, bool (*f)(A) ) 00252 { 00253 return exact(ima) | convert::to_fun(f); 00254 } 00255 00256 template <typename I, typename A> 00257 image_if< I, fun::C<bool(*)(A)> > 00258 operator | (Image<I>& ima, bool (*f)(A) ) 00259 { 00260 return exact(ima) | convert::to_fun(f); 00261 } 00262 00263 00264 # endif // ! MLN_INCLUDE_ONLY 00265 00266 } // end of namespace mln 00267 00268 00269 #endif // ! MLN_CORE_IMAGE_DMORPH_IMAGE_IF_HH