1 #ifndef OCC2VTK_INTERNAL_H
2 #define OCC2VTK_INTERNAL_H
4 #include <NCollection_BaseCollection.hxx>
5 #include <NCollection_BaseList.hxx>
6 #include <NCollection_TListNode.hxx>
7 #include <NCollection_TListIterator.hxx>
9 #include <TopoDS_Vertex.hxx>
10 #include <TopoDS_Edge.hxx>
11 #include <TopoDS_Face.hxx>
13 template <class TheItemType> class GEOM_Set
14 : public NCollection_BaseCollection<TheItemType>,
15 public NCollection_BaseList
18 typedef NCollection_TListNode<TheItemType> SetNode;
19 typedef NCollection_TListIterator<TheItemType> Iterator;
23 GEOM_Set(const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
24 NCollection_BaseCollection<TheItemType>(theAllocator),
25 NCollection_BaseList() {}
28 GEOM_Set (const GEOM_Set& theOther) :
29 NCollection_BaseCollection<TheItemType>(theOther.myAllocator),
30 NCollection_BaseList()
33 //! Size - Number of items
34 virtual Standard_Integer Size (void) const
37 //! Replace this list by the items of theOther collection
38 virtual void Assign (const NCollection_BaseCollection<TheItemType>& theOther)
40 if (this == &theOther)
43 TYPENAME NCollection_BaseCollection<TheItemType>::Iterator& anIter =
44 theOther.CreateIterator();
45 for (; anIter.More(); anIter.Next())
47 SetNode* pNew = new (this->myAllocator) SetNode(anIter.Value());
52 //! Replace this list by the items of theOther Set
53 GEOM_Set& operator= (const GEOM_Set& theOther)
55 if (this == &theOther)
58 SetNode * pCur = (SetNode *) theOther.PFirst();
61 SetNode* pNew = new (this->myAllocator) SetNode(pCur->Value());
63 pCur = (SetNode *) pCur->Next();
70 { PClear (SetNode::delNode, this->myAllocator); }
73 Standard_Boolean Add (const TheItemType& theItem)
75 Iterator anIter(*this);
78 if (anIter.Value() == theItem)
79 return Standard_False;
82 SetNode * pNew = new (this->myAllocator) SetNode(theItem);
88 Standard_Boolean Remove (const TheItemType& theItem)
90 Iterator anIter(*this);
93 if (anIter.Value() == theItem)
95 PRemove (anIter, SetNode::delNode, this->myAllocator);
100 return Standard_False;
103 //! Remove - wrapper against 'hiding' warnings
104 void Remove (Iterator& theIter)
105 { NCollection_BaseList::PRemove (theIter,
107 this->myAllocator); }
109 //! Contains - item inclusion query
110 Standard_Boolean Contains (const TheItemType& theItem) const
112 Iterator anIter(*this);
113 for (; anIter.More(); anIter.Next())
114 if (anIter.Value() == theItem)
115 return Standard_True;
116 return Standard_False;
120 Standard_Boolean IsASubset (const GEOM_Set& theOther)
122 if (this == &theOther)
123 return Standard_True;
124 Iterator anIter(theOther);
125 for (; anIter.More(); anIter.Next())
126 if (!Contains(anIter.Value()))
127 return Standard_False;
128 return Standard_True;
132 Standard_Boolean IsAProperSubset (const GEOM_Set& theOther)
134 if (myLength <= theOther.Extent())
135 return Standard_False;
136 Iterator anIter(theOther);
137 for (; anIter.More(); anIter.Next())
138 if (!Contains(anIter.Value()))
139 return Standard_False;
140 return Standard_True;
144 void Union (const GEOM_Set& theOther)
146 if (this == &theOther)
148 Iterator anIter(theOther);
150 Standard_Integer i, iLength=myLength;
151 for (; anIter.More(); anIter.Next())
153 Standard_Boolean isIn=Standard_False;
154 const TheItemType& theItem = anIter.Value();
155 for (aMyIter.Init(*this), i=1;
158 if (theItem == aMyIter.Value())
159 isIn = Standard_True;
162 SetNode * pNew = new (this->myAllocator) SetNode(theItem);
169 void Intersection (const GEOM_Set& theOther)
171 if (this == &theOther)
173 Iterator anIter(*this);
174 while (anIter.More())
175 if (theOther.Contains(anIter.Value()))
178 NCollection_BaseList::PRemove (anIter, SetNode::delNode, this->myAllocator);
181 //! Difference (Subtraction)
182 void Difference (const GEOM_Set& theOther)
184 if (this == &theOther)
186 Iterator anIter(*this);
187 while (anIter.More())
188 if (theOther.Contains(anIter.Value()))
189 NCollection_BaseList::PRemove (anIter, SetNode::delNode, this->myAllocator);
194 //! Destructor - clears the List
199 //! Creates Iterator for use on BaseCollection
200 virtual TYPENAME NCollection_BaseCollection<TheItemType>::Iterator&
201 CreateIterator(void) const
202 { return *(new (this->IterAllocator()) Iterator(*this)); }
206 typedef GEOM_Set<TopoDS_Vertex> TVertexSet;
207 typedef GEOM_Set<TopoDS_Edge> TEdgeSet;
208 typedef GEOM_Set<TopoDS_Face> TFaceSet;
210 class VertexSourceInternal
213 TVertexSet myVertexSet;
216 class EdgeSourceInternal
222 class FaceSourceInternal
228 #endif // OCC2VTK_INTERNAL_H