1 // File: NCollection_BaseList.cxx
2 // Created: Tue Apr 23 09:16:44 2002
3 // Author: Alexander KARTOMIN (akm)
4 // <a-kartomin@opencascade.com>
5 // Purpose: Implementation of the BaseList class
7 #include <NCollection_BaseList.hxx>
9 //=======================================================================
11 //purpose : Deletes all nodes from the list
12 //=======================================================================
14 void NCollection_BaseList::PClear
15 (NCollection_DelListNode fDel,
16 Handle(NCollection_BaseAllocator)& theAllocator)
18 NCollection_ListNode* pCur = myFirst;
19 NCollection_ListNode* pNext = NULL;
23 fDel (pCur,theAllocator);
27 myFirst = myLast = NULL;
30 //=======================================================================
32 //purpose : Appends one item at the end
33 //=======================================================================
35 void NCollection_BaseList::PAppend (NCollection_ListNode* theNode)
38 myLast->Next() = theNode;
41 theNode->Next() = NULL;
46 //=======================================================================
48 //purpose : Appends another list at the end
49 //=======================================================================
51 void NCollection_BaseList::PAppend (NCollection_BaseList& theOther)
53 if (this == &theOther || theOther.IsEmpty())
57 myFirst = theOther.myFirst;
59 myLast->Next() = theOther.myFirst;
60 myLast = theOther.myLast;
61 theOther.myFirst = theOther.myLast = NULL;
63 myLength += theOther.myLength;
64 theOther.myLength = 0;
67 //=======================================================================
69 //purpose : Prepends one item at the beginning
70 //=======================================================================
72 void NCollection_BaseList::PPrepend (NCollection_ListNode* theNode)
74 theNode->Next() = myFirst;
81 //=======================================================================
84 //=======================================================================
86 void NCollection_BaseList::PPrepend (NCollection_BaseList& theOther)
88 if (this == &theOther || theOther.IsEmpty())
92 myLast = theOther.myLast;
94 theOther.myLast->Next() = myFirst;
95 myFirst = theOther.myFirst;
96 theOther.myFirst = theOther.myLast = NULL;
98 myLength += theOther.myLength;
99 theOther.myLength = 0;
102 //=======================================================================
103 //function : PRemoveFirst
105 //=======================================================================
107 void NCollection_BaseList::PRemoveFirst
108 (NCollection_DelListNode fDel,
109 Handle(NCollection_BaseAllocator)& theAllocator)
111 Standard_NoSuchObject_Raise_if(IsEmpty(),
112 "NCollection_BaseList::PRemoveFirst");
113 NCollection_ListNode* pItem = myFirst;
114 myFirst = pItem->Next();
115 fDel (pItem, theAllocator);
121 //=======================================================================
124 //=======================================================================
126 void NCollection_BaseList::PRemove
128 NCollection_DelListNode fDel,
129 Handle(NCollection_BaseAllocator)& theAllocator)
131 Standard_NoSuchObject_Raise_if(!theIter.More(),
132 "NCollection_BaseList::PRemove");
133 if (theIter.myPrevious == NULL)
135 PRemoveFirst (fDel,theAllocator);
136 theIter.myCurrent = myFirst;
140 NCollection_ListNode* pNode = (theIter.myCurrent)->Next();
141 (theIter.myPrevious)->Next() = pNode;
142 fDel (theIter.myCurrent,theAllocator);
143 theIter.myCurrent = pNode;
145 myLast = theIter.myPrevious;
150 //=======================================================================
151 //function : PInsertBefore
153 //=======================================================================
155 void NCollection_BaseList::PInsertBefore (NCollection_ListNode* theNode,
158 Standard_NoSuchObject_Raise_if(!theIter.More(),
159 "NCollection_BaseList::PInsertBefore");
160 if (theIter.myPrevious == NULL)
163 theIter.myPrevious = myFirst;
167 (theIter.myPrevious)->Next() = theNode;
168 theNode->Next() = theIter.myCurrent;
169 theIter.myPrevious = theNode;
174 //=======================================================================
175 //function : PInsertBefore
177 //=======================================================================
179 void NCollection_BaseList::PInsertBefore (NCollection_BaseList& theOther,
182 Standard_NoSuchObject_Raise_if(!theIter.More(),
183 "NCollection_BaseList::PInsertBefore");
184 if (theIter.myPrevious == NULL)
186 theIter.myPrevious = theOther.myLast;
189 else if (!theOther.IsEmpty())
191 myLength += theOther.myLength;
192 (theIter.myPrevious)->Next() = theOther.myFirst;
193 (theOther.myLast)->Next() = theIter.myCurrent;
194 theIter.myPrevious = theOther.myLast;
195 theOther.myLast = theOther.myFirst = NULL;
196 theOther.myLength = 0;
200 //=======================================================================
201 //function : PInsertAfter
203 //=======================================================================
205 void NCollection_BaseList::PInsertAfter (NCollection_ListNode* theNode,
208 Standard_NoSuchObject_Raise_if(!theIter.More(),
209 "NCollection_BaseList::PInsertAfter");
210 if (theIter.myCurrent == myLast)
216 theNode->Next() = (theIter.myCurrent)->Next();
217 (theIter.myCurrent)->Next() = theNode;
222 //=======================================================================
223 //function : PInsertAfter
225 //=======================================================================
227 void NCollection_BaseList::PInsertAfter(NCollection_BaseList& theOther,
230 Standard_NoSuchObject_Raise_if(!theIter.More(),
231 "NCollection_BaseList::PInsertAfter");
232 if (theIter.myCurrent == myLast)
236 else if (!theOther.IsEmpty())
238 myLength += theOther.myLength;
239 (theOther.myLast)->Next() = (theIter.myCurrent)->Next();
240 (theIter.myCurrent)->Next() = theOther.myFirst;
241 theOther.myLast = theOther.myFirst = NULL;
242 theOther.myLength = 0;
246 //=======================================================================
247 //function : PReverse
248 //purpose : reverse the list
249 //=======================================================================
251 void NCollection_BaseList::PReverse ()
254 NCollection_ListNode * aHead = myFirst->Next();
255 NCollection_ListNode * aNeck = myFirst;
256 aNeck->Next() = NULL;
258 NCollection_ListNode * aTmp = aHead->Next();
259 aHead->Next() = aNeck;