0024512: clang++ compiler complains about extra semicolon
[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
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.
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_ListNode.hxx>
30
31 typedef void (* NCollection_DelListNode) 
32      (NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
33
34 // ********************************************************** BaseList class
35 class NCollection_BaseList
36 {
37  public:
38   class Iterator
39   {
40   public:
41     // ******** Empty constructor
42     Iterator  (void) :
43       myCurrent (NULL),
44       myPrevious(NULL) {}
45     // ******** Constructor with initialisation
46     Iterator  (const NCollection_BaseList& theList) :
47       myCurrent (theList.myFirst),
48       myPrevious(NULL) {}
49     // ******** Initialisation
50     void Init (const NCollection_BaseList& theList)
51     {
52       myCurrent  = theList.myFirst;
53       myPrevious = NULL;
54     }
55     // ******** Initialisation
56     void Initialize (const NCollection_BaseList& theList)
57     {
58       Init(theList);
59     }
60     // ******** More
61     Standard_Boolean More (void) const
62     { return (myCurrent!=NULL); }
63     // ******** Assignment operator
64     Iterator& operator= (const Iterator& theIt)
65     {
66       if (&theIt != this)
67       {
68         myCurrent  = theIt.myCurrent;
69         myPrevious = theIt.myPrevious;
70       }
71       return * this;
72     }
73 //skt----------------------------------------------------
74     // ******** Comparison operator
75     Standard_Boolean operator== (const Iterator& theIt)
76     {
77       return myCurrent == theIt.myCurrent;
78     }
79 //-------------------------------------------------------
80   protected:
81     void Init (const NCollection_BaseList& theList,
82                NCollection_ListNode * const thePrev)
83     {
84       myCurrent  = thePrev ? thePrev -> Next() :
85                              (NCollection_ListNode *)theList.PLast();
86       myPrevious = thePrev;
87     }
88   public:
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
93
94  public:
95   // ---------- PUBLIC METHODS ------------
96   // ******** Extent
97   // Purpose: Returns the number of nodes in the list
98   Standard_Integer Extent (void) const
99   { return myLength; }
100
101   // ******** IsEmpty
102   // Purpose: Query if the list is empty
103   Standard_Boolean IsEmpty (void) const
104   { return (myFirst == NULL); }
105
106  protected:
107   // --------- PROTECTED METHODS ----------
108
109   // ******** Constructor
110   // Purpose: Initializes an empty list
111   NCollection_BaseList(void) :
112     myFirst(NULL),
113     myLast(NULL),
114     myLength(0) {}
115
116   // ******** PClear
117   // Purpose: deletes all nodes
118   Standard_EXPORT void PClear (NCollection_DelListNode fDel,
119                                Handle(NCollection_BaseAllocator)& theAllocator);
120
121   // ******** PFirst
122   // Purpose: Returns pointer to the first node
123   const NCollection_ListNode* PFirst (void) const
124   { return myFirst; }
125
126   // ******** PLast
127   // Purpose: Returns pointer to the last node
128   const NCollection_ListNode* PLast (void) const
129   { return myLast; }
130
131   // ******** PAppend
132   // Purpose: Appends theNode at the end
133   Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
134
135   // ******** PAppend
136   // Purpose: Appends theNode at the end, returns iterator to the previous
137   void                 PAppend (NCollection_ListNode* theNode,
138                                 Iterator&             theIt)
139   {
140     NCollection_ListNode * aPrev = myLast;
141     PAppend (theNode);
142     theIt.Init (* this, aPrev);
143   }
144
145   // ******** PAppend
146   // Purpose: Appends theOther list at the end (clearing it)
147   Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
148
149   // ******** PPrepend
150   // Purpose: Prepends theNode at the beginning
151   Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
152
153   // ******** PPrepend
154   // Purpose: Prepends theOther list at the beginning (clearing it)
155   Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
156
157   // ******** PRemoveFirst
158   // Purpose: Removes first node
159   Standard_EXPORT void PRemoveFirst 
160     (NCollection_DelListNode fDel,
161      Handle(NCollection_BaseAllocator)& theAllocator);
162
163   // ******** PRemove
164   // Purpose: Removes the node pointed by theIter[ator]
165   Standard_EXPORT void PRemove 
166     (Iterator& theIter,
167      NCollection_DelListNode fDel,
168      Handle(NCollection_BaseAllocator)& theAllocator);
169
170   // ******** PInsertBefore
171   // Purpose: Inserts theNode before one pointed by theIter[ator]
172   Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
173                                       Iterator& theIter);
174
175   // ******** PInsertBefore
176   // Purpose: Inserts theOther list before the node pointed by theIter[ator]
177   Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
178                                       Iterator& theIter);
179
180   // ******** PInsertAfter
181   // Purpose: Inserts theNode after one pointed by theIter[ator]
182   Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
183                                      Iterator& theIter);
184
185   // ******** PInsertAfter
186   // Purpose: Inserts theOther list after the node pointed by theIter[ator]
187   Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
188                                      Iterator& theIter);
189
190   // ******** PReverse
191   // Purpose: Reverse the list
192   Standard_EXPORT void PReverse     ();
193
194  protected:
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
199
200   // ------------ FRIEND CLASSES ------------
201   friend class Iterator;
202 };
203
204 #endif