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
00027 #ifndef MLN_CORE_FACES_PSITE_HH
00028 # define MLN_CORE_FACES_PSITE_HH
00029
00033
00034 # include <cstdlib>
00035
00036 # include <mln/core/internal/pseudo_site_base.hh>
00037
00038 # include <mln/topo/complex.hh>
00039
00040
00041
00042
00043
00044
00045 namespace mln
00046 {
00047
00048 template <unsigned N, unsigned D, typename P> struct p_faces;
00049
00050
00056 template <unsigned N, unsigned D, typename P>
00057 class faces_psite
00058 : public internal::pseudo_site_base_< const P&,
00059 faces_psite<N, D, P> >
00060 {
00061 public:
00062
00063
00064 typedef p_faces<N, D, P> target;
00065
00068 faces_psite();
00070 faces_psite(const p_faces<N, D, P>& pf, const topo::n_face<N, D>& face);
00071 faces_psite(const p_faces<N, D, P>& pf, unsigned face_id);
00073
00077 bool is_valid() const;
00079 void invalidate();
00081
00087 const target& site_set() const;
00088
00090 const target* target_() const;
00092 void change_target(const target& new_target);
00094
00098 const P& subj_();
00100
00104 topo::n_face<N, D> face() const;
00105
00107 unsigned n() const;
00109 unsigned face_id() const;
00111
00112 private:
00116 void update_();
00117
00118 P p_;
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 private:
00136 const target* pf_;
00138 topo::n_face<N, D> face_;
00140 };
00141
00142
00145
00146
00147
00152 template <unsigned N, unsigned D, typename P>
00153 bool
00154 operator==(const faces_psite<N, D, P>& lhs,
00155 const faces_psite<N, D, P>& rhs);
00156
00157
00162 template <unsigned N, unsigned D, typename P>
00163 bool
00164 operator!=(const faces_psite<N, D, P>& lhs,
00165 const faces_psite<N, D, P>& rhs);
00166
00173 template <unsigned N, unsigned D, typename P>
00174 bool
00175 operator< (const faces_psite<N, D, P>& lhs,
00176 const faces_psite<N, D, P>& rhs);
00178
00179
00180 template <unsigned N, unsigned D, typename P>
00181 inline
00182 std::ostream&
00183 operator<<(std::ostream& ostr, const faces_psite<N, D, P>& p);
00184
00185
00186
00187 # ifndef MLN_INCLUDE_ONLY
00188
00189 template <unsigned N, unsigned D, typename P>
00190 inline
00191 faces_psite<N, D, P>::faces_psite()
00192 : pf_(0)
00193 {
00194
00195 metal::bool_< N <= D >::check();
00196
00197 invalidate();
00198 }
00199
00200 template <unsigned N, unsigned D, typename P>
00201 inline
00202 faces_psite<N, D, P>::faces_psite(const p_faces<N, D, P>& pf,
00203 const topo::n_face<N, D>& face)
00204 : pf_(&pf),
00205 face_(face)
00206 {
00207
00208 metal::bool_< N <= D >::check();
00209
00210
00211
00212 update_();
00213 }
00214
00215 template <unsigned N, unsigned D, typename P>
00216 inline
00217 faces_psite<N, D, P>::faces_psite(const p_faces<N, D, P>& pf,
00218 unsigned face_id)
00219 : pf_(&pf),
00220 face_(pf.cplx(), face_id)
00221 {
00222
00223 metal::bool_< N <= D >::check();
00224
00225 update_();
00226 }
00227
00228 template <unsigned N, unsigned D, typename P>
00229 inline
00230 bool
00231 faces_psite<N, D, P>::is_valid() const
00232 {
00233
00234 return face_.is_valid();
00235 }
00236
00237 template <unsigned N, unsigned D, typename P>
00238 inline
00239 void
00240 faces_psite<N, D, P>::invalidate()
00241 {
00242 return face_.invalidate();
00243 }
00244
00245 template <unsigned N, unsigned D, typename P>
00246 inline
00247 const p_faces<N, D, P>&
00248 faces_psite<N, D, P>::site_set() const
00249 {
00250 mln_precondition(target_());
00251 return *target_();
00252 }
00253
00254 template <unsigned N, unsigned D, typename P>
00255 inline
00256 const p_faces<N, D, P>*
00257 faces_psite<N, D, P>::target_() const
00258 {
00259
00260 return pf_;
00261 }
00262
00263 template <unsigned N, unsigned D, typename P>
00264 inline
00265 void
00266 faces_psite<N, D, P>::change_target(const target& new_target)
00267 {
00268
00269 pf_ = &new_target;
00270 face_.set_cplx(new_target.cplx());
00271 invalidate();
00272 }
00273
00274
00275
00276 template <unsigned N, unsigned D, typename P>
00277 inline
00278 const P&
00279 faces_psite<N, D, P>::subj_()
00280 {
00281
00282
00283 abort();
00284 return p_;
00285 }
00286
00287 template <unsigned N, unsigned D, typename P>
00288 inline
00289 topo::n_face<N, D>
00290 faces_psite<N, D, P>::face() const
00291 {
00292 return face_;
00293 }
00294
00295 template <unsigned N, unsigned D, typename P>
00296 inline
00297 unsigned
00298 faces_psite<N, D, P>::n() const
00299 {
00300 return face_.n();
00301 }
00302
00303 template <unsigned N, unsigned D, typename P>
00304 inline
00305 unsigned
00306 faces_psite<N, D, P>::face_id() const
00307 {
00308 return face_.face_id();
00309 }
00310
00311 template <unsigned N, unsigned D, typename P>
00312 inline
00313 void
00314 faces_psite<N, D, P>::update_()
00315 {
00316 mln_precondition(is_valid());
00317
00318
00319 }
00320
00321
00322
00323
00324
00325
00326 template <unsigned N, unsigned D, typename P>
00327 bool
00328 operator==(const faces_psite<N, D, P>& lhs,
00329 const faces_psite<N, D, P>& rhs)
00330 {
00331 mln_precondition(&lhs.site_set() == &rhs.site_set());
00332 return lhs.face() == rhs.face();
00333 }
00334
00335 template <unsigned N, unsigned D, typename P>
00336 bool
00337 operator!=(const faces_psite<N, D, P>& lhs,
00338 const faces_psite<N, D, P>& rhs)
00339 {
00340 mln_precondition(&lhs.site_set() == &rhs.site_set());
00341 return lhs.face() != rhs.face();
00342 }
00343
00344 template <unsigned N, unsigned D, typename P>
00345 bool
00346 operator< (const faces_psite<N, D, P>& lhs,
00347 const faces_psite<N, D, P>& rhs)
00348 {
00349 mln_precondition(&lhs.site_set() == &rhs.site_set());
00350 return lhs.face() < rhs.face();
00351 }
00352
00353
00354
00355
00356
00357
00358 template <unsigned N, unsigned D, typename P>
00359 inline
00360 std::ostream&
00361 operator<<(std::ostream& ostr, const faces_psite<N, D, P>& p)
00362 {
00363 return ostr << "(dim = " << p.n() << ", id = " << p.face_id() << ')';
00364 }
00365
00366 # endif // ! MLN_INCLUDE_ONLY
00367
00368 }
00369
00370 #endif // ! MLN_CORE_FACES_PSITE_HH