1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
// File: NCollection_BaseList.hxx
// Created: 17.04.02 10:12:48
// Author: Alexander Kartomin (akm)
// <a-kartomin@opencascade.com>
// Copyright: Open Cascade 2002
//
// Purpose: This is a base class for the List, Set, Queue and Stack
// collections. It offers operations on abstract lists (of the
// objects of class NCollection_ListNode).
// Apart from this class being brand new (in TCollection said
// collections were independent, only using the same class for
// node representation), here is an important new feature -
// the list length is continuously updated, so the method
// Extent is quite quick.
//
#ifndef NCollection_BaseList_HeaderFile
#define NCollection_BaseList_HeaderFile
#include <Standard_NoSuchObject.hxx>
#include <NCollection_ListNode.hxx>
#ifdef WNT
// Disable the warning "operator new unmatched by delete"
#pragma warning (disable:4291)
#endif
typedef void (* NCollection_DelListNode)
(NCollection_ListNode*, Handle(NCollection_BaseAllocator)& theAl);
// ********************************************************** BaseList class
class NCollection_BaseList
{
public:
class Iterator
{
public:
// ******** Empty constructor
Iterator (void) :
myCurrent (NULL),
myPrevious(NULL) {}
// ******** Constructor with initialisation
Iterator (const NCollection_BaseList& theList) :
myCurrent (theList.myFirst),
myPrevious(NULL) {}
// ******** Initialisation
void Init (const NCollection_BaseList& theList)
{
myCurrent = theList.myFirst;
myPrevious = NULL;
}
// ******** More
Standard_Boolean More (void) const
{ return (myCurrent!=NULL); }
// ******** Assignment operator
Iterator& operator= (const Iterator& theIt)
{
if (&theIt != this)
{
myCurrent = theIt.myCurrent;
myPrevious = theIt.myPrevious;
}
return * this;
}
//skt----------------------------------------------------
// ******** Comparison operator
Standard_Boolean operator== (const Iterator& theIt)
{
return myCurrent == theIt.myCurrent;
}
//-------------------------------------------------------
protected:
void Init (const NCollection_BaseList& theList,
NCollection_ListNode * const thePrev)
{
myCurrent = thePrev ? thePrev -> Next() :
(NCollection_ListNode *)theList.PLast();
myPrevious = thePrev;
}
public:
NCollection_ListNode * myCurrent; // Pointer to the current node
NCollection_ListNode * myPrevious;// Pointer to the previous one
friend class NCollection_BaseList;
}; // End of nested class Iterator
public:
// ---------- PUBLIC METHODS ------------
// ******** Extent
// Purpose: Returns the number of nodes in the list
Standard_Integer Extent (void) const
{ return myLength; }
// ******** IsEmpty
// Purpose: Query if the list is empty
Standard_Boolean IsEmpty (void) const
{ return (myFirst == NULL); }
protected:
// --------- PROTECTED METHODS ----------
// ******** Constructor
// Purpose: Initializes an empty list
NCollection_BaseList(void) :
myFirst(NULL),
myLast(NULL),
myLength(0) {}
// ******** PClear
// Purpose: deletes all nodes
Standard_EXPORT void PClear (NCollection_DelListNode fDel,
Handle(NCollection_BaseAllocator)& theAllocator);
// ******** PFirst
// Purpose: Returns pointer to the first node
const NCollection_ListNode* PFirst (void) const
{ return myFirst; }
// ******** PLast
// Purpose: Returns pointer to the last node
const NCollection_ListNode* PLast (void) const
{ return myLast; }
// ******** PAppend
// Purpose: Appends theNode at the end
Standard_EXPORT void PAppend (NCollection_ListNode* theNode);
// ******** PAppend
// Purpose: Appends theNode at the end, returns iterator to the previous
void PAppend (NCollection_ListNode* theNode,
Iterator& theIt)
{
NCollection_ListNode * aPrev = myLast;
PAppend (theNode);
theIt.Init (* this, aPrev);
}
// ******** PAppend
// Purpose: Appends theOther list at the end (clearing it)
Standard_EXPORT void PAppend (NCollection_BaseList& theOther);
// ******** PPrepend
// Purpose: Prepends theNode at the beginning
Standard_EXPORT void PPrepend (NCollection_ListNode* theNode);
// ******** PPrepend
// Purpose: Prepends theOther list at the beginning (clearing it)
Standard_EXPORT void PPrepend (NCollection_BaseList& theOther);
// ******** PRemoveFirst
// Purpose: Removes first node
Standard_EXPORT void PRemoveFirst
(NCollection_DelListNode fDel,
Handle(NCollection_BaseAllocator)& theAllocator);
// ******** PRemove
// Purpose: Removes the node pointed by theIter[ator]
Standard_EXPORT void PRemove
(Iterator& theIter,
NCollection_DelListNode fDel,
Handle(NCollection_BaseAllocator)& theAllocator);
// ******** PInsertBefore
// Purpose: Inserts theNode before one pointed by theIter[ator]
Standard_EXPORT void PInsertBefore (NCollection_ListNode* theNode,
Iterator& theIter);
// ******** PInsertBefore
// Purpose: Inserts theOther list before the node pointed by theIter[ator]
Standard_EXPORT void PInsertBefore (NCollection_BaseList& theOther,
Iterator& theIter);
// ******** PInsertAfter
// Purpose: Inserts theNode after one pointed by theIter[ator]
Standard_EXPORT void PInsertAfter (NCollection_ListNode* theNode,
Iterator& theIter);
// ******** PInsertAfter
// Purpose: Inserts theOther list after the node pointed by theIter[ator]
Standard_EXPORT void PInsertAfter (NCollection_BaseList& theOther,
Iterator& theIter);
// ******** PReverse
// Purpose: Reverse the list
Standard_EXPORT void PReverse ();
protected:
// ------------ PRIVATE FIELDS ------------
NCollection_ListNode * myFirst; // Pointer to the head
NCollection_ListNode * myLast; // Pointer to the tail
Standard_Integer myLength; // Actual length
// ------------ FRIEND CLASSES ------------
friend class Iterator;
};
#endif
|