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