1 // Created on: 2002-04-17
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
8 // under the terms of the GNU Lesser General Public 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: This is a base class for the List, Set, Queue and Stack
17 // collections. It offers operations on abstract lists (of the
18 // objects of class NCollection_ListNode).
19 // Apart from this class being brand new (in TCollection said
20 // collections were independent, only using the same class for
21 // node representation), here is an important new feature -
22 // the list length is continuously updated, so the method
23 // Extent is quite quick.
25 #ifndef NCollection_BaseList_HeaderFile
26 #define NCollection_BaseList_HeaderFile
28 #include <Standard_NoSuchObject.hxx>
29 #include <NCollection_ListNode.hxx>
31 typedef void (* NCollection_DelListNode)
32 (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
34 // ********************************************************** BaseList class
35 class NCollection_BaseList
41 // ******** Empty constructor
45 // ******** Constructor with initialisation
46 Iterator (const NCollection_BaseList& theList) :
47 myCurrent (theList.myFirst),
49 // ******** Initialisation
50 void Init (const NCollection_BaseList& theList)
52 myCurrent = theList.myFirst;
55 // ******** Initialisation
56 void Initialize (const NCollection_BaseList& theList)
61 Standard_Boolean More (void) const
62 { return (myCurrent!=NULL); }
63 // ******** Assignment operator
64 Iterator& operator= (const Iterator& theIt)
68 myCurrent = theIt.myCurrent;
69 myPrevious = theIt.myPrevious;
73 //skt----------------------------------------------------
74 // ******** Comparison operator
75 Standard_Boolean operator== (const Iterator& theIt)
77 return myCurrent == theIt.myCurrent;
79 //-------------------------------------------------------
81 void Init (const NCollection_BaseList& theList,
82 NCollection_ListNode * const thePrev)
84 myCurrent = thePrev ? thePrev -> Next() :
85 (NCollection_ListNode *)theList.PLast();
89 NCollection_ListNode * myCurrent; // Pointer to the current node
90 NCollection_ListNode * myPrevious;// Pointer to the previous one
91 friend class NCollection_BaseList;
92 }; // End of nested class Iterator
95 // ---------- PUBLIC METHODS ------------
97 // Purpose: Returns the number of nodes in the list
98 Standard_Integer Extent (void) const
102 // Purpose: Query if the list is empty
103 Standard_Boolean IsEmpty (void) const
104 { return (myFirst == NULL); }
107 // --------- PROTECTED METHODS ----------
109 // ******** Constructor
110 // Purpose: Initializes an empty list
111 NCollection_BaseList(void) :
117 // Purpose: deletes all nodes
118 Standard_EXPORT void PClear (NCollection_DelListNode fDel,
119 Handle(NCollection_BaseAllocator)& theAllocator);
122 // Purpose: Returns pointer to the first node
123 const NCollection_ListNode* PFirst (void) const
127 // Purpose: Returns pointer to the last node
128 const NCollection_ListNode* PLast (void) const
132 // Purpose: Appends theNode at the end
133 Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
136 // Purpose: Appends theNode at the end, returns iterator to the previous
137 void PAppend (NCollection_ListNode* theNode,
140 NCollection_ListNode * aPrev = myLast;
142 theIt.Init (* this, aPrev);
146 // Purpose: Appends theOther list at the end (clearing it)
147 Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
150 // Purpose: Prepends theNode at the beginning
151 Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
154 // Purpose: Prepends theOther list at the beginning (clearing it)
155 Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
157 // ******** PRemoveFirst
158 // Purpose: Removes first node
159 Standard_EXPORT void PRemoveFirst
160 (NCollection_DelListNode fDel,
161 Handle(NCollection_BaseAllocator)& theAllocator);
164 // Purpose: Removes the node pointed by theIter[ator]
165 Standard_EXPORT void PRemove
167 NCollection_DelListNode fDel,
168 Handle(NCollection_BaseAllocator)& theAllocator);
170 // ******** PInsertBefore
171 // Purpose: Inserts theNode before one pointed by theIter[ator]
172 Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
175 // ******** PInsertBefore
176 // Purpose: Inserts theOther list before the node pointed by theIter[ator]
177 Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
180 // ******** PInsertAfter
181 // Purpose: Inserts theNode after one pointed by theIter[ator]
182 Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
185 // ******** PInsertAfter
186 // Purpose: Inserts theOther list after the node pointed by theIter[ator]
187 Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
191 // Purpose: Reverse the list
192 Standard_EXPORT void PReverse ();
195 // ------------ PRIVATE FIELDS ------------
196 NCollection_ListNode * myFirst; // Pointer to the head
197 NCollection_ListNode * myLast; // Pointer to the tail
198 Standard_Integer myLength; // Actual length
200 // ------------ FRIEND CLASSES ------------
201 friend class Iterator;