Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgBWSet.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgBWSet.h
00003     Pair of SgPointSet for Black and White */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef SG_BWSET_H
00007 #define SG_BWSET_H
00008 
00009 #include "SgPointSet.h"
00010 #include "SgBWArray.h"
00011 #include "SgPointSetUtil.h"
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 /** Pair of SgPointSet's indexed by color SG_BLACK, SG_WHITE */
00016 class SgBWSet
00017 {
00018 public:
00019     SgBWSet()
00020     {
00021     }
00022 
00023     SgBWSet(const SgPointSet& black, const SgPointSet& white)
00024         : m_set(black, white)
00025     {
00026     }
00027 
00028     const SgPointSet& operator[](SgBlackWhite c) const
00029     {
00030         return m_set[c];
00031     }
00032 
00033     SgPointSet& operator[](SgBlackWhite c)
00034     {
00035         return m_set[c];
00036     }
00037 
00038     bool operator==(const SgBWSet& other) const;
00039 
00040     bool operator!=(const SgBWSet& other) const;
00041 
00042     SgBWSet& operator|=(const SgBWSet& other);
00043 
00044     void Clear()
00045     {
00046         m_set[SG_BLACK].Clear();
00047         m_set[SG_WHITE].Clear();
00048     }
00049 
00050     bool BothEmpty() const
00051     {
00052         // not called IsEmpty to avoid possible confusion with
00053         // test on single SgPointSet
00054         return m_set[SG_BLACK].IsEmpty() && m_set[SG_WHITE].IsEmpty();
00055     }
00056 
00057     bool Disjoint() const
00058     {
00059         return m_set[SG_BLACK].Disjoint(m_set[SG_WHITE]);
00060     }
00061 
00062     void AssertDisjoint() const
00063     {
00064         SG_ASSERT(Disjoint());
00065     }
00066 
00067     SgPointSet Both() const
00068     {
00069         return m_set[SG_BLACK] | m_set[SG_WHITE];
00070     }
00071 
00072     bool OneContains(SgPoint p) const
00073     {
00074         return m_set[SG_BLACK].Contains(p) 
00075             || m_set[SG_WHITE].Contains(p);
00076     }
00077 
00078     bool BothContain(SgPoint p) const
00079     {
00080         return m_set[SG_BLACK].Contains(p)
00081             && m_set[SG_WHITE].Contains(p);
00082     }
00083 
00084 private:
00085     SgBWArray<SgPointSet> m_set;
00086 };
00087 
00088 inline bool SgBWSet::operator==(const SgBWSet& other) const
00089 {
00090     return (m_set[SG_BLACK] == other.m_set[SG_BLACK]
00091             && m_set[SG_WHITE] == other.m_set[SG_WHITE]);
00092 }
00093 
00094 inline bool SgBWSet::operator!=(const SgBWSet& other) const
00095 {
00096     return ! operator==(other);
00097 }
00098 
00099 inline SgBWSet& SgBWSet::operator|=(const SgBWSet& other)
00100 {
00101     m_set[SG_BLACK] |= other.m_set[SG_BLACK];
00102     m_set[SG_WHITE] |= other.m_set[SG_WHITE];
00103     return (*this);
00104 }
00105 
00106 inline std::ostream& operator<<(std::ostream& out, const SgBWSet& set)
00107 {
00108     out << set[SG_BLACK] << set[SG_WHITE];
00109     return out;
00110 }
00111 
00112 //----------------------------------------------------------------------------
00113 
00114 #endif // SG_BWSET_H


Sun Mar 13 2011 Doxygen 1.7.1