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