Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and 00002 // Development 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_HH 00028 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_HH 00029 00037 00038 # include <mln/core/internal/image_domain_morpher.hh> 00039 00040 00041 00042 namespace mln 00043 { 00044 00045 00046 // Forward declaration. 00047 template <typename I, typename S> class sub_image; 00048 00049 00050 namespace internal 00051 { 00052 00054 template <typename I, typename S> 00055 struct data< sub_image<I,S> > 00056 { 00057 data(const I& ima, const S& pset); 00058 00059 I ima_; 00060 S domain_; 00061 }; 00062 00063 } // end of namespace mln::internal 00064 00065 00066 00067 namespace trait 00068 { 00069 00070 template <typename I, typename S> 00071 struct image_< sub_image<I,S> > : default_image_morpher< I, 00072 mln_value(I), 00073 sub_image<I,S> > 00074 { 00075 // private: 00076 // typedef mln_trait_image_data(I) I_data_; 00077 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_; 00078 // public: 00079 00080 typedef trait::image::category::domain_morpher category; 00081 00082 typedef trait::image::ext_domain::none ext_domain; // No extension of domain. 00083 typedef trait::image::ext_value::irrelevant ext_value; 00084 typedef trait::image::ext_io::irrelevant ext_io; 00085 00086 typedef trait::image::vw_io::none vw_io; 00087 typedef trait::image::vw_set::none vw_set; 00088 typedef trait::image::value_alignment::not_aligned value_alignment; 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 class sub_image : public internal::image_domain_morpher< I, 00103 S, 00104 sub_image<I,S> > 00105 { 00106 public: 00108 typedef sub_image< tag::image_<I>, tag::domain_<S> > skeleton; 00109 00111 sub_image(); 00112 00114 sub_image(const I& ima, const S& pset); 00115 00117 void init_(const I& ima, const S& pset); 00118 00120 const S& domain() const; 00121 00123 operator sub_image<const I, S>() const; 00124 }; 00125 00126 00127 00128 00129 00130 template <typename I, typename S> 00131 sub_image<const I, S> 00132 operator|(const Image<I>& ima, const Site_Set<S>& pset); 00133 00134 00135 template <typename I, typename S> 00136 sub_image<I, S> 00137 operator|(Image<I>& ima, const Site_Set<S>& pset); 00138 00139 00140 00141 template <typename I, typename S, typename J> 00142 void init_(tag::image_t, sub_image<I,S>& target, const J& model); 00143 00144 00145 00146 # ifndef MLN_INCLUDE_ONLY 00147 00148 // init_ 00149 00150 template <typename I, typename S, typename J> 00151 inline 00152 void init_(tag::image_t, sub_image<I,S>& target, const J& model) 00153 { 00154 I ima; 00155 init_(tag::image, ima, model); 00156 S pset; 00157 init_(tag::domain, pset, model); 00158 target.init_(ima, pset); 00159 } 00160 00161 00162 // internal::data< sub_image<I,S> > 00163 00164 namespace internal 00165 { 00166 00167 template <typename I, typename S> 00168 inline 00169 data< sub_image<I,S> >::data(const I& ima, const S& pset) 00170 : ima_(ima), 00171 domain_(pset) 00172 { 00173 } 00174 00175 } // end of namespace mln::internal 00176 00177 00178 // sub_image<I,S> 00179 00180 template <typename I, typename S> 00181 inline 00182 sub_image<I,S>::sub_image() 00183 { 00184 } 00185 00186 template <typename I, typename S> 00187 inline 00188 sub_image<I,S>::sub_image(const I& ima, const S& pset) 00189 { 00190 init_(ima, pset); 00191 } 00192 00193 template <typename I, typename S> 00194 inline 00195 void 00196 sub_image<I,S>::init_(const I& ima, const S& pset) 00197 { 00198 mln_precondition(! this->is_valid()); 00199 this->data_ = new internal::data< sub_image<I,S> >(ima, pset); 00200 } 00201 00202 template <typename I, typename S> 00203 inline 00204 const S& 00205 sub_image<I,S>::domain() const 00206 { 00207 return this->data_->domain_; 00208 } 00209 00210 template <typename I, typename S> 00211 inline 00212 sub_image<I,S>::operator sub_image<const I, S>() const 00213 { 00214 sub_image<const I, S> tmp(this->data_->ima_, 00215 this->data_->domain_); 00216 return tmp; 00217 } 00218 00219 00220 // Operators. 00221 00222 template <typename I, typename S> 00223 inline 00224 sub_image<const I, S> 00225 operator|(const Image<I>& ima, const Site_Set<S>& pset) 00226 { 00227 sub_image<const I, S> tmp(exact(ima), exact(pset)); 00228 return tmp; 00229 } 00230 00231 template <typename I, typename S> 00232 inline 00233 sub_image<I, S> 00234 operator|(Image<I>& ima, const Site_Set<S>& pset) 00235 { 00236 sub_image<I, S> tmp(exact(ima), exact(pset)); 00237 return tmp; 00238 } 00239 00240 # endif // ! MLN_INCLUDE_ONLY 00241 00242 } // end of namespace mln 00243 00244 00245 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_HH