Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 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_CONCEPT_IMAGE_HH 00028 # define MLN_CORE_CONCEPT_IMAGE_HH 00029 00033 00034 # include <mln/core/concept/site_set.hh> 00035 # include <mln/core/concept/mesh.hh> 00036 00037 # include <mln/core/trait/all.hh> // FIXME: Move out of core! 00038 # include <mln/core/macros.hh> 00039 # include <mln/core/site_set/box.hh> 00040 00041 # include <mln/trait/concrete.hh> // FIXME: Should be in all.hh! 00042 # include <mln/trait/images.hh> 00043 00044 # include <mln/metal/abort.hh> 00045 # include <mln/metal/is_a.hh> 00046 # include <mln/metal/equal.hh> 00047 00048 # include <mln/tag/init.hh> 00049 00050 00051 namespace mln 00052 { 00053 00054 00055 // Forward declarations. 00056 template <typename E> struct Image; 00057 template <typename E> struct Literal; 00058 00059 00060 // Image category flag type. 00061 template <> 00062 struct Image<void> 00063 { 00064 typedef Object<void> super; 00065 }; 00066 00067 00072 template <typename E> 00073 struct Image : public Object<E> 00074 { 00075 typedef Image<void> category; 00076 00077 template <typename J> 00078 Image<E>& operator=(const J& rhs); 00079 00080 /* 00081 // provided by internal::image_base: 00082 00083 typedef domain_t; 00084 typedef site; 00085 typedef psite; 00086 00087 typedef piter; 00088 typedef fwd_piter; 00089 typedef bkd_piter; 00090 00091 bool has(const psite& p) const; 00092 unsigned nsites() const; // If relevant. 00093 00094 bool is_valid() const; 00095 00096 typedef t_eligible_values_set; 00097 const t_eligible_values_set& values_eligible() const; 00098 00099 typedef t_values_space; 00100 const t_values_space& values_space() const; 00101 00102 typedef value; 00103 00104 // to be provided in concrete image classes: 00105 00106 typedef vset; 00107 const vset& values() const; 00108 00109 typedef rvalue; 00110 typedef lvalue; 00111 rvalue operator()(const psite& p) const; 00112 lvalue operator()(const psite& p); 00113 00114 const domain_t& domain() const; 00115 00116 typedef skeleton; 00117 */ 00118 00119 protected: 00120 Image(); 00121 }; 00122 00123 00124 namespace convert 00125 { 00126 00127 namespace over_load 00128 { 00129 00130 template <typename V, unsigned S, typename I> 00131 void 00132 from_to_(const V (&values)[S], Image<I>& to); 00133 00134 } // end of namespace mln::convert::over_load 00135 00136 } // end of namespace mln::convert 00137 00138 00139 00140 # ifndef MLN_INCLUDE_ONLY 00141 00142 00143 namespace internal 00144 { 00145 00146 template <typename values_browsing_trait, typename E> 00147 struct image_values_interface_check 00148 { 00149 static void run() { /* No Requirement */} 00150 }; 00151 00152 template <typename E> 00153 struct image_values_interface_check< 00154 mln::trait::image::value_browsing::value_wise, 00155 E> 00156 { 00157 static void run() 00158 { 00159 } 00160 }; 00161 00162 00163 // check_init 00164 00165 template < typename E, 00166 typename A > 00167 int check_init(void (E::*)(A)) 00168 { 00169 return 0; 00170 } 00171 00172 template < typename E, 00173 typename A1, typename A2 > 00174 int check_init(void (E::*)(A1, A2)) 00175 { 00176 return 0; 00177 } 00178 00179 template < typename E, 00180 typename A1, typename A2, typename A3 > 00181 int check_init(void (E::*)(A1, A2, A3)) 00182 { 00183 return 0; 00184 } 00185 00186 } // end of namespace mln::internal 00187 00188 00189 template <typename E> 00190 template <typename J> 00191 inline 00192 Image<E>& 00193 Image<E>::operator=(const J&) 00194 { 00199 mlc_abort(E)::check(); 00200 return *this; 00201 } 00202 00203 00204 template <typename E> 00205 inline 00206 Image<E>::Image() 00207 { 00208 // provided by internal::image_base: 00209 00210 typedef mln_domain(E) domain_t; 00211 typedef mln_site(E) site; 00212 typedef mln_psite(E) psite; 00213 00214 typedef mln_piter(E) piter; 00215 typedef mln_fwd_piter(E) fwd_piter; 00216 typedef mln_bkd_piter(E) bkd_piter; 00217 00218 bool (E::*m1)(const psite& p) const = & E::has; 00219 m1 = 0; 00220 00221 // Only some image types feature the 'nsites' method. 00222 // unsigned (E::*m2)() const = & E::nsites; 00223 // m2 = 0; 00224 00225 bool (E::*m3)() const = & E::is_valid; 00226 m3 = 0; 00227 00228 typedef typename E::t_eligible_values_set t_eligible_values_set; 00229 00230 const t_eligible_values_set& (E::*m4)() const = & E::values_eligible; 00231 m4 = 0; 00232 00233 typedef typename E::t_values_space t_values_space; 00234 00235 const t_values_space& (E::*m5)() const = & E::values_space; 00236 m5 = 0; 00237 00238 // to be provided in concrete image classes: 00239 00240 typedef mln_value(E) value; 00241 typedef mln_rvalue(E) rvalue; 00242 typedef mln_lvalue(E) lvalue; 00243 00244 mlc_is_not_a(value, Literal)::check(); 00245 00246 // FIXME Doc 00247 //typedef mln_vset(E) vset; 00248 //const vset& (E::*m5)() const = & E::values; 00249 //m5 = 0; 00250 00251 rvalue (E::*m6)(const psite& p) const = & E::operator(); 00252 m6 = 0; 00253 lvalue (E::*m7)(const psite& p) = & E::operator(); 00254 m7 = 0; 00255 00256 const domain_t& (E::*m8)() const = & E::domain; 00257 m8 = 0; 00258 00259 typedef typename E::skeleton skeleton; 00260 00261 // Check E::init_ presence. Since its signature varies from an 00262 // image type to another, that is the only thing we can ensure. 00263 internal::check_init(& E::init_); 00264 00266 internal::image_values_interface_check<mln_trait_image_value_browsing(E), 00267 E>::run(); 00268 } 00269 00270 00271 namespace convert 00272 { 00273 00274 namespace over_load 00275 { 00276 00277 template <typename V, unsigned S, typename I> 00278 void 00279 from_to_(const V (&values)[S], Image<I>& to_) 00280 { 00281 mlc_bool(S != 0)::check(); 00282 mlc_converts_to(V, mln_value(I))::check(); 00283 typedef mln_site(I) P; 00284 enum { d = P::dim, 00285 s = mlc_root(d, S)::value }; 00286 metal::bool_<(mlc_pow_int(s, d) == S)>::check(); 00287 00288 I& to = exact(to_); 00289 mln_precondition(! to.is_valid()); 00290 00291 box<P> b(all_to(0), all_to(s - 1)); 00292 to.init_(b); 00293 mln_fwd_piter(box<P>) p(b); 00294 unsigned i = 0; 00295 for_all(p) 00296 to(p) = values[i++]; 00297 } 00298 00299 } // end of namespace mln::convert::over_load 00300 00301 } // end of namespace mln::convert 00302 00303 # endif // ! MLN_INCLUDE_ONLY 00304 00305 } // end of namespace mln 00306 00307 00308 # include <mln/core/routine/initialize.hh> 00309 00310 00311 #endif // ! MLN_CORE_CONCEPT_IMAGE_HH