00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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 }
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
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 }
00260
00261
00262 #endif // ! MLN_CORE_SITE_SET_P_SET_OF_HH