// Copyright (c) 1998-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 #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; }