dependency.hh

Go to the documentation of this file.
00001 // $Id: dependency.hh 602 2006-05-16 08:47:58Z christi $
00002 #ifndef DUNE_AMG_DEPENDENCY_HH
00003 #define DUNE_AMG_DEPENDENCY_HH
00004 
00005 
00006 #include<bitset>
00007 #include<ostream>
00008 
00009 #include "graph.hh"
00010 #include "properties.hh"
00011 #include <dune/common/propertymap.hh>
00012 
00013 
00014 namespace Dune
00015 {
00016   namespace Amg
00017   {
00035     class EdgeProperties
00036     {
00037       friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
00038     public:
00040       enum{INFLUENCE, DEPEND, SIZE};
00041 
00042     private:
00043       
00044       std::bitset<SIZE> flags_;
00045     public:
00047       EdgeProperties();
00048       
00050       std::bitset<SIZE>::reference operator[](std::size_t v);
00051       
00053       bool operator[](std::size_t v)const;
00054 
00060       bool depends() const;
00061     
00066       void setDepends();
00067 
00071       void resetDepends();
00072 
00077       bool influences() const;
00078      
00082       void setInfluences();
00083 
00087       void resetInfluences();
00088 
00093       bool isOneWay() const;
00094 
00099       bool isTwoWay() const;
00100 
00105       bool isStrong()  const;
00106 
00110       void reset();
00111     
00115       void printFlags() const;
00116     };
00117 
00123     class VertexProperties{
00124       friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
00125     public:
00126       enum{ ISOLATED, VISITED, FRONT, /* EXCLUDED, */ SIZE };
00127     private:
00128       
00130       std::bitset<SIZE> flags_;
00131 
00132     public:
00134       VertexProperties();
00135 
00137       std::bitset<SIZE>::reference operator[](std::size_t v);
00138       
00140       bool operator[](std::size_t v) const;
00141 
00148       void setIsolated();
00149 
00153       bool isolated() const;
00154 
00158       void resetIsolated();
00159 
00163       void setVisited();
00164     
00168       bool visited() const;
00169 
00173       void resetVisited();
00174 
00178       void setFront();
00179 
00183       bool front() const;
00184     
00188       void resetFront();
00189 
00193       void setExcluded();
00194       
00199       bool excluded() const;
00200 
00204       void resetExcluded();
00205 
00209       void reset();
00210       
00211     };
00212 
00213     template<typename G, std::size_t i>
00214     class PropertyGraphVertexPropertyMap
00215       : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
00216                             PropertyGraphVertexPropertyMap<G,i> >
00217     {
00218     public:
00219 
00220       typedef ReadWritePropertyMapTag Category;
00221 
00222       enum{
00224       index = i
00225         };
00226       
00230       typedef G Graph;
00231 
00235       typedef std::bitset<VertexProperties::SIZE> BitSet;
00236 
00240       typedef typename BitSet::reference Reference;
00241 
00245       typedef bool ValueType;
00246       
00250       typedef typename G::VertexDescriptor Vertex;
00251       
00256       PropertyGraphVertexPropertyMap(G& g)
00257         : graph_(&g)
00258       {}
00259 
00263       PropertyGraphVertexPropertyMap()
00264         :graph_(0)
00265       {}
00266       
00267 
00272       Reference operator[](const Vertex& vertex) const
00273       {
00274         return graph_->getVertexProperties(vertex)[index];
00275       }
00276     private:
00277       Graph* graph_;
00278     };
00279     
00280   } // end namespace Amg
00281 
00282   template<typename G, typename EP, typename VM, typename EM>
00283   struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
00284   {
00285     typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
00286   };
00287   
00288   template<typename G, typename EP, typename VM, typename EM>
00289   typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
00290   get(const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
00291   {
00292     return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
00293   }
00294   
00295   namespace Amg
00296   {
00297     inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
00298     {
00299       return os << props.flags_;
00300     }
00301     
00302     EdgeProperties::EdgeProperties()
00303       : flags_(0)
00304     {}
00305 
00306     inline std::bitset<EdgeProperties::SIZE>::reference 
00307     EdgeProperties::operator[](std::size_t v)
00308     {
00309       return flags_[v];
00310     }
00311     
00312     inline bool EdgeProperties::operator[](std::size_t i) const
00313     {
00314       return flags_[i];
00315     }
00316     
00317     inline void EdgeProperties::reset()
00318     {
00319       flags_=0;
00320     }
00321     
00322     inline void EdgeProperties::setInfluences()
00323     {
00324       // Set the INFLUENCE bit
00325       flags_ |= (1<<INFLUENCE);
00326     }
00327 
00328     inline bool EdgeProperties::influences() const
00329     {
00330       // Test the INFLUENCE bit
00331       return flags_.test(INFLUENCE);
00332     }
00333 
00334     inline void EdgeProperties::setDepends()
00335     {
00336       // Set the first bit.
00337       flags_ |= (1<<DEPEND);
00338     }
00339 
00340     inline void EdgeProperties::resetDepends()
00341     {
00342       // reset the first bit.
00343       flags_ &= ~(1<<DEPEND);
00344     }
00345 
00346     inline bool EdgeProperties::depends() const
00347     {
00348       // Return the first bit.
00349       return flags_.test(DEPEND);
00350     }
00351 
00352     inline void EdgeProperties::resetInfluences()
00353     {
00354       // reset the second bit.
00355       flags_ &= ~(1<<INFLUENCE);
00356     }
00357 
00358     inline bool EdgeProperties::isOneWay() const
00359     {
00360       // Test whether only the first bit is set
00361       return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
00362     }
00363 
00364     inline bool EdgeProperties::isTwoWay() const
00365     {
00366       // Test whether the first and second bit is set      
00367       return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
00368     }
00369 
00370     inline bool EdgeProperties::isStrong() const
00371     {
00372       // Test whether the first or second bit is set
00373       return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
00374     }
00375 
00376 
00377     inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
00378     {
00379       return os << props.flags_;
00380     }
00381 
00382     inline VertexProperties::VertexProperties()
00383       : flags_(0)
00384     {}
00385     
00386     
00387     inline std::bitset<VertexProperties::SIZE>::reference 
00388     VertexProperties::operator[](std::size_t v)
00389     {
00390       return flags_[v];
00391     }
00392     
00393     inline bool VertexProperties::operator[](std::size_t v) const
00394     {
00395       return flags_[v];
00396     }
00397     
00398     inline void VertexProperties::setIsolated()
00399     {
00400       flags_.set(ISOLATED);
00401     }
00402 
00403     inline bool VertexProperties::isolated() const
00404     {
00405       return flags_.test(ISOLATED);
00406     }
00407 
00408     inline void VertexProperties::resetIsolated()
00409     {
00410       flags_.reset(ISOLATED);
00411     }
00412 
00413     inline void VertexProperties::setVisited()
00414     {
00415       flags_.set(VISITED);
00416     }
00417 
00418     inline bool VertexProperties::visited() const
00419     {
00420       return flags_.test(VISITED);
00421     }
00422 
00423     inline void VertexProperties::resetVisited()
00424     {
00425       flags_.reset(VISITED);
00426     }
00427 
00428     inline void VertexProperties::setFront()
00429     {
00430       flags_.set(FRONT);
00431     }
00432 
00433     inline bool VertexProperties::front() const
00434     {
00435       return  flags_.test(FRONT);
00436     }
00437 
00438     inline void VertexProperties::resetFront()
00439     {
00440       flags_.reset(FRONT);
00441     }
00442     /*
00443     inline void VertexProperties::setExcluded()
00444     {
00445       flags_.set(EXCLUDED);
00446     }
00447 
00448     inline bool VertexProperties::excluded() const
00449     {
00450       return  flags_.test(EXCLUDED);
00451     }
00452 
00453     inline void VertexProperties::resetExcluded()
00454     {
00455       flags_.reset(EXCLUDED);
00456     }
00457     */
00458     inline void VertexProperties::reset()
00459     {
00460       flags_=0;
00461     }
00462     
00464   }
00465 }
00466 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)