1 // Created on: 1993-01-18
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_NoSuchObject.hxx>
19 //=======================================================================
20 //function : TCollection_Stack
22 //=======================================================================
24 TCollection_Stack::TCollection_Stack() :
30 //=======================================================================
31 //function : TCollection_Stack
33 //=======================================================================
35 TCollection_Stack::TCollection_Stack(const TCollection_Stack& Other)
37 if (!Other.IsEmpty()) {
38 cout << "WARNING copy constructor of non empty stack !"<<endl;
40 TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop;
41 TCollection_StackNode* q;
42 TCollection_StackNode* r = NULL;
45 q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L);
49 p = (TCollection_StackNode*)p->Next();
51 myDepth = Other.myDepth;
54 //=======================================================================
57 //=======================================================================
59 const TCollection_Stack& TCollection_Stack::Assign
60 (const TCollection_Stack& Other)
62 if (this == &Other) return *this;
64 TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop;
65 TCollection_StackNode* q;
66 TCollection_StackNode* r = NULL;
68 q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L);
72 p = (TCollection_StackNode*)p->Next();
74 myDepth = Other.myDepth;
79 //=======================================================================
82 //=======================================================================
84 const Item& TCollection_Stack::Top() const
86 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
87 return ((TCollection_StackNode*)myTop)->Value();
90 //=======================================================================
93 //=======================================================================
95 void TCollection_Stack::Push(const Item& I)
97 myTop = new TCollection_StackNode(I,(TCollection_StackNode*)myTop);
101 //=======================================================================
104 //=======================================================================
106 void TCollection_Stack::Pop()
108 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
109 TCollection_StackNode* p = (TCollection_StackNode*) myTop;
115 //=======================================================================
118 //=======================================================================
120 void TCollection_Stack::Clear()
122 TCollection_StackNode* p = (TCollection_StackNode*) myTop;
123 TCollection_StackNode* q;
125 q = (TCollection_StackNode*)p->Next();
133 //=======================================================================
134 //function : ChangeTop
136 //=======================================================================
138 Item& TCollection_Stack::ChangeTop()
140 Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
141 return ((TCollection_StackNode*)myTop)->Value();
144 //=======================================================================
147 //=======================================================================
149 void TCollection_StackIterator::Next()
151 current = ((TCollection_StackNode*)current)->Next();
154 //=======================================================================
157 //=======================================================================
159 const Item& TCollection_StackIterator::Value() const
161 Standard_NoSuchObject_Raise_if(current == NULL,
162 "TCollection_StackIterator");
163 return ((TCollection_StackNode*)current)->Value();