#include #include #include // ------------ // constructor // ----------- PCollection_HStack::PCollection_HStack() { TheDepth = 0; TheTop = new PCollection_StackNode; } // ------------------------------------ // Push : insert an item on the top // ------------------------------------ void PCollection_HStack::Push(const Item& T) { TheTop = TheTop->Construct(T); TheDepth = TheDepth + 1; } // ------------------------------------ // Pop : remove an item from the top // ------------------------------------ void PCollection_HStack::Pop() { if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise(); Handle(PCollection_StackNode) temp = TheTop; TheTop = TheTop->Tail(); temp.Delete(); TheDepth = TheDepth - 1; } // ----------------------------- // IsEmpty : is the stack empty ? // ----------------------------- Standard_Boolean PCollection_HStack::IsEmpty() const { return TheTop->IsEmpty(); } // ------------------------------------ // Clear : remove all items // ------------------------------------ void PCollection_HStack::Clear() { Handle(PCollection_StackNode) temp; while (TheDepth != 0) { temp = TheTop; TheTop = TheTop->Tail(); temp.Delete(); --TheDepth; } } // ------------------------------------ // ChangeTop : replace the top by T // ------------------------------------ void PCollection_HStack::ChangeTop(const Item& T) { if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise(); TheTop->SetValue(T); } // ----------------------------- // Top : item on the Top // ----------------------------- Item PCollection_HStack::Top() const { if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise(); return TheTop->Value(); } // ------------------------------------ // ShallowCopy redefinition // ------------------------------------ Handle(Standard_Persistent) PCollection_HStack::ShallowCopy() const { PCollection_HStack* TheCopy = new PCollection_HStack (*this); TheCopy->TheTop = Handle(PCollection_StackNode)::DownCast(::ShallowCopy(TheTop)); return TheCopy; } // ------------------------------------ // ShallowDump redefinition // ------------------------------------ void PCollection_HStack::ShallowDump(Standard_OStream& S) const { S << "begin class Stack "<< endl; S << "Length of Stack : "<< TheDepth << endl; TheTop->ShallowDump(S); S << "end of class Stack." << endl; } // ----------------------------- // Depth : numbers of items // ----------------------------- Standard_Integer PCollection_HStack::Depth() const { return TheDepth; } // ----------------------------- // FTop : Top of the Stack // ----------------------------- Handle(PCollection_StackNode) PCollection_HStack::FTop() const { return TheTop; }