0031671: Coding Rules - eliminate warnings issued by clang 11
[occt.git] / src / NCollection / NCollection_BaseList.hxx
CommitLineData
b311480e 1// Created on: 2002-04-17
2// Created by: Alexander Kartomin (akm)
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 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.
7fd59977 24
25#ifndef NCollection_BaseList_HeaderFile
26#define NCollection_BaseList_HeaderFile
27
28#include <Standard_NoSuchObject.hxx>
ddf2fe8e 29#include <NCollection_DefineAlloc.hxx>
7fd59977 30#include <NCollection_ListNode.hxx>
31
7fd59977 32typedef void (* NCollection_DelListNode)
33 (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
34
35// ********************************************************** BaseList class
36class NCollection_BaseList
37{
ddf2fe8e 38public:
39 //! Memory allocation
40 DEFINE_STANDARD_ALLOC
41 DEFINE_NCOLLECTION_ALLOC
42
43public:
7fd59977 44 class Iterator
45 {
46 public:
47 // ******** Empty constructor
48 Iterator (void) :
49 myCurrent (NULL),
50 myPrevious(NULL) {}
51 // ******** Constructor with initialisation
52 Iterator (const NCollection_BaseList& theList) :
53 myCurrent (theList.myFirst),
54 myPrevious(NULL) {}
55 // ******** Initialisation
56 void Init (const NCollection_BaseList& theList)
57 {
58 myCurrent = theList.myFirst;
59 myPrevious = NULL;
60 }
9991c9c2 61 // ******** Initialisation
62 void Initialize (const NCollection_BaseList& theList)
63 {
64 Init(theList);
65 }
7fd59977 66 // ******** More
67 Standard_Boolean More (void) const
68 { return (myCurrent!=NULL); }
99ee8f1a 69
7fd59977 70 // ******** Comparison operator
79a35943 71 Standard_Boolean operator== (const Iterator& theIt) const
7fd59977 72 {
73 return myCurrent == theIt.myCurrent;
74 }
99ee8f1a 75
79a35943 76 //! Performs comparison of two iterators
ddf2fe8e 77 Standard_Boolean IsEqual (const Iterator& theOther) const
79a35943 78 {
79 return *this == theOther;
80 }
7fd59977 81 protected:
82 void Init (const NCollection_BaseList& theList,
83 NCollection_ListNode * const thePrev)
84 {
85 myCurrent = thePrev ? thePrev -> Next() :
86 (NCollection_ListNode *)theList.PLast();
87 myPrevious = thePrev;
88 }
89 public:
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
94
95 public:
96 // ---------- PUBLIC METHODS ------------
97 // ******** Extent
98 // Purpose: Returns the number of nodes in the list
99 Standard_Integer Extent (void) const
100 { return myLength; }
101
102 // ******** IsEmpty
103 // Purpose: Query if the list is empty
104 Standard_Boolean IsEmpty (void) const
105 { return (myFirst == NULL); }
106
9df7f429 107 // ******** Allocator
108 //! Returns attached allocator
109 const Handle(NCollection_BaseAllocator)& Allocator() const
110 { return myAllocator; }
111
6928e351 112 // ******** Destructor
113 // Purpose: defines virtual interface
114 virtual ~NCollection_BaseList (void)
115 {}
116
7fd59977 117 protected:
118 // --------- PROTECTED METHODS ----------
119
120 // ******** Constructor
121 // Purpose: Initializes an empty list
ddf2fe8e 122 NCollection_BaseList (const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
7fd59977 123 myFirst(NULL),
124 myLast(NULL),
ddf2fe8e 125 myLength(0)
126 {
127 myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
128 }
7fd59977 129
130 // ******** PClear
131 // Purpose: deletes all nodes
ddf2fe8e 132 Standard_EXPORT void PClear (NCollection_DelListNode fDel);
7fd59977 133
134 // ******** PFirst
135 // Purpose: Returns pointer to the first node
136 const NCollection_ListNode* PFirst (void) const
137 { return myFirst; }
138
139 // ******** PLast
140 // Purpose: Returns pointer to the last node
141 const NCollection_ListNode* PLast (void) const
142 { return myLast; }
143
144 // ******** PAppend
145 // Purpose: Appends theNode at the end
146 Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
147
148 // ******** PAppend
149 // Purpose: Appends theNode at the end, returns iterator to the previous
150 void PAppend (NCollection_ListNode* theNode,
151 Iterator& theIt)
152 {
153 NCollection_ListNode * aPrev = myLast;
154 PAppend (theNode);
155 theIt.Init (* this, aPrev);
156 }
157
158 // ******** PAppend
159 // Purpose: Appends theOther list at the end (clearing it)
160 Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
161
162 // ******** PPrepend
163 // Purpose: Prepends theNode at the beginning
164 Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
165
166 // ******** PPrepend
167 // Purpose: Prepends theOther list at the beginning (clearing it)
168 Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
169
170 // ******** PRemoveFirst
171 // Purpose: Removes first node
172 Standard_EXPORT void PRemoveFirst
ddf2fe8e 173 (NCollection_DelListNode fDel);
7fd59977 174
175 // ******** PRemove
176 // Purpose: Removes the node pointed by theIter[ator]
177 Standard_EXPORT void PRemove
178 (Iterator& theIter,
ddf2fe8e 179 NCollection_DelListNode fDel);
7fd59977 180
181 // ******** PInsertBefore
182 // Purpose: Inserts theNode before one pointed by theIter[ator]
183 Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
184 Iterator& theIter);
185
186 // ******** PInsertBefore
187 // Purpose: Inserts theOther list before the node pointed by theIter[ator]
188 Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
189 Iterator& theIter);
190
191 // ******** PInsertAfter
192 // Purpose: Inserts theNode after one pointed by theIter[ator]
193 Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
194 Iterator& theIter);
195
196 // ******** PInsertAfter
197 // Purpose: Inserts theOther list after the node pointed by theIter[ator]
198 Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
199 Iterator& theIter);
200
201 // ******** PReverse
202 // Purpose: Reverse the list
203 Standard_EXPORT void PReverse ();
204
205 protected:
ddf2fe8e 206 // ------------ PROTECTED FIELDS ------------
207 Handle(NCollection_BaseAllocator) myAllocator;
7fd59977 208 NCollection_ListNode * myFirst; // Pointer to the head
209 NCollection_ListNode * myLast; // Pointer to the tail
210 Standard_Integer myLength; // Actual length
211
212 // ------------ FRIEND CLASSES ------------
213 friend class Iterator;
214};
215
216#endif