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_INTERNAL_IMAGE_BASE_HH 00028 # define MLN_CORE_INTERNAL_IMAGE_BASE_HH 00029 00035 00036 # include <mln/core/concept/image.hh> 00037 # include <mln/core/grids.hh> 00038 # include <mln/core/trait/qlf_value.hh> 00039 # include <mln/core/internal/check/image_all.hh> 00040 # include <mln/core/internal/data.hh> 00041 # include <mln/core/internal/morpher_lvalue.hh> 00042 # include <mln/util/tracked_ptr.hh> 00043 # include <mln/value/set.hh> 00044 # include <mln/value/super_value.hh> 00045 00046 // image_base 00047 // ^ 00048 // | 00049 // --------------------------- 00050 // | | 00051 // image_primary image_morpher 00052 // ^ ^ 00053 // | | 00054 // | ----------------------------------------- 00055 // | | | | 00056 // pw_image_base image_domain_morpher image_value_morpher image_identity 00057 00058 00059 namespace mln 00060 { 00061 00062 namespace internal 00063 { 00064 00065 00066 template <typename E> 00067 struct image_checked_ 00068 : 00069 public check::image_all_<E>, 00070 public Image<E> 00071 { 00072 }; 00073 00074 00075 00080 // 00081 template <typename T, typename S, typename E> 00082 struct image_base 00083 : 00084 public image_checked_<E> 00085 00086 { 00088 typedef T value; 00089 00091 typedef mln::value::set<T> t_eligible_values_set; 00092 00093 // Return the set of the image eligigle values 00094 const t_eligible_values_set& values_eligible() const; 00095 00097 typedef mln::value::set< 00098 typename mln::value::super_value<T>::ret > t_values_space; 00099 00101 const t_values_space& values_space() const; 00102 00103 00105 typedef S domain_t; 00106 00108 typedef mln_psite(S) psite; 00109 00111 typedef mln_site(S) site; 00112 00113 00115 typedef mln_fwd_piter(S) fwd_piter; 00116 00118 typedef mln_bkd_piter(S) bkd_piter; 00119 00120 00123 typedef fwd_piter piter; 00124 00125 00126 00128 bool has(const psite& p) const; 00129 00131 std::size_t nsites() const; 00132 00134 bool is_valid() const; 00135 00136 // FIXME: Add void init_data(..); 00137 00138 00140 image_base& operator=(const image_base& rhs); 00141 00143 image_base(const image_base& rhs); 00144 00148 const void* id_() const; 00149 00150 00152 void destroy(); 00153 00155 const util::tracked_ptr< internal::data<E> >& hook_data_() const; 00156 00157 protected: 00158 00160 image_base(); 00161 00162 // Internal data, sharable by several images. 00163 util::tracked_ptr< internal::data<E> > data_; 00164 }; 00165 00166 00167 00168 # ifndef MLN_INCLUDE_ONLY 00169 00170 template <typename T, typename S, typename E> 00171 inline 00172 image_base<T, S, E>::image_base() 00173 { 00174 } 00175 00176 template <typename T, typename S, typename E> 00177 inline 00178 image_base<T, S, E>::image_base(const image_base& rhs) 00179 : image_checked_<E>() 00180 { 00181 mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive? 00182 this->data_ = rhs.data_; 00183 } 00184 00185 template <typename T, typename S, typename E> 00186 inline 00187 image_base<T, S, E>& 00188 image_base<T, S, E>::operator=(const image_base<T, S, E>& rhs) 00189 { 00190 mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive? 00191 if (& rhs == this) // || ! exact(rhs).is_valid()) 00192 return *this; 00193 this->data_ = rhs.data_; 00194 return *this; 00195 } 00196 00197 template <typename T, typename S, typename E> 00198 inline 00199 const void* 00200 image_base<T, S, E>::id_() const 00201 { 00202 return data_.ptr_; 00203 } 00204 00205 template <typename T, typename S, typename E> 00206 inline 00207 bool 00208 image_base<T, S, E>::is_valid() const 00209 { 00210 return data_ != 0; 00211 } 00212 00213 template <typename T, typename S, typename E> 00214 inline 00215 bool 00216 image_base<T, S, E>::has(const psite& p) const 00217 { 00218 mln_precondition(exact(this)->is_valid()); 00219 return exact(this)->domain().has(p); 00220 } 00221 00222 template <typename T, typename S, typename E> 00223 inline 00224 std::size_t 00225 image_base<T, S, E>::nsites() const 00226 { 00227 mlc_equal(mln_trait_site_set_nsites(S), 00228 mln::trait::site_set::nsites::known)::check(); 00229 mln_precondition(exact(this)->is_valid()); 00230 return exact(this)->domain().nsites(); 00231 } 00232 00233 template <typename T, typename S, typename E> 00234 inline 00235 const typename image_base<T, S, E>::t_eligible_values_set& 00236 image_base<T, S, E>::values_eligible() const 00237 { 00238 return t_eligible_values_set::the(); 00239 } 00240 00241 template <typename T, typename S, typename E> 00242 inline 00243 const typename image_base<T, S, E>::t_values_space& 00244 image_base<T, S, E>::values_space() const 00245 { 00246 return t_values_space::the(); 00247 } 00248 00249 template <typename T, typename S, typename E> 00250 inline 00251 void 00252 image_base<T, S, E>::destroy() 00253 { 00254 data_.clean_(); 00255 } 00256 00257 template <typename T, typename S, typename E> 00258 inline 00259 const util::tracked_ptr< internal::data<E> >& 00260 image_base<T, S, E>::hook_data_() const 00261 { 00262 return data_; 00263 } 00264 00265 # endif // ! MLN_INCLUDE_ONLY 00266 00267 } // end of namespace mln::internal 00268 00269 } // end of namespace mln 00270 00271 00272 #endif // ! MLN_CORE_INTERNAL_IMAGE_BASE_HH