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_SET_OF_HH 00027 # define MLN_CORE_SITE_SET_P_SET_OF_HH 00028 00036 # include <mln/core/site_set/p_double.hh> 00037 # include <mln/core/internal/site_set_base.hh> 00038 # include <mln/core/internal/site_set_impl.hh> 00039 # include <mln/util/set.hh> 00040 00041 00042 00043 namespace mln 00044 { 00045 00046 // Forward declaration. 00047 template <typename S> class p_set_of; 00048 00049 00050 namespace trait 00051 { 00052 00053 template <typename S> 00054 struct site_set_< p_set_of<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 00070 template <typename S> 00071 class p_set_of : public internal::site_set_base_< mln_site(S), 00072 p_set_of<S> >, 00073 public internal::site_set_impl<S>, 00074 private mlc_is_a(S, Site_Set)::check_t 00075 { 00076 typedef p_set_of<S> self_; 00077 typedef util::set<S> set_; 00078 public: 00079 00081 typedef S element; 00082 00083 00085 typedef p_double_psite<self_, element> psite; 00086 00088 typedef p_double_piter<self_, 00089 mln_fwd_eiter(set_), 00090 mln_fwd_piter(S)> fwd_piter; 00091 00093 typedef p_double_piter<self_, 00094 mln_bkd_eiter(set_), 00095 mln_bkd_piter(S)> bkd_piter; 00096 00098 typedef fwd_piter piter; 00099 00100 00102 p_set_of(); 00103 00104 00106 bool has(const psite& p) const; 00107 00109 bool is_valid() const; 00110 00111 00113 typedef S i_element; 00114 00116 void insert(const S& s); 00117 00118 00120 const S& operator[](unsigned i) const; 00121 00123 unsigned nelements() const; 00124 00125 00127 void clear(); 00128 00129 00131 std::size_t memory_size() const; 00132 00134 const util::set<S>& set_hook_() const; 00135 00136 00137 // Required by p_double-related classes. 00138 const util::set<S>& set_1_() const; 00139 template <typename I> 00140 const S& set_2_(const I& it) const; 00141 00142 protected: 00143 00145 util::set<S> s_; 00146 }; 00147 00148 00149 00150 template <typename S> 00151 std::ostream& operator<<(std::ostream& ostr, const p_set_of<S>& s); 00152 00153 00154 00155 00156 # ifndef MLN_INCLUDE_ONLY 00157 00158 template <typename S> 00159 inline 00160 p_set_of<S>::p_set_of() 00161 { 00162 } 00163 00164 template <typename S> 00165 inline 00166 bool 00167 p_set_of<S>::has(const psite& p) const 00168 { 00169 return p.index() < s_.nelements() && s_[p.index()].has(p.p()); 00170 } 00171 00172 template <typename S> 00173 inline 00174 bool 00175 p_set_of<S>::is_valid() const 00176 { 00177 return true; 00178 } 00179 00180 template <typename S> 00181 inline 00182 void 00183 p_set_of<S>::insert(const S& s) 00184 { 00185 mln_precondition(s.is_valid()); 00186 s_.insert(s); 00187 this->update_nsites_(s); 00188 this->update_bbox_(s); 00189 } 00190 00191 template <typename S> 00192 inline 00193 const S& 00194 p_set_of<S>::operator[](unsigned i) const 00195 { 00196 mln_precondition(i < s_.nelements()); 00197 return s_[i]; 00198 } 00199 00200 template <typename S> 00201 inline 00202 unsigned 00203 p_set_of<S>::nelements() const 00204 { 00205 return s_.nelements(); 00206 } 00207 00208 template <typename S> 00209 inline 00210 void 00211 p_set_of<S>::clear() 00212 { 00213 s_.clear(); 00214 mln_postcondition(this->is_empty()); 00215 } 00216 00217 template <typename S> 00218 inline 00219 std::size_t 00220 p_set_of<S>::memory_size() const 00221 { 00222 return s_.memory_size(); 00223 } 00224 00225 template <typename S> 00226 inline 00227 const util::set<S>& 00228 p_set_of<S>::set_hook_() const 00229 { 00230 return s_; 00231 } 00232 00233 template <typename S> 00234 inline 00235 const util::set<S>& 00236 p_set_of<S>::set_1_() const 00237 { 00238 return s_; 00239 } 00240 00241 template <typename S> 00242 template <typename I> 00243 inline 00244 const S& 00245 p_set_of<S>::set_2_(const I& it) const 00246 { 00247 return it.element(); 00248 } 00249 00250 00251 template <typename S> 00252 std::ostream& operator<<(std::ostream& ostr, const p_set_of<S>& s) 00253 { 00254 return ostr << s.set_hook_(); 00255 } 00256 00257 # endif // ! MLN_INCLUDE_ONLY 00258 00259 } // end of namespace mln 00260 00261 00262 #endif // ! MLN_CORE_SITE_SET_P_SET_OF_HH