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_COMPLEX_PSITE_HH
00027 # define MLN_CORE_SITE_SET_COMPLEX_PSITE_HH
00028 
00032 
00033 # include <mln/core/internal/pseudo_site_base.hh>
00034 
00035 # include <mln/topo/complex.hh>
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 namespace mln
00050 {
00051   
00052   template <unsigned D, typename G> class p_complex;
00053 
00054 
00059   template <unsigned D, typename G>
00060   class complex_psite
00061     : public internal::pseudo_site_base_< const mln_site(G)&, complex_psite<D, G> >
00062   {
00063   public:
00064     
00065     
00066     typedef p_complex<D, G> target;
00067 
00068     typedef p_complex<D, G> target_t; 
00069 
00070     
00073     complex_psite();
00075     complex_psite(const p_complex<D, G>& pc,
00076                   const topo::face<D>& face);
00077     complex_psite(const p_complex<D, G>& pc, unsigned n, unsigned face_id);
00079 
00083     bool is_valid() const;
00085     void invalidate();
00087 
00093     const target& site_set() const;
00094 
00096     const target* target_() const;
00098     void change_target(const target& new_target);
00100 
00104     const mln_site(G)& subj_();
00106 
00110     const topo::face<D>& face() const;
00111 
00113     unsigned n() const;
00115     unsigned face_id() const;
00117 
00118   private:
00122     void update_();
00123     
00124     mln_site(G) p_;
00126 
00127     
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139   private:
00143     const target* pc_;
00145     topo::face<D> face_;
00147   };
00148 
00149 
00152   
00153 
00154 
00159   
00160 
00161   template <unsigned D, typename G>
00162   bool
00163   operator==(const complex_psite<D, G>& lhs,
00164              const complex_psite<D, G>& rhs);
00165 
00170   
00171 
00172   template <unsigned D, typename G>
00173   bool
00174   operator!=(const complex_psite<D, G>& lhs,
00175              const complex_psite<D, G>& rhs);
00176 
00183   
00184 
00185   template <unsigned D, typename G>
00186   bool
00187   operator< (const complex_psite<D, G>& lhs,
00188              const complex_psite<D, G>& rhs);
00190 
00191 
00192   template <unsigned D, typename G>
00193   inline
00194   std::ostream&
00195   operator<<(std::ostream& ostr, const complex_psite<D, G>& p);
00196 
00197 
00198 
00199 # ifndef MLN_INCLUDE_ONLY
00200 
00201   template <unsigned D, typename G>
00202   inline
00203   complex_psite<D, G>::complex_psite()
00204     : pc_(0)
00205   {
00206     invalidate();
00207   }
00208 
00209   template <unsigned D, typename G>
00210   inline
00211   complex_psite<D, G>::complex_psite(const p_complex<D, G>& pc,
00212                                      const topo::face<D>& face)
00213     : pc_(&pc),
00214       face_(face)
00215   {
00216     
00217     
00218 #if 0
00219     mln_precondition(pc.cplx() == face.cplx());
00220 #endif
00221     if (is_valid())
00222       update_();
00223   }
00224 
00225   template <unsigned D, typename G>
00226   inline
00227   complex_psite<D, G>::complex_psite(const p_complex<D, G>& pc,
00228                                      unsigned n, unsigned face_id)
00229     : pc_(&pc),
00230       face_(pc.cplx(), n, face_id)  
00231   {
00232     if (is_valid())
00233       update_();
00234   }
00235 
00236   template <unsigned D, typename G>
00237   inline
00238   bool
00239   complex_psite<D, G>::is_valid() const
00240   {
00241     
00242 #if 0
00243     mln_invariant(!pc_ || pc_.cplx() == face_.cplx());
00244 #endif
00245     return face_.is_valid();
00246   }
00247 
00248   template <unsigned D, typename G>
00249   inline
00250   void
00251   complex_psite<D, G>::invalidate()
00252   {
00253     return face_.invalidate();
00254   }
00255 
00256   template <unsigned D, typename G>
00257   inline
00258   const p_complex<D, G>&
00259   complex_psite<D, G>::site_set() const
00260   {
00261     mln_precondition(target_());
00262     return *target_();
00263   }
00264 
00265   template <unsigned D, typename G>
00266   inline
00267   const p_complex<D, G>*
00268   complex_psite<D, G>::target_() const
00269   {
00270     
00271 #if 0
00272     mln_invariant(!pc_ || pc_.cplx() == face_.cplx());
00273 #endif
00274     return pc_;
00275   }
00276 
00277   template <unsigned D, typename G>
00278   inline
00279   void
00280   complex_psite<D, G>::change_target(const target& new_target)
00281   {
00282     
00283     pc_ = &new_target;
00284     face_.set_cplx(new_target.cplx());
00285     invalidate();
00286   }
00287 
00288   
00289   
00290   template <unsigned D, typename G>
00291   inline
00292   const mln_site(G)&
00293   complex_psite<D, G>::subj_()
00294   {
00295     return p_;
00296   }
00297 
00298   template <unsigned D, typename G>
00299   inline
00300   const topo::face<D>&
00301   complex_psite<D, G>::face() const
00302   {
00303     return face_;
00304   }
00305 
00306   template <unsigned D, typename G>
00307   inline
00308   unsigned
00309   complex_psite<D, G>::n() const
00310   {
00311     return face_.n();
00312   }
00313 
00314   template <unsigned D, typename G>
00315   inline
00316   unsigned
00317   complex_psite<D, G>::face_id() const
00318   {
00319     return face_.face_id();
00320   }
00321 
00322   template <unsigned D, typename G>
00323   inline
00324   void
00325   complex_psite<D, G>::update_()
00326   {
00327     mln_precondition(is_valid());
00328     
00329 #if 0
00330     mln_invariant(!pc_ || pc_.cplx() == face_.cplx());
00331 #endif
00332     
00333     
00334     p_ = site_set().geom()(face_);
00335   }
00336 
00337 
00338   
00339 
00340 
00341 
00342   template <unsigned D, typename G>
00343   bool
00344   operator==(const complex_psite<D, G>& lhs,
00345              const complex_psite<D, G>& rhs)
00346   {
00347     mln_precondition(&lhs.site_set() == &rhs.site_set());
00348     return lhs.face() == rhs.face();
00349   }
00350 
00351   template <unsigned D, typename G>
00352   bool
00353   operator!=(const complex_psite<D, G>& lhs,
00354              const complex_psite<D, G>& rhs)
00355   {
00356     mln_precondition(&lhs.site_set() == &rhs.site_set());
00357     return lhs.face() != rhs.face();
00358   }
00359 
00360   template <unsigned D, typename G>
00361   bool
00362   operator< (const complex_psite<D, G>& lhs,
00363              const complex_psite<D, G>& rhs)
00364   {
00365     mln_precondition(&lhs.site_set() == &rhs.site_set());
00366     return lhs.face() < rhs.face();
00367   }
00368 
00369 
00370   
00371 
00372 
00373 
00374   template <unsigned D, typename G>
00375   inline
00376   std::ostream&
00377   operator<<(std::ostream& ostr, const complex_psite<D, G>& p)
00378   {
00379     return ostr << p.face();
00380   }
00381 
00382 # endif // ! MLN_INCLUDE_ONLY
00383 
00384 } 
00385 
00386 #endif // ! MLN_CORE_SITE_SET_COMPLEX_PSITE_HH