Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TCollection / TCollection_Queue.gxx
CommitLineData
7fd59977 1// File: TCollection_Queue.gxx
2// Created: Mon Jan 18 14:55:37 1993
3// Author: Remi LEQUETTE
4// <rle@phylox>
5
6#include <Standard_NoSuchObject.hxx>
7
8//=======================================================================
9//function : TCollection_Queue
10//purpose :
11//=======================================================================
12
13TCollection_Queue::TCollection_Queue() :
14 myFront(NULL),
15 myEnd(NULL),
16 myLength(0)
17{
18}
19
20//=======================================================================
21//function : TCollection_Queue
22//purpose :
23//=======================================================================
24
25TCollection_Queue::TCollection_Queue(const TCollection_Queue& Other)
26{
27 if (!Other.IsEmpty()) {
28 cout << "WARNING copy constructor of non empty Queue !"<<endl;
29 }
30 TCollection_QueueNode* p = (TCollection_QueueNode*) Other.myFront;
31 TCollection_QueueNode* q = NULL;
32 TCollection_QueueNode* r = NULL;
33 myFront = NULL;
34 while (p) {
35 q = new TCollection_QueueNode(p->Value(),(TCollection_MapNode*)0L);
36 if (r) r->Next() = q;
37 else myFront = q;
38 r = q;
39 p = (TCollection_QueueNode*)p->Next();
40 }
41 myEnd = q;
42 myLength = Other.myLength;
43}
44
45//=======================================================================
46//function : Assign
47//purpose :
48//=======================================================================
49
50const TCollection_Queue& TCollection_Queue::Assign
51 (const TCollection_Queue& Other)
52{
53 if (this == &Other) return *this;
54 Clear();
55 TCollection_QueueNode* p = (TCollection_QueueNode*) Other.myFront;
56 TCollection_QueueNode* q=NULL;
57 TCollection_QueueNode* r = NULL;
58 while (p) {
59 q = new TCollection_QueueNode(p->Value(),(TCollection_MapNode*)0L);
60 if (r) r->Next() = q;
61 else myFront = q;
62 r = q;
63 p = (TCollection_QueueNode*)p->Next();
64 }
65 myEnd = q;
66 myLength = Other.myLength;
67 return *this;
68}
69
70
71
72//=======================================================================
73//function : Front
74//purpose :
75//=======================================================================
76
77const Item& TCollection_Queue::Front() const
78{
79 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Queue");
80 return ((TCollection_QueueNode*)myFront)->Value();
81}
82
83//=======================================================================
84//function : Push
85//purpose :
86//=======================================================================
87
88void TCollection_Queue::Push(const Item& I)
89{
90 TCollection_QueueNode* p = new TCollection_QueueNode(I,(TCollection_MapNode*)0L);
91 if (myLength) ((TCollection_QueueNode*)myEnd)->Next() = p;
92 else myFront = p;
93 myEnd = p;
94 myLength++;
95}
96
97//=======================================================================
98//function : Pop
99//purpose :
100//=======================================================================
101
102void TCollection_Queue::Pop()
103{
104 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Queue");
105 TCollection_QueueNode* p = (TCollection_QueueNode*) myFront;
106 myFront = p->Next();
107 delete p;
108 myLength--;
109 if (myLength == 0) myEnd = NULL;
110}
111
112//=======================================================================
113//function : Clear
114//purpose :
115//=======================================================================
116
117void TCollection_Queue::Clear()
118{
119 TCollection_QueueNode* p = (TCollection_QueueNode*) myFront;
120 TCollection_QueueNode* q = 0L;
121 while(p) {
122 q = (TCollection_QueueNode*)p->Next();
123 delete p;
124 p = q;
125 }
126 myLength = 0;
127 myFront = myEnd = NULL;
128}
129
130//=======================================================================
131//function : ChangeFront
132//purpose :
133//=======================================================================
134
135Item& TCollection_Queue::ChangeFront()
136{
137 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Queue");
138 return ((TCollection_QueueNode*)myFront)->Value();
139}
140