1 // File: NCollection_BaseList.hxx
2 // Created: 17.04.02 10:12:48
3 // Author: Alexander Kartomin (akm)
4 // <a-kartomin@opencascade.com>
5 // Copyright: Open Cascade 2002
7 // Purpose: This is a base class for the List, Set, Queue and Stack
8 // collections. It offers operations on abstract lists (of the
9 // objects of class NCollection_ListNode).
10 // Apart from this class being brand new (in TCollection said
11 // collections were independent, only using the same class for
12 // node representation), here is an important new feature -
13 // the list length is continuously updated, so the method
14 // Extent is quite quick.
17 #ifndef NCollection_BaseList_HeaderFile
18 #define NCollection_BaseList_HeaderFile
20 #include <Standard_NoSuchObject.hxx>
21 #include <NCollection_ListNode.hxx>
24 // Disable the warning "operator new unmatched by delete"
25 #pragma warning (disable:4291)
28 typedef void (* NCollection_DelListNode)
29 (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
31 // ********************************************************** BaseList class
32 class NCollection_BaseList
38 // ******** Empty constructor
42 // ******** Constructor with initialisation
43 Iterator (const NCollection_BaseList& theList) :
44 myCurrent (theList.myFirst),
46 // ******** Initialisation
47 void Init (const NCollection_BaseList& theList)
49 myCurrent = theList.myFirst;
52 // ******** Initialisation
53 void Initialize (const NCollection_BaseList& theList)
58 Standard_Boolean More (void) const
59 { return (myCurrent!=NULL); }
60 // ******** Assignment operator
61 Iterator& operator= (const Iterator& theIt)
65 myCurrent = theIt.myCurrent;
66 myPrevious = theIt.myPrevious;
70 //skt----------------------------------------------------
71 // ******** Comparison operator
72 Standard_Boolean operator== (const Iterator& theIt)
74 return myCurrent == theIt.myCurrent;
76 //-------------------------------------------------------
78 void Init (const NCollection_BaseList& theList,
79 NCollection_ListNode * const thePrev)
81 myCurrent = thePrev ? thePrev -> Next() :
82 (NCollection_ListNode *)theList.PLast();
86 NCollection_ListNode * myCurrent; // Pointer to the current node
87 NCollection_ListNode * myPrevious;// Pointer to the previous one
88 friend class NCollection_BaseList;
89 }; // End of nested class Iterator
92 // ---------- PUBLIC METHODS ------------
94 // Purpose: Returns the number of nodes in the list
95 Standard_Integer Extent (void) const
99 // Purpose: Query if the list is empty
100 Standard_Boolean IsEmpty (void) const
101 { return (myFirst == NULL); }
104 // --------- PROTECTED METHODS ----------
106 // ******** Constructor
107 // Purpose: Initializes an empty list
108 NCollection_BaseList(void) :
114 // Purpose: deletes all nodes
115 Standard_EXPORT void PClear (NCollection_DelListNode fDel,
116 Handle(NCollection_BaseAllocator)& theAllocator);
119 // Purpose: Returns pointer to the first node
120 const NCollection_ListNode* PFirst (void) const
124 // Purpose: Returns pointer to the last node
125 const NCollection_ListNode* PLast (void) const
129 // Purpose: Appends theNode at the end
130 Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
133 // Purpose: Appends theNode at the end, returns iterator to the previous
134 void PAppend (NCollection_ListNode* theNode,
137 NCollection_ListNode * aPrev = myLast;
139 theIt.Init (* this, aPrev);
143 // Purpose: Appends theOther list at the end (clearing it)
144 Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
147 // Purpose: Prepends theNode at the beginning
148 Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
151 // Purpose: Prepends theOther list at the beginning (clearing it)
152 Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
154 // ******** PRemoveFirst
155 // Purpose: Removes first node
156 Standard_EXPORT void PRemoveFirst
157 (NCollection_DelListNode fDel,
158 Handle(NCollection_BaseAllocator)& theAllocator);
161 // Purpose: Removes the node pointed by theIter[ator]
162 Standard_EXPORT void PRemove
164 NCollection_DelListNode fDel,
165 Handle(NCollection_BaseAllocator)& theAllocator);
167 // ******** PInsertBefore
168 // Purpose: Inserts theNode before one pointed by theIter[ator]
169 Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
172 // ******** PInsertBefore
173 // Purpose: Inserts theOther list before the node pointed by theIter[ator]
174 Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
177 // ******** PInsertAfter
178 // Purpose: Inserts theNode after one pointed by theIter[ator]
179 Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
182 // ******** PInsertAfter
183 // Purpose: Inserts theOther list after the node pointed by theIter[ator]
184 Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
188 // Purpose: Reverse the list
189 Standard_EXPORT void PReverse ();
192 // ------------ PRIVATE FIELDS ------------
193 NCollection_ListNode * myFirst; // Pointer to the head
194 NCollection_ListNode * myLast; // Pointer to the tail
195 Standard_Integer myLength; // Actual length
197 // ------------ FRIEND CLASSES ------------
198 friend class Iterator;