Open
Graph Drawing
Framework

 v.2012.05
 

FaceSet.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_FACE_SET_H
00049 #define OGDF_FACE_SET_H
00050 
00051 
00052 #include <ogdf/basic/FaceArray.h>
00053 #include <ogdf/basic/List.h>
00054 
00055 
00056 
00057 namespace ogdf {
00058 
00059 
00061 
00063 class OGDF_EXPORT FaceSetSimple {
00064 public:
00066     FaceSetSimple(const CombinatorialEmbedding &E) : m_isContained(E,false) { }
00067 
00069     ~FaceSetSimple() { }
00070 
00072 
00075     void insert(face f) {
00076         OGDF_ASSERT(f->embeddingOf() == m_isContained.embeddingOf());
00077         bool &isContained = m_isContained[f];
00078         if (isContained == false) {
00079             isContained = true;
00080             m_faces.pushFront(f);
00081         }
00082     }
00083 
00084 
00086 
00088     void clear() {
00089         SListIterator<face> it;
00090         for(it = m_faces.begin(); it.valid(); ++it) {
00091             m_isContained[*it] = false;
00092         }
00093         m_faces.clear();
00094     }
00095 
00096 
00098 
00101     bool isMember(face f) const {
00102         OGDF_ASSERT(f->embeddingOf() == m_isContained.embeddingOf());
00103         return m_isContained[f];
00104     }
00105 
00107     const SListPure<face> &faces() const {
00108         return m_faces;
00109     }
00110 
00111 private:
00113     FaceArray<bool> m_isContained;
00115     SListPure<face> m_faces;
00116 };
00117 
00118 
00119 
00121 
00123 class OGDF_EXPORT FaceSetPure {
00124 public:
00126     FaceSetPure(const CombinatorialEmbedding &E) : m_it(E,ListIterator<face>()) { }
00127 
00129     ~FaceSetPure() { }
00130 
00132 
00135     void insert(face f) {
00136         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00137         ListIterator<face> &itF = m_it[f];
00138         if (!itF.valid())
00139             itF = m_faces.pushBack(f);
00140     }
00141 
00143 
00146     void remove(face f) {
00147         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00148         ListIterator<face> &itF = m_it[f];
00149         if (itF.valid()) {
00150             m_faces.del(itF);
00151             itF = ListIterator<face>();
00152         }
00153     }
00154 
00155 
00157 
00159     void clear() {
00160         ListIterator<face> it;
00161         for(it = m_faces.begin(); it.valid(); ++it) {
00162             m_it[*it] = ListIterator<face>();
00163         }
00164         m_faces.clear();
00165     }
00166 
00167 
00169 
00172     bool isMember(face f) const {
00173         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00174         return m_it[f].valid();
00175     }
00176 
00178     const ListPure<face> &faces() const {
00179         return m_faces;
00180     }
00181 
00182 private:
00184     FaceArray<ListIterator<face> > m_it;
00186     ListPure<face> m_faces;
00187 };
00188 
00189 
00190 
00192 class OGDF_EXPORT FaceSet {
00193 public:
00195     FaceSet(const CombinatorialEmbedding &E) : m_it(E,ListIterator<face>()) { }
00196 
00198     ~FaceSet() { }
00199 
00201 
00204     void insert(face f) {
00205         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00206         ListIterator<face> &itF = m_it[f];
00207         if (!itF.valid())
00208             itF = m_faces.pushBack(f);
00209     }
00210 
00212     /* running time: O(1)
00213      * Precond.: f is a face in the asociated embedding
00214      */
00215     void remove(face f) {
00216         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00217         ListIterator<face> &itF = m_it[f];
00218         if (itF.valid()) {
00219             m_faces.del(itF);
00220             itF = ListIterator<face>();
00221         }
00222     }
00223 
00224 
00226 
00228     void clear() {
00229         ListIterator<face> it;
00230         for(it = m_faces.begin(); it.valid(); ++it) {
00231             m_it[*it] = ListIterator<face>();
00232         }
00233         m_faces.clear();
00234     }
00235 
00236 
00238 
00241     bool isMember(face f) const {
00242         OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf());
00243         return m_it[f].valid();
00244     }
00245 
00247 
00249     int size() const {
00250         return m_faces.size();
00251     }
00252 
00254     const List<face> &faces() const {
00255         return m_faces;
00256     }
00257 
00258 private:
00260     FaceArray<ListIterator<face> > m_it;
00262     List<face> m_faces;
00263 };
00264 
00265 
00266 } // end namespace ogdf
00267 
00268 
00269 #endif
00270