mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-07-25 12:55:50 +03:00
170 lines
5.2 KiB
Plaintext
Executable File
170 lines
5.2 KiB
Plaintext
Executable File
// Created on: 1993-01-18
|
|
// Created by: Remi LEQUETTE
|
|
// Copyright (c) 1993-1999 Matra Datavision
|
|
// Copyright (c) 1999-2012 OPEN CASCADE SAS
|
|
//
|
|
// The content of this file is subject to the Open CASCADE Technology Public
|
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
|
// except in compliance with the License. Please obtain a copy of the License
|
|
// at http://www.opencascade.org and read it completely before using this file.
|
|
//
|
|
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
|
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
|
//
|
|
// The Original Code and all software distributed under the License is
|
|
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
|
// Initial Developer hereby disclaims all such warranties, including without
|
|
// limitation, any warranties of merchantability, fitness for a particular
|
|
// purpose or non-infringement. Please see the License for the specific terms
|
|
// and conditions governing the rights and limitations under the License.
|
|
|
|
|
|
#include <Standard_NoSuchObject.hxx>
|
|
|
|
//=======================================================================
|
|
//function : TCollection_Stack
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
TCollection_Stack::TCollection_Stack() :
|
|
myTop(NULL),
|
|
myDepth(0)
|
|
{
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : TCollection_Stack
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
TCollection_Stack::TCollection_Stack(const TCollection_Stack& Other)
|
|
{
|
|
if (!Other.IsEmpty()) {
|
|
cout << "WARNING copy constructor of non empty stack !"<<endl;
|
|
}
|
|
TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop;
|
|
TCollection_StackNode* q;
|
|
TCollection_StackNode* r = NULL;
|
|
myTop = NULL;
|
|
while (p) {
|
|
q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L);
|
|
if (r) r->Next() = q;
|
|
else myTop = q;
|
|
r = q;
|
|
p = (TCollection_StackNode*)p->Next();
|
|
}
|
|
myDepth = Other.myDepth;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Assign
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
const TCollection_Stack& TCollection_Stack::Assign
|
|
(const TCollection_Stack& Other)
|
|
{
|
|
if (this == &Other) return *this;
|
|
Clear();
|
|
TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop;
|
|
TCollection_StackNode* q;
|
|
TCollection_StackNode* r = NULL;
|
|
while (p) {
|
|
q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L);
|
|
if (r) r->Next() = q;
|
|
else myTop = q;
|
|
r = q;
|
|
p = (TCollection_StackNode*)p->Next();
|
|
}
|
|
myDepth = Other.myDepth;
|
|
return *this;
|
|
}
|
|
|
|
|
|
//=======================================================================
|
|
//function : Top
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
const Item& TCollection_Stack::Top() const
|
|
{
|
|
Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
|
|
return ((TCollection_StackNode*)myTop)->Value();
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Push
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void TCollection_Stack::Push(const Item& I)
|
|
{
|
|
myTop = new TCollection_StackNode(I,(TCollection_StackNode*)myTop);
|
|
myDepth++;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Pop
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void TCollection_Stack::Pop()
|
|
{
|
|
Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
|
|
TCollection_StackNode* p = (TCollection_StackNode*) myTop;
|
|
myTop = p->Next();
|
|
delete p;
|
|
myDepth--;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Clear
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void TCollection_Stack::Clear()
|
|
{
|
|
TCollection_StackNode* p = (TCollection_StackNode*) myTop;
|
|
TCollection_StackNode* q;
|
|
while(p) {
|
|
q = (TCollection_StackNode*)p->Next();
|
|
delete p;
|
|
p = q;
|
|
}
|
|
myDepth = 0;
|
|
myTop = NULL;
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : ChangeTop
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
Item& TCollection_Stack::ChangeTop()
|
|
{
|
|
Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack");
|
|
return ((TCollection_StackNode*)myTop)->Value();
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Next
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
void TCollection_StackIterator::Next()
|
|
{
|
|
current = ((TCollection_StackNode*)current)->Next();
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Value
|
|
//purpose :
|
|
//=======================================================================
|
|
|
|
const Item& TCollection_StackIterator::Value() const
|
|
{
|
|
Standard_NoSuchObject_Raise_if(current == NULL,
|
|
"TCollection_StackIterator");
|
|
return ((TCollection_StackNode*)current)->Value();
|
|
}
|