0031671: Coding Rules - eliminate warnings issued by clang 11
[occt.git] / src / NCollection / NCollection_BaseList.hxx
1 // Created on: 2002-04-17
2 // Created by: Alexander Kartomin (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
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.
24
25 #ifndef NCollection_BaseList_HeaderFile
26 #define NCollection_BaseList_HeaderFile
27
28 #include <Standard_NoSuchObject.hxx>
29 #include <NCollection_DefineAlloc.hxx>
30 #include <NCollection_ListNode.hxx>
31
32 typedef void (* NCollection_DelListNode) 
33      (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
34
35 // ********************************************************** BaseList class
36 class NCollection_BaseList
37 {
38 public:
39   //! Memory allocation
40   DEFINE_STANDARD_ALLOC
41   DEFINE_NCOLLECTION_ALLOC
42
43 public:
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     }
61     // ******** Initialisation
62     void Initialize (const NCollection_BaseList& theList)
63     {
64       Init(theList);
65     }
66     // ******** More
67     Standard_Boolean More (void) const
68     { return (myCurrent!=NULL); }
69
70     // ******** Comparison operator
71     Standard_Boolean operator== (const Iterator& theIt) const
72     {
73       return myCurrent == theIt.myCurrent;
74     }
75
76     //! Performs comparison of two iterators
77     Standard_Boolean IsEqual (const Iterator& theOther) const
78     {
79       return *this == theOther;
80     }
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
107   // ******** Allocator
108   //! Returns attached allocator
109   const Handle(NCollection_BaseAllocator)& Allocator() const 
110   { return myAllocator; }
111
112   // ******** Destructor
113   // Purpose: defines virtual interface
114   virtual ~NCollection_BaseList (void)
115   {}
116
117  protected:
118   // --------- PROTECTED METHODS ----------
119
120   // ******** Constructor
121   // Purpose: Initializes an empty list
122   NCollection_BaseList (const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
123     myFirst(NULL),
124     myLast(NULL),
125     myLength(0)
126   {
127     myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
128   }
129
130   // ******** PClear
131   // Purpose: deletes all nodes
132   Standard_EXPORT void PClear (NCollection_DelListNode fDel);
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 
173     (NCollection_DelListNode fDel);
174
175   // ******** PRemove
176   // Purpose: Removes the node pointed by theIter[ator]
177   Standard_EXPORT void PRemove 
178     (Iterator& theIter,
179      NCollection_DelListNode fDel);
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:
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
211
212   // ------------ FRIEND CLASSES ------------
213   friend class Iterator;
214 };
215
216 #endif