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_SITE_SET_P_VACCESS_HH 00027 # define MLN_CORE_SITE_SET_P_VACCESS_HH 00028 00032 00033 # include <utility> 00034 # include <mln/core/concept/site_set.hh> 00035 # include <mln/core/site_set/p_double.hh> 00036 # include <mln/core/internal/site_set_base.hh> 00037 # include <mln/core/internal/pseudo_site_base.hh> 00038 # include <mln/core/internal/site_set_impl.hh> 00039 # include <mln/value/set.hh> 00040 00041 00042 namespace mln 00043 { 00044 00045 // Forward declaration. 00046 template <typename V, typename S> class p_vaccess; 00047 00048 00049 00050 namespace trait 00051 { 00052 00053 template <typename V, typename S> 00054 struct site_set_< p_vaccess<V,S> > 00055 { 00056 typedef mln_trait_site_set_nsites(S) nsites; 00057 typedef mln_trait_site_set_bbox(S) bbox; 00058 typedef trait::site_set::contents::growing contents; 00059 typedef trait::site_set::arity::multiple arity; 00060 }; 00061 00062 } // end of namespace trait 00063 00064 00065 00069 template <typename V, typename S> 00070 class p_vaccess : public internal::site_set_base_< mln_site(S), 00071 p_vaccess<V,S> >, 00072 public internal::site_set_impl< S > 00073 { 00074 typedef p_vaccess<V,S> self_; 00075 public: 00076 00078 typedef V value; 00079 00081 typedef mln::value::set<V> vset; 00082 typedef vset t_eligible_values_set; // FIXME: Required by value set iterators... 00083 00085 typedef S pset; 00086 00088 typedef p_double_psite<self_, S> psite; 00089 00091 typedef p_double_piter<self_, mln_fwd_viter(vset), mln_fwd_piter(S)> fwd_piter; 00092 00094 typedef p_double_piter<self_, mln_bkd_viter(vset), mln_bkd_piter(S)> bkd_piter; 00095 00097 typedef fwd_piter piter; 00098 00099 00101 p_vaccess(); 00102 p_vaccess(const V& vset); 00103 00104 00106 bool has(const psite& p) const; 00107 00110 bool has(const V& v, const mln_psite(S)& p) const; 00111 00113 bool is_valid() const; 00114 00115 00117 typedef mln_element(S) element; 00118 00120 typedef std::pair<V, element> i_element; 00121 00123 void insert(const i_element& v_e); 00124 00126 void insert(const V& v, const element& e); 00127 00128 00129 // Clear this set. 00130 void clear(); 00131 00132 00134 const mln::value::set<V>& values() const; 00135 00137 const S& operator()(const V& v) const; 00138 00139 00141 std::size_t memory_size() const; 00142 00143 // Required by p_double-related classes. 00144 const mln::value::set<V>& set_1_() const; 00145 const S& set_2_(const V& v) const; 00146 00147 protected: 00148 00149 mln::value::set<V> vs_; 00150 std::vector<S> ps_; 00151 }; 00152 00153 00154 00155 00156 # ifndef MLN_INCLUDE_ONLY 00157 00158 00159 // p_vaccess<V,S> 00160 00161 template <typename V, typename S> 00162 inline 00163 p_vaccess<V,S>::p_vaccess() 00164 : vs_(), 00165 ps_(vs_.nvalues()) 00166 { 00167 } 00168 00169 template <typename V, typename S> 00170 inline 00171 p_vaccess<V,S>::p_vaccess(const V& vset) 00172 : vs_(vset), 00173 ps_(vs_.nvalues()) 00174 { 00175 } 00176 00177 template <typename V, typename S> 00178 inline 00179 bool 00180 p_vaccess<V,S>::has(const psite&) const 00181 { 00182 // FIXME 00183 return true; 00184 } 00185 00186 template <typename V, typename S> 00187 inline 00188 bool 00189 p_vaccess<V,S>::has(const V& v, const mln_psite(S)& p) const 00190 { 00191 return ps_[vs_.index_of(v)].has(p); 00192 } 00193 00194 template <typename V, typename S> 00195 inline 00196 bool 00197 p_vaccess<V,S>::is_valid() const 00198 { 00199 // FIXME 00200 return true; 00201 } 00202 00203 template <typename V, typename S> 00204 inline 00205 void 00206 p_vaccess<V,S>::insert(const V& v, const element& e) 00207 { 00208 ps_[vs_.index_of(v)].insert(e); 00209 this->update_nsites_(e); 00210 this->update_bbox_(e); 00211 } 00212 00213 template <typename V, typename S> 00214 inline 00215 void 00216 p_vaccess<V,S>::insert(const i_element& v_e) 00217 { 00218 insert(v_e.first, v_e.second); 00219 } 00220 00221 template <typename V, typename S> 00222 inline 00223 void 00224 p_vaccess<V,S>::clear() 00225 { 00226 const unsigned n = ps_.size(); 00227 for (unsigned i = 0; i < n; ++i) 00228 ps_[i].clear(); 00229 } 00230 00231 template <typename V, typename S> 00232 inline 00233 const S& 00234 p_vaccess<V,S>::operator()(const V& v) const 00235 { 00236 return ps_[vs_.index_of(v)]; 00237 } 00238 00239 template <typename V, typename S> 00240 inline 00241 std::size_t 00242 p_vaccess<V,S>::memory_size() const 00243 { 00244 std::size_t mem = 0; 00245 const unsigned n = ps_.size(); 00246 for (unsigned i = 0; i < n; ++i) 00247 mem += ps_[i].memory_size(); 00248 return sizeof(*this) + mem; 00249 } 00250 00251 template <typename V, typename S> 00252 inline 00253 const mln::value::set<V>& 00254 p_vaccess<V,S>::values() const 00255 { 00256 return vs_; 00257 } 00258 00259 template <typename V, typename S> 00260 inline 00261 const mln::value::set<V>& 00262 p_vaccess<V,S>::set_1_() const 00263 { 00264 return vs_; 00265 } 00266 00267 template <typename V, typename S> 00268 inline 00269 const S& 00270 p_vaccess<V,S>::set_2_(const V& v) const 00271 { 00272 return ps_[vs_.index_of(v)]; 00273 } 00274 00275 # endif // ! MLN_INCLUDE_ONLY 00276 00277 } // end of namespace mln 00278 00279 00280 #endif // ! MLN_CORE_SITE_SET_P_VACCESS_HH