Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_MUTABLE_ARRAY_OF_HH 00027 # define MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH 00028 00041 # include <mln/core/site_set/p_double.hh> 00042 # include <mln/core/internal/site_set_base.hh> 00043 # include <mln/util/array.hh> 00044 00045 00046 00047 namespace mln 00048 { 00049 00050 // Forward declaration. 00051 template <typename S> class p_mutable_array_of; 00052 00053 00054 namespace trait 00055 { 00056 00057 template <typename S> 00058 struct site_set_< p_mutable_array_of<S> > 00059 { 00060 typedef trait::site_set::nsites::unknown nsites; 00061 typedef trait::site_set::bbox::unknown bbox; 00062 typedef trait::site_set::contents::growing contents; 00063 typedef trait::site_set::arity::multiple arity; 00064 }; 00065 00066 } // end of namespace trait 00067 00068 00069 00075 template <typename S> 00076 class p_mutable_array_of : public internal::site_set_base_< mln_site(S), 00077 p_mutable_array_of<S> >, 00078 private mlc_is_a(S, Site_Set)::check_t 00079 { 00080 typedef p_mutable_array_of<S> self_; 00081 typedef util::array<S> array_; 00082 public: 00083 00085 typedef S element; 00086 00087 00089 typedef p_double_psite<self_, element> psite; 00090 00092 typedef p_double_piter<self_, 00093 mln_fwd_eiter(array_), 00094 mln_fwd_piter(S)> fwd_piter; 00095 00097 typedef p_double_piter<self_, 00098 mln_bkd_eiter(array_), 00099 mln_bkd_piter(S)> bkd_piter; 00100 00102 typedef fwd_piter piter; 00103 00104 00106 p_mutable_array_of(); 00107 00108 00110 void reserve(unsigned n); 00111 00112 00114 bool has(const psite& p) const; 00115 00117 bool is_valid() const; 00118 00119 00121 typedef S i_element; 00122 00125 void insert(const S& s); 00126 00127 00129 const S& operator[](unsigned i) const; 00130 00132 S& operator[](unsigned i); 00133 00135 unsigned nelements() const; 00136 00137 00139 void clear(); 00140 00142 bool is_empty_() const; // Override the default impl since we have not .nsites(). 00143 00144 00146 std::size_t memory_size() const; 00147 00149 const util::array<S>& array_hook_() const; 00150 00151 00152 // Required by p_double-related classes. 00153 const util::array<S>& set_1_() const; 00154 template <typename I> 00155 const S& set_2_(const I& it) const; 00156 00157 protected: 00158 00160 util::array<S> arr_; 00161 }; 00162 00163 00164 00165 template <typename S> 00166 std::ostream& operator<<(std::ostream& ostr, const p_mutable_array_of<S>& r); 00167 00168 00169 00170 00171 # ifndef MLN_INCLUDE_ONLY 00172 00173 template <typename S> 00174 inline 00175 p_mutable_array_of<S>::p_mutable_array_of() 00176 { 00177 } 00178 00179 template <typename S> 00180 inline 00181 void 00182 p_mutable_array_of<S>::reserve(unsigned n) 00183 { 00184 arr_.reserve(n); 00185 } 00186 00187 template <typename S> 00188 inline 00189 bool 00190 p_mutable_array_of<S>::has(const psite& p) const 00191 { 00192 return p.index() < arr_.nelements() && arr_[p.index()].has(p.p()); 00193 } 00194 00195 template <typename S> 00196 inline 00197 bool 00198 p_mutable_array_of<S>::is_valid() const 00199 { 00200 return true; 00201 } 00202 00203 template <typename S> 00204 inline 00205 void 00206 p_mutable_array_of<S>::insert(const S& s) 00207 { 00208 mln_precondition(s.is_valid()); 00209 arr_.append(s); 00210 } 00211 00212 template <typename S> 00213 inline 00214 const S& 00215 p_mutable_array_of<S>::operator[](unsigned i) const 00216 { 00217 mln_precondition(i < arr_.nelements()); 00218 return arr_[i]; 00219 } 00220 00221 template <typename S> 00222 inline 00223 S& 00224 p_mutable_array_of<S>::operator[](unsigned i) 00225 { 00226 mln_precondition(i < arr_.nelements()); 00227 return arr_[i]; 00228 } 00229 00230 template <typename S> 00231 inline 00232 unsigned 00233 p_mutable_array_of<S>::nelements() const 00234 { 00235 return arr_.nelements(); 00236 } 00237 00238 template <typename S> 00239 inline 00240 void 00241 p_mutable_array_of<S>::clear() 00242 { 00243 arr_.clear(); 00244 mln_postcondition(this->is_empty()); 00245 } 00246 00247 template <typename S> 00248 inline 00249 bool 00250 p_mutable_array_of<S>::is_empty_() const 00251 { 00252 return arr_.is_empty(); 00253 } 00254 00255 template <typename S> 00256 inline 00257 std::size_t 00258 p_mutable_array_of<S>::memory_size() const 00259 { 00260 return arr_.memory_size(); 00261 } 00262 00263 template <typename S> 00264 inline 00265 const util::array<S>& 00266 p_mutable_array_of<S>::array_hook_() const 00267 { 00268 return arr_; 00269 } 00270 00271 template <typename S> 00272 inline 00273 const util::array<S>& 00274 p_mutable_array_of<S>::set_1_() const 00275 { 00276 return arr_; 00277 } 00278 00279 template <typename S> 00280 template <typename I> 00281 inline 00282 const S& 00283 p_mutable_array_of<S>::set_2_(const I& it) const 00284 { 00285 return it.element(); 00286 } 00287 00288 00289 template <typename S> 00290 std::ostream& operator<<(std::ostream& ostr, const p_mutable_array_of<S>& a) 00291 { 00292 return ostr << a.array_hook_(); 00293 } 00294 00295 # endif // ! MLN_INCLUDE_ONLY 00296 00297 } // end of namespace mln 00298 00299 00300 #endif // ! MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH