Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009, 2011 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH 00028 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH 00029 00030 00036 00037 00038 # include <mln/core/internal/image_domain_morpher.hh> 00039 # include <mln/core/site_set/p_if.hh> 00040 # include <mln/fun/p2b/has.hh> 00041 00042 # include <mln/debug/println.hh> 00043 00044 00045 namespace mln 00046 { 00047 00048 00049 // Forward declaration. 00050 template <typename I, typename S> struct sub_image_if; 00051 00052 00053 namespace internal 00054 { 00055 00057 template <typename I, typename S> 00058 struct data< sub_image_if<I,S> > 00059 { 00060 data(I& ima, const S& s); 00061 00062 I ima_; 00063 p_if< S, fun::p2b::has<I> > s_; 00064 }; 00065 00066 } // end of namespace mln::internal 00067 00068 00069 00070 namespace trait 00071 { 00072 00073 template <typename I, typename S> 00074 struct image_< sub_image_if<I,S> > : default_image_morpher< I, 00075 mln_value(I), 00076 sub_image_if<I,S> > 00077 { 00078 // private: 00079 // typedef mln_trait_image_data(I) I_data_; 00080 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_; 00081 // public: 00082 00083 typedef trait::image::category::domain_morpher category; 00084 00085 typedef trait::image::ext_domain::none ext_domain; // No extension of domain. 00086 typedef trait::image::ext_value::irrelevant ext_value; 00087 typedef trait::image::ext_io::irrelevant ext_io; 00088 00089 typedef trait::image::value_storage::disrupted value_storage; 00090 // HOT FIXME: except if S is a Box 00091 }; 00092 00093 } // end of namespace mln::trait 00094 00095 00096 00100 // 00101 template <typename I, typename S> 00102 struct sub_image_if : public internal::image_domain_morpher< I, 00103 p_if< S, fun::p2b::has<I> >, 00104 sub_image_if<I,S> > 00105 { 00107 typedef sub_image_if< tag::image_<I>, tag::domain_<S> > skeleton; 00108 00110 sub_image_if(); 00111 00113 sub_image_if(I& ima, const S& s); 00114 00116 void init_(I& ima, const S& s); 00117 00119 const p_if< S, fun::p2b::has<I> >& domain() const; 00120 00121 // /// Const promotion via conversion. 00122 // operator sub_image_if<const I, S>() const; 00123 }; 00124 00125 00126 00127 00128 00129 template <typename I, typename S> 00130 sub_image_if<const I, S> 00131 operator / (const Image<I>& ima, const Site_Set<S>& s); 00132 00133 00134 template <typename I, typename S> 00135 sub_image_if<I, S> 00136 operator / (Image<I>& ima, const Site_Set<S>& s); 00137 00138 00139 template <typename I, typename S, typename J> 00140 void init_(tag::image_t, sub_image_if<I,S>& target, const J& model); 00141 00142 00143 00144 # ifndef MLN_INCLUDE_ONLY 00145 00146 // init_ 00147 00148 template <typename I, typename S, typename J> 00149 inline 00150 void init_(tag::image_t, sub_image_if<I,S>& target, const J& model) 00151 { 00152 I ima; 00153 init_(tag::image, ima, model); 00154 S s; 00155 init_(tag::domain, s, model); 00156 target.init_(ima, s); 00157 } 00158 00159 00160 // internal::data< sub_image_if<I,S> > 00161 00162 namespace internal 00163 { 00164 00165 template <typename I, typename S> 00166 inline 00167 data< sub_image_if<I,S> >::data(I& ima, const S& s) 00168 : ima_(ima) 00169 { 00170 typedef fun::p2b::has<I> F; 00171 F f(ima); 00172 s_ = p_if<S,F>(s, f); 00173 } 00174 00175 } // end of namespace mln::internal 00176 00177 00178 // sub_image_if<I,S> 00179 00180 template <typename I, typename S> 00181 inline 00182 sub_image_if<I,S>::sub_image_if() 00183 { 00184 } 00185 00186 template <typename I, typename S> 00187 inline 00188 sub_image_if<I,S>::sub_image_if(I& ima, const S& s) 00189 { 00190 init_(ima, s); 00191 } 00192 00193 template <typename I, typename S> 00194 inline 00195 void 00196 sub_image_if<I,S>::init_(I& ima, const S& s) 00197 { 00198 mln_precondition(! this->is_valid()); 00199 this->data_ = new internal::data< sub_image_if<I,S> >(ima, s); 00200 } 00201 00202 template <typename I, typename S> 00203 inline 00204 const p_if< S, fun::p2b::has<I> >& 00205 sub_image_if<I,S>::domain() const 00206 { 00207 return this->data_->s_; 00208 } 00209 00210 // template <typename I, typename S> 00211 // inline 00212 // sub_image_if<I,S>::operator sub_image_if<const I, S>() const 00213 // { 00214 // sub_image_if<const I, S> tmp(this->data_->ima_, 00215 // this->data_->s_); 00216 // return tmp; 00217 // } 00218 00219 00220 // Operators. 00221 00222 template <typename I, typename S> 00223 inline 00224 sub_image_if<const I, S> 00225 operator / (const Image<I>& ima, const Site_Set<S>& s) 00226 { 00227 // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0); 00228 sub_image_if<const I, S> tmp(exact(ima), exact(s)); 00229 return tmp; 00230 } 00231 00232 template <typename I, typename S> 00233 inline 00234 sub_image_if<I, S> 00235 operator / (Image<I>& ima, const Site_Set<S>& s) 00236 { 00237 // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0); 00238 sub_image_if<I, S> tmp(exact(ima), exact(s)); 00239 return tmp; 00240 } 00241 00242 # endif // ! MLN_INCLUDE_ONLY 00243 00244 } // end of namespace mln 00245 00246 00247 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH