1 // Created on: 2002-04-23
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // Purpose: Implementation of the BaseList class
18 #include <NCollection_BaseList.hxx>
20 //=======================================================================
22 //purpose : Deletes all nodes from the list
23 //=======================================================================
25 void NCollection_BaseList::PClear (NCollection_DelListNode fDel)
27 NCollection_ListNode* pCur = myFirst;
28 NCollection_ListNode* pNext = NULL;
32 fDel (pCur, myAllocator);
36 myFirst = myLast = NULL;
39 //=======================================================================
41 //purpose : Appends one item at the end
42 //=======================================================================
44 void NCollection_BaseList::PAppend (NCollection_ListNode* theNode)
47 myLast->Next() = theNode;
50 theNode->Next() = NULL;
55 //=======================================================================
57 //purpose : Appends another list at the end
58 //=======================================================================
60 void NCollection_BaseList::PAppend (NCollection_BaseList& theOther)
62 if (this == &theOther || theOther.IsEmpty())
66 myFirst = theOther.myFirst;
68 myLast->Next() = theOther.myFirst;
69 myLast = theOther.myLast;
70 theOther.myFirst = theOther.myLast = NULL;
72 myLength += theOther.myLength;
73 theOther.myLength = 0;
76 //=======================================================================
78 //purpose : Prepends one item at the beginning
79 //=======================================================================
81 void NCollection_BaseList::PPrepend (NCollection_ListNode* theNode)
83 theNode->Next() = myFirst;
90 //=======================================================================
93 //=======================================================================
95 void NCollection_BaseList::PPrepend (NCollection_BaseList& theOther)
97 if (this == &theOther || theOther.IsEmpty())
101 myLast = theOther.myLast;
103 theOther.myLast->Next() = myFirst;
104 myFirst = theOther.myFirst;
105 theOther.myFirst = theOther.myLast = NULL;
107 myLength += theOther.myLength;
108 theOther.myLength = 0;
111 //=======================================================================
112 //function : PRemoveFirst
114 //=======================================================================
116 void NCollection_BaseList::PRemoveFirst (NCollection_DelListNode fDel)
118 Standard_NoSuchObject_Raise_if(IsEmpty(),
119 "NCollection_BaseList::PRemoveFirst");
120 NCollection_ListNode* pItem = myFirst;
121 myFirst = pItem->Next();
122 fDel (pItem, myAllocator);
128 //=======================================================================
131 //=======================================================================
133 void NCollection_BaseList::PRemove (Iterator& theIter, NCollection_DelListNode fDel)
135 Standard_NoSuchObject_Raise_if(!theIter.More(),
136 "NCollection_BaseList::PRemove");
137 if (theIter.myPrevious == NULL)
140 theIter.myCurrent = myFirst;
144 NCollection_ListNode* pNode = (theIter.myCurrent)->Next();
145 (theIter.myPrevious)->Next() = pNode;
146 fDel (theIter.myCurrent, myAllocator);
147 theIter.myCurrent = pNode;
149 myLast = theIter.myPrevious;
154 //=======================================================================
155 //function : PInsertBefore
157 //=======================================================================
159 void NCollection_BaseList::PInsertBefore (NCollection_ListNode* theNode,
162 Standard_NoSuchObject_Raise_if(!theIter.More(),
163 "NCollection_BaseList::PInsertBefore");
164 if (theIter.myPrevious == NULL)
167 theIter.myPrevious = myFirst;
171 (theIter.myPrevious)->Next() = theNode;
172 theNode->Next() = theIter.myCurrent;
173 theIter.myPrevious = theNode;
178 //=======================================================================
179 //function : PInsertBefore
181 //=======================================================================
183 void NCollection_BaseList::PInsertBefore (NCollection_BaseList& theOther,
186 Standard_NoSuchObject_Raise_if(!theIter.More(),
187 "NCollection_BaseList::PInsertBefore");
188 if (theIter.myPrevious == NULL)
190 theIter.myPrevious = theOther.myLast;
193 else if (!theOther.IsEmpty())
195 myLength += theOther.myLength;
196 (theIter.myPrevious)->Next() = theOther.myFirst;
197 (theOther.myLast)->Next() = theIter.myCurrent;
198 theIter.myPrevious = theOther.myLast;
199 theOther.myLast = theOther.myFirst = NULL;
200 theOther.myLength = 0;
204 //=======================================================================
205 //function : PInsertAfter
207 //=======================================================================
209 void NCollection_BaseList::PInsertAfter (NCollection_ListNode* theNode,
212 Standard_NoSuchObject_Raise_if(!theIter.More(),
213 "NCollection_BaseList::PInsertAfter");
214 if (theIter.myCurrent == myLast)
220 theNode->Next() = (theIter.myCurrent)->Next();
221 (theIter.myCurrent)->Next() = theNode;
226 //=======================================================================
227 //function : PInsertAfter
229 //=======================================================================
231 void NCollection_BaseList::PInsertAfter(NCollection_BaseList& theOther,
234 Standard_NoSuchObject_Raise_if(!theIter.More(),
235 "NCollection_BaseList::PInsertAfter");
236 if (theIter.myCurrent == myLast)
240 else if (!theOther.IsEmpty())
242 myLength += theOther.myLength;
243 (theOther.myLast)->Next() = (theIter.myCurrent)->Next();
244 (theIter.myCurrent)->Next() = theOther.myFirst;
245 theOther.myLast = theOther.myFirst = NULL;
246 theOther.myLength = 0;
250 //=======================================================================
251 //function : PReverse
252 //purpose : reverse the list
253 //=======================================================================
255 void NCollection_BaseList::PReverse ()
258 NCollection_ListNode * aHead = myFirst->Next();
259 NCollection_ListNode * aNeck = myFirst;
260 aNeck->Next() = NULL;
262 NCollection_ListNode * aTmp = aHead->Next();
263 aHead->Next() = aNeck;