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 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: 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_DefineAlloc.hxx>
30 #include <NCollection_ListNode.hxx>
32 typedef void (* NCollection_DelListNode)
33 (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
35 // ********************************************************** BaseList class
36 class NCollection_BaseList
41 DEFINE_NCOLLECTION_ALLOC
47 // ******** Empty constructor
51 // ******** Constructor with initialisation
52 Iterator (const NCollection_BaseList& theList) :
53 myCurrent (theList.myFirst),
55 // ******** Initialisation
56 void Init (const NCollection_BaseList& theList)
58 myCurrent = theList.myFirst;
61 // ******** Initialisation
62 void Initialize (const NCollection_BaseList& theList)
67 Standard_Boolean More (void) const
68 { return (myCurrent!=NULL); }
70 // ******** Comparison operator
71 Standard_Boolean operator== (const Iterator& theIt) const
73 return myCurrent == theIt.myCurrent;
76 //! Performs comparison of two iterators
77 Standard_Boolean IsEqual (const Iterator& theOther) const
79 return *this == theOther;
82 void Init (const NCollection_BaseList& theList,
83 NCollection_ListNode * const thePrev)
85 myCurrent = thePrev ? thePrev -> Next() :
86 (NCollection_ListNode *)theList.PLast();
90 NCollection_ListNode * myCurrent; // Pointer to the current node
91 NCollection_ListNode * myPrevious;// Pointer to the previous one
92 friend class NCollection_BaseList;
93 }; // End of nested class Iterator
96 // ---------- PUBLIC METHODS ------------
98 // Purpose: Returns the number of nodes in the list
99 Standard_Integer Extent (void) const
103 // Purpose: Query if the list is empty
104 Standard_Boolean IsEmpty (void) const
105 { return (myFirst == NULL); }
107 // ******** Allocator
108 //! Returns attached allocator
109 const Handle(NCollection_BaseAllocator)& Allocator() const
110 { return myAllocator; }
112 // ******** Destructor
113 // Purpose: defines virtual interface
114 virtual ~NCollection_BaseList (void)
118 // --------- PROTECTED METHODS ----------
120 // ******** Constructor
121 // Purpose: Initializes an empty list
122 NCollection_BaseList (const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
127 myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
131 // Purpose: deletes all nodes
132 Standard_EXPORT void PClear (NCollection_DelListNode fDel);
135 // Purpose: Returns pointer to the first node
136 const NCollection_ListNode* PFirst (void) const
140 // Purpose: Returns pointer to the last node
141 const NCollection_ListNode* PLast (void) const
145 // Purpose: Appends theNode at the end
146 Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
149 // Purpose: Appends theNode at the end, returns iterator to the previous
150 void PAppend (NCollection_ListNode* theNode,
153 NCollection_ListNode * aPrev = myLast;
155 theIt.Init (* this, aPrev);
159 // Purpose: Appends theOther list at the end (clearing it)
160 Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
163 // Purpose: Prepends theNode at the beginning
164 Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
167 // Purpose: Prepends theOther list at the beginning (clearing it)
168 Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
170 // ******** PRemoveFirst
171 // Purpose: Removes first node
172 Standard_EXPORT void PRemoveFirst
173 (NCollection_DelListNode fDel);
176 // Purpose: Removes the node pointed by theIter[ator]
177 Standard_EXPORT void PRemove
179 NCollection_DelListNode fDel);
181 // ******** PInsertBefore
182 // Purpose: Inserts theNode before one pointed by theIter[ator]
183 Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
186 // ******** PInsertBefore
187 // Purpose: Inserts theOther list before the node pointed by theIter[ator]
188 Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
191 // ******** PInsertAfter
192 // Purpose: Inserts theNode after one pointed by theIter[ator]
193 Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
196 // ******** PInsertAfter
197 // Purpose: Inserts theOther list after the node pointed by theIter[ator]
198 Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
202 // Purpose: Reverse the list
203 Standard_EXPORT void PReverse ();
206 // ------------ PROTECTED FIELDS ------------
207 Handle(NCollection_BaseAllocator) myAllocator;
208 NCollection_ListNode * myFirst; // Pointer to the head
209 NCollection_ListNode * myLast; // Pointer to the tail
210 Standard_Integer myLength; // Actual length
212 // ------------ FRIEND CLASSES ------------
213 friend class Iterator;