1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Standard_NoSuchObject.hxx>
16 #include <Standard_NotImplemented.hxx>
17 #include <Standard_NoMoreObject.hxx>
23 PCollection_HStack::PCollection_HStack()
26 TheTop = new PCollection_StackNode;
29 // ------------------------------------
30 // Push : insert an item on the top
31 // ------------------------------------
32 void PCollection_HStack::Push(const Item& T)
34 TheTop = TheTop->Construct(T);
35 TheDepth = TheDepth + 1;
39 // ------------------------------------
40 // Pop : remove an item from the top
41 // ------------------------------------
42 void PCollection_HStack::Pop()
44 if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
45 Handle(PCollection_StackNode) temp = TheTop;
46 TheTop = TheTop->Tail();
48 TheDepth = TheDepth - 1;
52 // -----------------------------
53 // IsEmpty : is the stack empty ?
54 // -----------------------------
55 Standard_Boolean PCollection_HStack::IsEmpty() const
57 return TheTop->IsEmpty();
60 // ------------------------------------
61 // Clear : remove all items
62 // ------------------------------------
63 void PCollection_HStack::Clear()
65 Handle(PCollection_StackNode) temp;
66 while (TheDepth != 0) {
68 TheTop = TheTop->Tail();
74 // ------------------------------------
75 // ChangeTop : replace the top by T
76 // ------------------------------------
77 void PCollection_HStack::ChangeTop(const Item& T)
79 if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
83 // -----------------------------
84 // Top : item on the Top
85 // -----------------------------
86 Item PCollection_HStack::Top() const
88 if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
89 return TheTop->Value();
93 // ------------------------------------
94 // ShallowCopy redefinition
95 // ------------------------------------
96 Handle(Standard_Persistent) PCollection_HStack::ShallowCopy() const
98 PCollection_HStack* TheCopy = new PCollection_HStack (*this);
100 Handle(PCollection_StackNode)::DownCast(::ShallowCopy(TheTop));
104 // ------------------------------------
105 // ShallowDump redefinition
106 // ------------------------------------
107 void PCollection_HStack::ShallowDump(Standard_OStream& S) const
109 S << "begin class Stack "<< endl;
110 S << "Length of Stack : "<< TheDepth << endl;
111 TheTop->ShallowDump(S);
112 S << "end of class Stack." << endl;
117 // -----------------------------
118 // Depth : numbers of items
119 // -----------------------------
120 Standard_Integer PCollection_HStack::Depth() const {
124 // -----------------------------
125 // FTop : Top of the Stack
126 // -----------------------------
127 Handle(PCollection_StackNode) PCollection_HStack::FTop() const {