mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
4
src/PCollection/FILES
Executable file
4
src/PCollection/FILES
Executable file
@@ -0,0 +1,4 @@
|
||||
PCollection_Compare.gxx
|
||||
PCollection_CMPLRS.edl
|
||||
PCollection_LDSHR.edl
|
||||
PCollection_WOKSteps.edl
|
155
src/PCollection/PCollection.cdl
Executable file
155
src/PCollection/PCollection.cdl
Executable file
@@ -0,0 +1,155 @@
|
||||
-- File: PCollection.cdl
|
||||
-- Created: Tue Feb 9 18:44:30 1993
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun4>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
package PCollection
|
||||
|
||||
uses
|
||||
Standard,
|
||||
DBC,
|
||||
MMgt,
|
||||
PMMgt,
|
||||
TCollection
|
||||
|
||||
is
|
||||
|
||||
enumeration AccessMode is
|
||||
Read,
|
||||
Update
|
||||
end AccessMode;
|
||||
|
||||
|
||||
generic class HArray1, FieldOfHArray1 ;
|
||||
|
||||
generic class HArray2, FieldOfHArray2 ;
|
||||
|
||||
generic class HSingleList;
|
||||
---Purpose: The private generic class SingleList represents
|
||||
-- a sequence of 0 or more linked items.
|
||||
|
||||
generic class HDoubleList;
|
||||
---Purpose: A List is a sequence of zero or more items
|
||||
-- Each item has two pointers (backward,forward)
|
||||
|
||||
|
||||
generic class HSequence,SeqNode,SeqExplorer;
|
||||
|
||||
---Purpose: Generic sequence of elements
|
||||
-- indexed by an integer in the range 1..N.
|
||||
|
||||
generic class HQueue,QueueNode,QueueIterator;
|
||||
|
||||
---Purpose: A queue is a sequence of items in which items
|
||||
-- are added at one end (called the back of the queue)
|
||||
-- and removed at the other end (calledthe front).
|
||||
-- The Queue is empty if there are no elements.
|
||||
|
||||
|
||||
generic class HSet,SetNode,SetIterator;
|
||||
|
||||
---Purpose: A set is an unordered collection of items
|
||||
-- We can not have duplicated items in a given set.
|
||||
|
||||
|
||||
generic class HStack,StackNode,StackIterator;
|
||||
|
||||
---Purpose: A stack is a list of items in which items are
|
||||
-- added and removed from the same end, called the
|
||||
-- top of the stack.
|
||||
|
||||
generic class Hash;
|
||||
|
||||
---Purpose: Definition of hash function. This class is used by Map
|
||||
-- class and may be redefined by user.
|
||||
|
||||
generic class HDataMap,MapNode,Array,MapIterator;
|
||||
|
||||
---Purpose: A map is a Collection of bindings
|
||||
-- between two objects. One is considered as
|
||||
-- the key and a hash code value must be
|
||||
-- computed for it.
|
||||
|
||||
generic class HDoubleMap,
|
||||
DoubleMapNode,
|
||||
ArrayDoubleMap,
|
||||
DoubleMapIterator;
|
||||
---Purpose: A double map is a collection of bindings
|
||||
-- between two objects.
|
||||
-- It can be retrieved either by its Key or its Item;
|
||||
-- A hash code value must be computed for both.
|
||||
|
||||
generic class HIndexedDataMap,
|
||||
IndexedDataMapNode,
|
||||
ArrayIndexedDataMap;
|
||||
---Purpose: The IndexedDataMap is a hashed set of objects of
|
||||
-- Type Key, called Keys. Keys can be inserted in
|
||||
-- the Map but not removed. The Map keeps the number
|
||||
-- of keys called NbKeys. Each time a Key is inserted
|
||||
-- the Map tests if this Key is already in the Map.
|
||||
-- If it is, nothing is done. If not, NbKeys is
|
||||
-- incremented and it's value is bound to the Key
|
||||
-- and called the Index.
|
||||
|
||||
deferred generic class Compare ;
|
||||
|
||||
---Purpose: Defines a comparison operator which can be used by
|
||||
-- any ordered structure. The way to compare items
|
||||
-- has to be described in subclasses, which inherit
|
||||
-- from instantiations of Compare.
|
||||
|
||||
private deferred class PrivCompareOfInteger
|
||||
instantiates Compare from PCollection(Integer);
|
||||
|
||||
private deferred class PrivCompareOfReal
|
||||
instantiates Compare from PCollection(Real);
|
||||
|
||||
class CompareOfInteger;
|
||||
|
||||
class CompareOfReal;
|
||||
|
||||
enumeration Side is Left , Right;
|
||||
|
||||
generic class HAVLSearchTree,
|
||||
AVLNode,
|
||||
AVLNodeStack,
|
||||
AVLIterator ;
|
||||
|
||||
exception IsNotRoot inherits Failure;
|
||||
exception IsNullTree inherits Failure;
|
||||
exception IsContained inherits Failure;
|
||||
|
||||
generic class HArbitraryTree,
|
||||
SeqArbitraryTree,
|
||||
StackArbitraryTree,
|
||||
ATPreOrderIterator ,
|
||||
ATPostOrderIterator,
|
||||
ATInOrderIterator ;
|
||||
|
||||
generic class HDirectedGraph,
|
||||
Vertex,
|
||||
Edge,
|
||||
SetOfVertex,
|
||||
SetOfEdge,
|
||||
StackOfVertex,
|
||||
QueueOfVertex,
|
||||
FrontEdgesIterator,
|
||||
BackEdgesIterator,
|
||||
DepthFirstIterator,
|
||||
BreadthFirstIterator,
|
||||
AdjacentVerticesIterator,
|
||||
VerticesIterator,
|
||||
RootsIterator,
|
||||
LeavesIterator,
|
||||
EdgesIterator;
|
||||
|
||||
class HAsciiString;
|
||||
|
||||
class HExtendedString;
|
||||
|
||||
|
||||
end PCollection;
|
||||
|
||||
|
129
src/PCollection/PCollection_ATInOrderIterator.gxx
Executable file
129
src/PCollection/PCollection_ATInOrderIterator.gxx
Executable file
@@ -0,0 +1,129 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_ATInOrderIterator.gxx
|
||||
// Created: Aug, 17 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Purpose: Permits to iterate through an ArbitraryTree so that, from
|
||||
// the most left leave, it reads it, then its parent, then in
|
||||
// the same order what is on its right.
|
||||
// IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
// THEN it will read ( C B D E A F I H J K G)
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create
|
||||
//-------------------------------------------------------------------
|
||||
PCollection_ATInOrderIterator::PCollection_ATInOrderIterator
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
CurrentStack = new PCollection_StackArbitraryTree;
|
||||
if (ATree.IsNull()) {
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
else {
|
||||
// ... stop at the last child to the left
|
||||
RecursiveAppend( ATree);
|
||||
CurrentTree = CurrentStack->Top();
|
||||
HasMore = Standard_True;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// More
|
||||
//-------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_ATInOrderIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Value
|
||||
//-------------------------------------------------------------------
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_ATInOrderIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return CurrentTree;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Clear
|
||||
//-------------------------------------------------------------------
|
||||
void PCollection_ATInOrderIterator::Clear ()
|
||||
{
|
||||
CurrentTree.Nullify();
|
||||
CurrentStack.Nullify();
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Next
|
||||
//-------------------------------------------------------------------
|
||||
void PCollection_ATInOrderIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
Handle(PCollection_HArbitraryTree) Temp;
|
||||
Standard_Integer Nb = CurrentTree->NbChildren();
|
||||
if( Nb > 1) {
|
||||
// ... go to the other children (first one already visited)
|
||||
Temp = CurrentTree->Child(2);
|
||||
RecursiveAppend( Temp);
|
||||
}
|
||||
else {
|
||||
// ... was <CurrentTree> the first child ?
|
||||
// ... If yes, nothing more to do than removing it
|
||||
// ... if not, go upward, and on the right as soon as possible
|
||||
Temp = RecursiveRemove( CurrentTree);
|
||||
Handle(PCollection_HArbitraryTree) Left = Temp->LeftSibling();
|
||||
if ( !Left.IsNull()) RecursiveAppend(Temp->RightSibling());
|
||||
}
|
||||
// ... CurrentTree's updating
|
||||
if (HasMore) CurrentTree = CurrentStack->Top();
|
||||
}
|
||||
|
||||
// INTERNAL TOOLS TO MANAGE CurrentStack
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------
|
||||
void PCollection_ATInOrderIterator::RecursiveAppend (
|
||||
const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
CurrentStack->Push(ATree);
|
||||
// ... is there still some child ?
|
||||
if( !ATree->IsLeaf()) {
|
||||
RecursiveAppend(ATree->Child(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_ATInOrderIterator::RecursiveRemove (
|
||||
const Handle(PCollection_HArbitraryTree)& ATree) {
|
||||
|
||||
Handle(PCollection_HArbitraryTree) Temp = ATree;
|
||||
CurrentStack->Pop();
|
||||
if( CurrentStack->IsEmpty()) {
|
||||
// ... it's the end...
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
else {
|
||||
// ... are there other trees to be removed ?
|
||||
Handle(PCollection_HArbitraryTree) Left = ATree->LeftSibling();
|
||||
Handle(PCollection_HArbitraryTree) Right = ATree->RightSibling();
|
||||
if(!Left.IsNull() && Right.IsNull()) {
|
||||
// ... it's still necessary to go upward
|
||||
Temp = CurrentStack->Top();
|
||||
Temp = RecursiveRemove( Temp);
|
||||
}
|
||||
}
|
||||
return Temp;
|
||||
}
|
||||
|
||||
|
105
src/PCollection/PCollection_ATPostOrderIterator.gxx
Executable file
105
src/PCollection/PCollection_ATPostOrderIterator.gxx
Executable file
@@ -0,0 +1,105 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_ATPostOrderIterator.gxx
|
||||
// Created: Aug, 13 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Purpose: Permits to iterate through an ArbitraryTree beginning by
|
||||
// the most left leave and its rightSibling, then upward to
|
||||
// its parent, ..
|
||||
// IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
// THEN it will read ( C D E B F I J K H G A)
|
||||
|
||||
|
||||
// --------
|
||||
// Create
|
||||
// --------
|
||||
PCollection_ATPostOrderIterator::
|
||||
PCollection_ATPostOrderIterator
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
CurrentStack = new PCollection_StackArbitraryTree;
|
||||
if (ATree.IsNull()) {
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
else {
|
||||
HasMore = Standard_True;
|
||||
RecursiveAppend(ATree);
|
||||
CurrentTree = CurrentStack->Top();
|
||||
}
|
||||
}
|
||||
|
||||
// --------
|
||||
// More
|
||||
// --------
|
||||
Standard_Boolean PCollection_ATPostOrderIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Value
|
||||
// --------
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_ATPostOrderIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return CurrentTree;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Clear
|
||||
// --------
|
||||
void PCollection_ATPostOrderIterator::Clear ()
|
||||
{
|
||||
CurrentTree.Nullify();
|
||||
CurrentStack.Nullify();
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Next
|
||||
// --------
|
||||
void PCollection_ATPostOrderIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
// ... removes the last tree
|
||||
CurrentStack->Pop();
|
||||
if (CurrentStack->IsEmpty()) {
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
else {
|
||||
// ... is there still someone on the right ?
|
||||
// ... if yes, go on to the right
|
||||
Handle(PCollection_HArbitraryTree) Temp = CurrentTree->RightSibling();
|
||||
if (!Temp.IsNull()) {
|
||||
RecursiveAppend(Temp);
|
||||
}
|
||||
CurrentTree = CurrentStack->Top();
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE TOOLS TO MANAGE CURRENTSTACK
|
||||
|
||||
// --------
|
||||
// --------
|
||||
void PCollection_ATPostOrderIterator::RecursiveAppend (
|
||||
const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
CurrentStack->Push(ATree);
|
||||
// ... is there still some child ?
|
||||
if ( !ATree->IsLeaf()) {
|
||||
RecursiveAppend( ATree->Child(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
119
src/PCollection/PCollection_ATPreOrderIterator.gxx
Executable file
119
src/PCollection/PCollection_ATPreOrderIterator.gxx
Executable file
@@ -0,0 +1,119 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_ATPreOrderIterator.gxx
|
||||
// Created: Aug, 13 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Purpose: Permits to iterate through an ArbitraryTree so that,
|
||||
// from the root, it reads each element on the left,
|
||||
// until the first leave, then goes to its rightSibling
|
||||
// and upward.
|
||||
// IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
// THEN it will read ( A B C D E F G H I J K)
|
||||
|
||||
// -----------
|
||||
// constructor :
|
||||
// -----------
|
||||
PCollection_ATPreOrderIterator::
|
||||
PCollection_ATPreOrderIterator
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
CurrentStack = new PCollection_StackArbitraryTree;
|
||||
if (ATree.IsNull()) {
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
else {
|
||||
HasMore = Standard_True;
|
||||
CurrentTree = ATree;
|
||||
CurrentStack->Push(ATree);
|
||||
}
|
||||
}
|
||||
|
||||
// --------
|
||||
// More
|
||||
// --------
|
||||
Standard_Boolean PCollection_ATPreOrderIterator::More() const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Value
|
||||
// --------
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_ATPreOrderIterator::Value() const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return CurrentTree;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Clear
|
||||
// --------
|
||||
void PCollection_ATPreOrderIterator::Clear()
|
||||
{
|
||||
CurrentTree.Nullify();
|
||||
CurrentStack.Nullify();
|
||||
HasMore = Standard_False;
|
||||
}
|
||||
|
||||
// --------
|
||||
// Next
|
||||
// --------
|
||||
void PCollection_ATPreOrderIterator::Next()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
Handle(PCollection_HArbitraryTree) Temp;
|
||||
if (CurrentTree->IsLeaf()) {
|
||||
// ... no child, so go upward, then to the right
|
||||
Temp = RecursiveRemove( CurrentTree);
|
||||
// ... and adds the right neighbour of the last removed tree
|
||||
if ( HasMore) {
|
||||
CurrentTree = Temp->RightSibling();
|
||||
CurrentStack->Push(CurrentTree);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// ... just go down for one step
|
||||
CurrentTree = CurrentTree->Child(1);
|
||||
CurrentStack->Push(CurrentTree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PRIVATE TOOLS TO MANAGE CURRENTSTACK
|
||||
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_ATPreOrderIterator::RecursiveRemove(
|
||||
const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
Handle(PCollection_HArbitraryTree) Temp;
|
||||
CurrentStack->Pop();
|
||||
if ( CurrentStack->IsEmpty()) {
|
||||
HasMore = Standard_False;
|
||||
Temp = ATree; // ... to be returned
|
||||
}
|
||||
else {
|
||||
// ... is there somebody to the right ? if yes, stop removing
|
||||
// ... if not, go on removing
|
||||
Temp = ATree->RightSibling();
|
||||
if (!Temp.IsNull()) {
|
||||
Temp = ATree; // ... to be returned
|
||||
}
|
||||
else {
|
||||
Temp = CurrentStack->Top();
|
||||
Temp = RecursiveRemove( Temp);
|
||||
}
|
||||
}
|
||||
return Temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
111
src/PCollection/PCollection_AVLIterator.gxx
Executable file
111
src/PCollection/PCollection_AVLIterator.gxx
Executable file
@@ -0,0 +1,111 @@
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// Created: Wed May,13 1992
|
||||
// Created by: Jean-Pierre TIRAULT
|
||||
// <jpt@topsn1>
|
||||
// Revised: Wed Oct,21 1992
|
||||
// By : Mireille MERCIEN
|
||||
// <mip@sdsun3>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
typedef PCollection_AVLNodeStack Stack;
|
||||
typedef PCollection_HAVLSearchTree Tree;
|
||||
typedef Handle(PCollection_HAVLSearchTree) Handle(Tree);
|
||||
typedef PCollection_AVLNode Node;
|
||||
typedef Handle(PCollection_AVLNode) Handle(Node);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
PCollection_AVLIterator::
|
||||
PCollection_AVLIterator ( const Handle(Tree)& aTree)
|
||||
{
|
||||
CurrentStack = new Stack; // Create an empty Stack
|
||||
Handle(Node) Root = aTree->GetRoot(); // Current node = root of tree
|
||||
if (Root.IsNull()) {
|
||||
HasMore = False;
|
||||
}
|
||||
else {
|
||||
HasMore = True;
|
||||
// CURRENTSTACK MANAGEMENT
|
||||
Append( Root);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_AVLIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_AVLIterator::Value () const
|
||||
{
|
||||
if (!HasMore) NoSuchObject::Raise();
|
||||
return CurrentNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_AVLIterator::Clear ()
|
||||
{
|
||||
CurrentNode.Nullify();
|
||||
CurrentStack.Nullify();
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_AVLIterator::Next ()
|
||||
{
|
||||
if (!HasMore) NoMoreObject::Raise();
|
||||
Handle(Node) Right = CurrentNode->RightChild();
|
||||
|
||||
// WHAT ARE THE FOLLOWING ELEMENTS ?
|
||||
if ( Right.IsNull()) {
|
||||
RecursiveRemove(CurrentNode);
|
||||
// MAYBE IT'S THE END
|
||||
if (CurrentStack->IsEmpty())
|
||||
HasMore = False;
|
||||
else
|
||||
CurrentNode = CurrentStack->Top();
|
||||
}
|
||||
else {
|
||||
Append (Right);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PRIVATE TOOLS TO ITERATE
|
||||
|
||||
|
||||
void PCollection_AVLIterator::Append ( const Handle(Node)& Root)
|
||||
{
|
||||
RecursiveAppend( Root);
|
||||
CurrentNode = CurrentStack->Top();
|
||||
}
|
||||
|
||||
|
||||
void PCollection_AVLIterator::RecursiveAppend(const Handle(Node)& ANode)
|
||||
{
|
||||
if (!ANode.IsNull()) {
|
||||
CurrentStack->Push(ANode);
|
||||
Handle(Node) Left = ANode->LeftChild();
|
||||
RecursiveAppend( Left);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PCollection_AVLIterator::RecursiveRemove(const Handle(Node)& theNode)
|
||||
{
|
||||
CurrentStack->Pop();
|
||||
if (CurrentStack->IsEmpty()) return;
|
||||
Handle(Node) NewNode = CurrentStack->Top();
|
||||
if (theNode == NewNode->RightChild()) {
|
||||
RecursiveRemove(NewNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
156
src/PCollection/PCollection_AVLNode.gxx
Executable file
156
src/PCollection/PCollection_AVLNode.gxx
Executable file
@@ -0,0 +1,156 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_AVLNode.gxx
|
||||
// Created: Fri May 24 10:38:53 1991
|
||||
// Author: Annick PANCHER
|
||||
// <apc>
|
||||
// Updated: Jean-Pierre TIRAULT Apr,6 1992, Mireille MERCIEN
|
||||
|
||||
#include <PCollection_Side.hxx>
|
||||
typedef PCollection_Side Side;
|
||||
typedef PCollection_AVLNode Node;
|
||||
typedef Handle(PCollection_AVLNode) Handle(Node);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Create
|
||||
// --------------------------------------------------------------------------
|
||||
PCollection_AVLNode::PCollection_AVLNode(const Item& theItem)
|
||||
{
|
||||
MyItem = theItem;
|
||||
Count = 1;
|
||||
MyRightChild.Nullify();
|
||||
MyLeftChild.Nullify();
|
||||
}
|
||||
|
||||
// -------------------------- READING ---------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// RightChild
|
||||
// --------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_AVLNode::RightChild () const
|
||||
{
|
||||
return MyRightChild;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// LeftChild
|
||||
// --------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_AVLNode::LeftChild () const
|
||||
{
|
||||
return MyLeftChild;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Value
|
||||
// --------------------------------------------------------------------------
|
||||
Item PCollection_AVLNode::Value () const
|
||||
{
|
||||
return MyItem;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetMultiplicity
|
||||
// --------------------------------------------------------------------------
|
||||
Integer PCollection_AVLNode::GetMultiplicity () const
|
||||
{
|
||||
return Count;
|
||||
}
|
||||
// -------------------- WRITING ---------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Setvalue
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::SetValue(const Item& theValue)
|
||||
{
|
||||
MyItem = theValue;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetRightChild
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::
|
||||
SetRightChild(const Handle(Node)& theNode)
|
||||
{
|
||||
MyRightChild = theNode;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// SetLeftChild
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::
|
||||
SetLeftChild(const Handle(Node)& theNode)
|
||||
{
|
||||
MyLeftChild = theNode;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetChild
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::SetChild
|
||||
( const Handle(Node)& theNode, const Side theSide)
|
||||
{
|
||||
if (theSide == PCollection_Left) {
|
||||
MyLeftChild = theNode;
|
||||
}
|
||||
else {
|
||||
MyRightChild = theNode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// SetMultiplicity
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::SetMultiplicity(const Integer theCount)
|
||||
{
|
||||
Count = theCount;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Copy
|
||||
//-----------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_AVLNode::Copy() const
|
||||
{
|
||||
Handle(Node) newNode = new Node(MyItem);
|
||||
newNode->SetMultiplicity(Count);
|
||||
if (!MyLeftChild.IsNull()) newNode->SetLeftChild(MyLeftChild->Copy());
|
||||
if (!MyRightChild.IsNull()) newNode->SetRightChild(MyRightChild->Copy());
|
||||
return newNode;
|
||||
}
|
||||
|
||||
// ------------ REDEFINED
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ShallowCopy
|
||||
// --------------------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_AVLNode::ShallowCopy() const
|
||||
{
|
||||
Handle(Node) TheCopy;
|
||||
TheCopy = new Node(MyItem);
|
||||
TheCopy->SetMultiplicity (Count);
|
||||
TheCopy->SetValue (MyItem);
|
||||
TheCopy->SetRightChild (MyRightChild);
|
||||
TheCopy->SetLeftChild (MyLeftChild);
|
||||
return TheCopy;
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
// ----------------------------------------------------------------------------
|
||||
void PCollection_AVLNode::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class AVLNode "<< endl;
|
||||
// MyItem->ShallowDump(S) ;
|
||||
S << "Count : "<< Count << "times." << endl;
|
||||
MyLeftChild->ShallowDump(S);
|
||||
MyRightChild->ShallowDump(S);
|
||||
S << "end class AVLNode" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
65
src/PCollection/PCollection_AdjacentVerticesIterator.gxx
Executable file
65
src/PCollection/PCollection_AdjacentVerticesIterator.gxx
Executable file
@@ -0,0 +1,65 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_AdjacentVerticesIterator.gxx
|
||||
// Created: Wed May 29 17:42:37 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_AdjacentVerticesIterator::PCollection_AdjacentVerticesIterator
|
||||
(const Handle(PCollection_Vertex)& V):MyEdgeIterator(V->GetFrontEdges())
|
||||
{
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_AdjacentVerticesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_AdjacentVerticesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
MyEdgeIterator.Next();
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_AdjacentVerticesIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
Handle(PCollection_Edge) AnEdge = MyEdgeIterator.Value();
|
||||
return AnEdge->Destination();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_AdjacentVerticesIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
62
src/PCollection/PCollection_BackEdgesIterator.gxx
Executable file
62
src/PCollection/PCollection_BackEdgesIterator.gxx
Executable file
@@ -0,0 +1,62 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_BackEdgesIterator.gxx
|
||||
// Created: Wed May 29 17:42:21 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_BackEdgesIterator::PCollection_BackEdgesIterator
|
||||
(const Handle(PCollection_Vertex)& V):MyEdgeIterator(V->GetBackEdges())
|
||||
{
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_BackEdgesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_BackEdgesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
MyEdgeIterator.Next();
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Edge) PCollection_BackEdgesIterator::Value () const
|
||||
{
|
||||
if (HasMore) {
|
||||
return MyEdgeIterator.Value();
|
||||
}
|
||||
else {
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_BackEdgesIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
81
src/PCollection/PCollection_BreadthFirstIterator.gxx
Executable file
81
src/PCollection/PCollection_BreadthFirstIterator.gxx
Executable file
@@ -0,0 +1,81 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_BreadthFirstIterator.gxx
|
||||
// Created: Wed May 29 17:43:06 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_BreadthFirstIterator::
|
||||
PCollection_BreadthFirstIterator (const Handle(PCollection_Vertex)& V)
|
||||
{
|
||||
Visited = new PCollection_SetOfVertex;
|
||||
Ready = new PCollection_QueueOfVertex;
|
||||
Visited->Add(V);
|
||||
//mip Ready->Add(V);
|
||||
Ready->Push(V);
|
||||
HasMore = !(Ready->IsEmpty());
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_BreadthFirstIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_BreadthFirstIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
Handle(PCollection_Vertex) w1 = Ready->Front();
|
||||
Ready->Pop();
|
||||
PCollection_FrontEdgesIterator It(w1);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Vertex) w2 = It.Value()->Destination();
|
||||
if (! (Visited->Contains(w2))) {
|
||||
//mip Ready->Add(w2);
|
||||
Ready->Push(w2);
|
||||
Visited->Add(w2);
|
||||
}
|
||||
It.Next();
|
||||
}
|
||||
HasMore = !(Ready->IsEmpty());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_BreadthFirstIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return Ready->Front();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_BreadthFirstIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
3
src/PCollection/PCollection_CMPLRS.edl
Executable file
3
src/PCollection/PCollection_CMPLRS.edl
Executable file
@@ -0,0 +1,3 @@
|
||||
@if ( ( %Station == "ao1" ) && ( %DBMS == "OBJS" ) ) then
|
||||
@uses "OBJSCMPLRS.edl";
|
||||
@endif;
|
36
src/PCollection/PCollection_Compare.cdl
Executable file
36
src/PCollection/PCollection_Compare.cdl
Executable file
@@ -0,0 +1,36 @@
|
||||
-- File: PCollection_Compare.cdl
|
||||
-- Created: Tue May 14 18:07:48 1991
|
||||
-- Author: Annick PANCHER
|
||||
-- <apc@topsn2>
|
||||
-- Revised: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
-- Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
deferred generic class Compare from PCollection ( Item as Storable)
|
||||
inherits Storable
|
||||
|
||||
---Purpose: Defines a comparison operator which can be used by
|
||||
-- any ordered structure. The way to compare items
|
||||
-- has to be described in subclasses, which inherit
|
||||
-- from instantiations of Compare.
|
||||
|
||||
is
|
||||
|
||||
IsLower (me; Left, Right: Item)
|
||||
---Purpose: Returns True if <Left> is lower than <Right>
|
||||
returns Boolean is virtual;
|
||||
---Level: Public
|
||||
|
||||
IsGreater (me; Left, Right: Item)
|
||||
---Purpose: Returns True if <Left> is greater than <Right>
|
||||
returns Boolean is virtual;
|
||||
---Level: Public
|
||||
|
||||
IsEqual(me; Left, Right: Item)
|
||||
---Purpose: Returns True when <Right> and <Left> are equal.
|
||||
returns Boolean;
|
||||
---Level: Public
|
||||
end;
|
||||
|
||||
|
42
src/PCollection/PCollection_Compare.gxx
Executable file
42
src/PCollection/PCollection_Compare.gxx
Executable file
@@ -0,0 +1,42 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_Compare.gxx
|
||||
// Created: Thu Aug 27 12:06:34 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// <mip@sdsun3>
|
||||
// Copyright: Matra Datavision 1992
|
||||
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
// -----------
|
||||
// IsLower :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_Compare::IsLower (const Item& ,
|
||||
const Item& ) const
|
||||
{
|
||||
// Standard_NotImplemented::Raise();
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsGreater :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_Compare::IsGreater (const Item& ,
|
||||
const Item& ) const
|
||||
{
|
||||
// Standard_NotImplemented::Raise();
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsEqual :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_Compare::IsEqual (const Item& ,
|
||||
const Item& ) const
|
||||
{
|
||||
// return (Left == Right) ;
|
||||
Standard_ProgramError::Raise("PCollection_Compare::IsEqual : Obsolete method...");
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
|
28
src/PCollection/PCollection_CompareOfInteger.cdl
Executable file
28
src/PCollection/PCollection_CompareOfInteger.cdl
Executable file
@@ -0,0 +1,28 @@
|
||||
-- File: PCollection_CompareOfInteger.cdl
|
||||
-- Created: Thu Aug 27 12:06:34 1992
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
class CompareOfInteger from PCollection
|
||||
inherits
|
||||
PrivCompareOfInteger
|
||||
|
||||
is
|
||||
|
||||
Create ;
|
||||
|
||||
IsLower (me; Left, Right: Integer)
|
||||
---Purpose: Returns True if <Left> is lower than <Right>.
|
||||
---Level: Public
|
||||
returns Boolean
|
||||
is redefined;
|
||||
|
||||
IsGreater (me; Left, Right: Integer)
|
||||
---Purpose: Returns True if <Left> is greater than <Right>.
|
||||
---Level: Public
|
||||
returns Boolean
|
||||
is redefined;
|
||||
|
||||
end;
|
32
src/PCollection/PCollection_CompareOfInteger.cxx
Executable file
32
src/PCollection/PCollection_CompareOfInteger.cxx
Executable file
@@ -0,0 +1,32 @@
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// <mip@sdsun3>
|
||||
// File: PCollection_CompareOfInteger.cxx
|
||||
// Created: Thu Aug 27 12:06:34 1992
|
||||
// Author: Mireille MERCIEN
|
||||
|
||||
#include <PCollection_CompareOfInteger.ixx>
|
||||
|
||||
// -----------
|
||||
// Create :
|
||||
// -----------
|
||||
PCollection_CompareOfInteger::PCollection_CompareOfInteger()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsLower :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_CompareOfInteger::IsLower (
|
||||
const Standard_Integer &Left,const Standard_Integer &Right) const
|
||||
{
|
||||
return (Left < Right) ;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsGreater :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_CompareOfInteger::IsGreater (
|
||||
const Standard_Integer &Left,const Standard_Integer &Right) const
|
||||
{
|
||||
return (Left > Right) ;
|
||||
}
|
28
src/PCollection/PCollection_CompareOfReal.cdl
Executable file
28
src/PCollection/PCollection_CompareOfReal.cdl
Executable file
@@ -0,0 +1,28 @@
|
||||
-- File: PCollection_CompareOfReal.cdl
|
||||
-- Created: Thu Aug 27 12:27:20 1992
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
class CompareOfReal from PCollection
|
||||
inherits
|
||||
PrivCompareOfReal
|
||||
|
||||
is
|
||||
|
||||
Create;
|
||||
|
||||
IsLower (me; Left, Right: Real)
|
||||
---Purpose: Returns True if <Left> is lower than <Right>.
|
||||
---Level: Public
|
||||
returns Boolean
|
||||
is redefined;
|
||||
|
||||
IsGreater (me; Left, Right: Real)
|
||||
---Purpose: Returns True if <Left> is greater than <Right>.
|
||||
---Level: Public
|
||||
returns Boolean
|
||||
is redefined;
|
||||
|
||||
end;
|
38
src/PCollection/PCollection_CompareOfReal.cxx
Executable file
38
src/PCollection/PCollection_CompareOfReal.cxx
Executable file
@@ -0,0 +1,38 @@
|
||||
// Do not delete this line. Used by sccs.
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// <mip@sdsun3>
|
||||
// File: PCollection_CompareOfReal.cxx
|
||||
// Created: Thu Aug 27 12:06:34 1992
|
||||
// Author: Mireille MERCIEN
|
||||
|
||||
#include <PCollection_CompareOfReal.ixx>
|
||||
|
||||
// -----------
|
||||
// Create :
|
||||
// -----------
|
||||
PCollection_CompareOfReal::PCollection_CompareOfReal()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsLower :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_CompareOfReal::IsLower (
|
||||
const Standard_Real &Left,const Standard_Real &Right) const
|
||||
{
|
||||
return (Left < Right) ;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// IsGreater :
|
||||
// -----------
|
||||
Standard_Boolean PCollection_CompareOfReal::IsGreater (
|
||||
const Standard_Real &Left,const Standard_Real &Right) const
|
||||
{
|
||||
return (Left > Right) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
73
src/PCollection/PCollection_DepthFirstIterator.gxx
Executable file
73
src/PCollection/PCollection_DepthFirstIterator.gxx
Executable file
@@ -0,0 +1,73 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_DepthFirstIterator.gxx
|
||||
// Created: Wed May 29 17:42:50 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_DepthFirstIterator::
|
||||
PCollection_DepthFirstIterator(const Handle(PCollection_Vertex)& V)
|
||||
{
|
||||
Visited = new PCollection_SetOfVertex;
|
||||
Ready = new PCollection_StackOfVertex;
|
||||
Visited->Add(V);
|
||||
Ready->Push(V);
|
||||
HasMore = ! (Ready->IsEmpty());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_DepthFirstIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_DepthFirstIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
Handle(PCollection_Vertex) w1 = Ready->Top();
|
||||
Ready->Pop();
|
||||
PCollection_FrontEdgesIterator It(w1);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Vertex) w2 = It.Value()->Destination();
|
||||
if (! (Visited->Contains(w2))) {
|
||||
Ready->Push(w2);
|
||||
Visited->Add(w2);
|
||||
}
|
||||
It.Next();
|
||||
}
|
||||
HasMore = !(Ready->IsEmpty());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_DepthFirstIterator::Value () const
|
||||
{
|
||||
if (HasMore)
|
||||
return Ready->Top();
|
||||
else
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_DepthFirstIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
Ready->Nullify();
|
||||
Visited->Nullify();
|
||||
}
|
93
src/PCollection/PCollection_DoubleMapIterator.gxx
Executable file
93
src/PCollection/PCollection_DoubleMapIterator.gxx
Executable file
@@ -0,0 +1,93 @@
|
||||
//-Copyright: Matra Datavision 1992
|
||||
//-Version:
|
||||
|
||||
//-History:
|
||||
// Version Date Purpose
|
||||
// 07/01/93 Creation
|
||||
|
||||
//-Language C++2.0
|
||||
|
||||
//-Declarations
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
//=======================================================================
|
||||
// Function : DoubleMapIterator
|
||||
//=======================================================================
|
||||
|
||||
PCollection_DoubleMapIterator::PCollection_DoubleMapIterator
|
||||
( const Handle(PCollection_HDoubleMap) &aDoubleMap )
|
||||
{
|
||||
Standard_Boolean Found = Standard_False;
|
||||
|
||||
myBuckets = aDoubleMap->GetArrayKey();
|
||||
// Sets the index and the node on the first "no empty" entry
|
||||
if ( aDoubleMap->IsEmpty() ) myCurrentIndex = myBuckets->Length() + 1;
|
||||
else myCurrentIndex = 1;
|
||||
|
||||
while ( myCurrentIndex <= myBuckets->Length() && !Found ) {
|
||||
if ( ! myBuckets->Value(myCurrentIndex).IsNull() ) {
|
||||
myCurrentNode = myBuckets->Value(myCurrentIndex);
|
||||
Found = Standard_True;
|
||||
}
|
||||
else myCurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : More
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean PCollection_DoubleMapIterator::More() const
|
||||
{
|
||||
Standard_Boolean Ok = ( myCurrentIndex <= myBuckets->Length()) &&
|
||||
(! myCurrentNode.IsNull());
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Next
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_DoubleMapIterator::Next()
|
||||
{
|
||||
Standard_Boolean Found = Standard_False;
|
||||
Standard_Boolean HasMore = ( myCurrentIndex <= myBuckets->Length()) &&
|
||||
(! myCurrentNode.IsNull());
|
||||
|
||||
if ( !HasMore ) Standard_NoMoreObject::Raise();
|
||||
|
||||
myCurrentNode = myCurrentNode->NextKey();
|
||||
if ( myCurrentNode.IsNull() ) {
|
||||
myCurrentIndex++;
|
||||
while ( myCurrentIndex <= myBuckets->Length() && !Found ) {
|
||||
myCurrentNode = myBuckets->Value(myCurrentIndex);
|
||||
if ( myCurrentNode.IsNull() )
|
||||
myCurrentIndex++;
|
||||
else
|
||||
Found = Standard_True;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : KeyValue
|
||||
//=======================================================================
|
||||
|
||||
Key PCollection_DoubleMapIterator::KeyValue () const
|
||||
{
|
||||
if ( myCurrentNode.IsNull() ) Standard_NoSuchObject::Raise();
|
||||
return myCurrentNode->GetKey();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : ItemValue
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_DoubleMapIterator::ItemValue () const
|
||||
{
|
||||
if ( myCurrentNode.IsNull() ) Standard_NoSuchObject::Raise();
|
||||
return myCurrentNode->GetItem();
|
||||
}
|
83
src/PCollection/PCollection_DoubleMapNode.gxx
Executable file
83
src/PCollection/PCollection_DoubleMapNode.gxx
Executable file
@@ -0,0 +1,83 @@
|
||||
//-Copyright: Matra Datavision 1992
|
||||
//-Version:
|
||||
|
||||
//-History:
|
||||
// Version Date Purpose
|
||||
// 14/12/92 Creation
|
||||
|
||||
//-Language C++2.0
|
||||
|
||||
//=======================================================================
|
||||
// Function : DoubleMapNode
|
||||
//=======================================================================
|
||||
|
||||
PCollection_DoubleMapNode::PCollection_DoubleMapNode
|
||||
(
|
||||
const Key &aKey,
|
||||
const Item &anItem,
|
||||
const Handle(PCollection_DoubleMapNode) &nextKey,
|
||||
const Handle(PCollection_DoubleMapNode) &nextItem ) :
|
||||
|
||||
myKey(aKey), myItem(anItem), myNextKey(nextKey), myNextItem(nextItem)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetNextKey
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_DoubleMapNode::SetNextKey
|
||||
( const Handle(PCollection_DoubleMapNode) &aNode )
|
||||
{
|
||||
myNextKey = aNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetNextItem
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_DoubleMapNode::SetNextItem
|
||||
( const Handle(PCollection_DoubleMapNode) &aNode )
|
||||
{
|
||||
myNextItem = aNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : GetKey
|
||||
//=======================================================================
|
||||
|
||||
Key PCollection_DoubleMapNode::GetKey () const
|
||||
{
|
||||
return myKey;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : GetItem
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_DoubleMapNode::GetItem () const
|
||||
{
|
||||
return myItem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : NextKey
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_DoubleMapNode)
|
||||
PCollection_DoubleMapNode::NextKey() const
|
||||
{
|
||||
return myNextKey;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetNextItem
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_DoubleMapNode)
|
||||
PCollection_DoubleMapNode::NextItem() const
|
||||
{
|
||||
return myNextItem;
|
||||
}
|
||||
|
103
src/PCollection/PCollection_Edge.gxx
Executable file
103
src/PCollection/PCollection_Edge.gxx
Executable file
@@ -0,0 +1,103 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_Edge.gxx
|
||||
// Created: Thu May 30 10:40:42 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_Edge::
|
||||
PCollection_Edge(const Handle(PCollection_Vertex)& Source,
|
||||
const Handle(PCollection_Vertex)& Destination,
|
||||
const Attribute& Value)
|
||||
{
|
||||
MyAttribute = Value;
|
||||
MySource = Source;
|
||||
MyDestination = Destination;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetAttribute
|
||||
//---------------------------------------------------------------------------
|
||||
Attribute PCollection_Edge::GetAttribute () const
|
||||
{
|
||||
return MyAttribute;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetAttribute
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Edge::SetAttribute (const Attribute& Value)
|
||||
{
|
||||
MyAttribute = Value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Source
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_Edge::Source () const
|
||||
{
|
||||
return MySource;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Destination
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_Edge::Destination () const
|
||||
{
|
||||
return MyDestination;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetSource
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Edge::SetSource (const Handle(PCollection_Vertex)& V)
|
||||
{
|
||||
MySource = V;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetDestination
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Edge::SetDestination (const Handle(PCollection_Vertex)& V)
|
||||
{
|
||||
MyDestination = V;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Reverse
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Edge::Reverse ()
|
||||
{
|
||||
Handle(PCollection_Edge) me = this;
|
||||
MyDestination->RemoveBackEdge(me);
|
||||
MySource->RemoveFrontEdge(me);
|
||||
MyDestination->AddFrontEdge(me);
|
||||
MySource->AddBackEdge(me);
|
||||
Handle (PCollection_Vertex) temp = MyDestination;
|
||||
MyDestination = MySource;
|
||||
MySource = temp;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// IsLoop
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Edge::IsLoop () const
|
||||
{
|
||||
return (MyDestination == MySource);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
67
src/PCollection/PCollection_EdgesIterator.gxx
Executable file
67
src/PCollection/PCollection_EdgesIterator.gxx
Executable file
@@ -0,0 +1,67 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_EdgesIterator.gxx
|
||||
// Created: Wed May 29 17:43:20 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_EdgesIterator::PCollection_EdgesIterator
|
||||
(const Handle(PCollection_HDirectedGraph)& G):MyEdgeIterator(G->GetEdges())
|
||||
{
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_EdgesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_EdgesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
MyEdgeIterator.Next();
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Edge) PCollection_EdgesIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return MyEdgeIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_EdgesIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
65
src/PCollection/PCollection_FrontEdgesIterator.gxx
Executable file
65
src/PCollection/PCollection_FrontEdgesIterator.gxx
Executable file
@@ -0,0 +1,65 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_FrontEdgesIterator.cxx
|
||||
// Created: Wed May 29 17:42:37 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_FrontEdgesIterator::PCollection_FrontEdgesIterator
|
||||
(const Handle(PCollection_Vertex)& V):MyEdgeIterator(V->GetFrontEdges())
|
||||
{
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_FrontEdgesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_FrontEdgesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
MyEdgeIterator.Next();
|
||||
HasMore = MyEdgeIterator.More();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Edge) PCollection_FrontEdgesIterator::Value () const
|
||||
{
|
||||
if (HasMore) {
|
||||
return MyEdgeIterator.Value();
|
||||
}
|
||||
else {
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_FrontEdgesIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
393
src/PCollection/PCollection_HAVLSearchTree.cdl
Executable file
393
src/PCollection/PCollection_HAVLSearchTree.cdl
Executable file
@@ -0,0 +1,393 @@
|
||||
-- File: PCollection_HAVLSearchTree.cdl
|
||||
-- Created: Tue May 21 17:43:21 1991
|
||||
-- Author: Annick PANCHER
|
||||
-- <apc@topsn2>
|
||||
-- Revised: Mireille MERCIEN
|
||||
-- <jpt@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class HAVLSearchTree from PCollection (
|
||||
Item as Storable;
|
||||
Comparator as Compare from PCollection(Item))
|
||||
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: Defines a binary search tree, e.g. an ordered and
|
||||
-- balanced binary tree. An AVLSearchTree is created with a
|
||||
-- kind of Item and a Comparator. It's composed with Nodes.
|
||||
-- One item is contained only by one Node, and a 'count' stores
|
||||
-- the number of its occurences.
|
||||
-- The only public operations on an AVLSearchTree,
|
||||
-- except reading ( the number of its Nodes, its Root
|
||||
-- or the Node containing an item) are to insert or
|
||||
-- remove an item, plus, of course, to find an item.
|
||||
--
|
||||
-- Then, it's possible to ask to a Node its value,
|
||||
-- the number of occurences of this value, and its
|
||||
-- right and left children. Other methods of Node are
|
||||
-- private and called by the private methods of
|
||||
-- AVLSearchTree which manage the Find method, and
|
||||
-- Insert and Remove operations, always ensuring
|
||||
-- order and balance.
|
||||
-- 1. ORDER :
|
||||
-- If the tree contains three elements A,B,C, which
|
||||
-- are ordered, regarding to a comparator Comp, as
|
||||
-- following:
|
||||
-- A < B < C
|
||||
-- Then TheRoot of the tree will contain B, with A as
|
||||
-- LeftChild and C as RightChild.
|
||||
-- Each element on the left of a node A are 'lower'
|
||||
-- than A in respect with the used comparator, and
|
||||
-- each element on its right are greater.
|
||||
--
|
||||
-- 2. BALANCE : The height of two children of a Node
|
||||
-- will never have a difference of more than one
|
||||
-- level. An AVLSearch Tree is ALWAYS balanced.
|
||||
-- Keywords: binary tree, ordered, balanced
|
||||
-- Warning: To use an AVLSearchTree, since it's ordered and
|
||||
-- balanced each time an item is inserted or removed,
|
||||
-- may be a bad choice if there are more changing
|
||||
-- operations than searching requests, for
|
||||
-- performances criterias. It can be judicious to
|
||||
-- use it when there are many items to consult
|
||||
-- frequently.
|
||||
-- References: Classix, Reusable C++ Components( Empathy
|
||||
-- incorporated, 1990).
|
||||
-- Algorithms are attributed to :
|
||||
-- G.M.Adel'son-Vel'skii and E.M.Landis, 1962.
|
||||
|
||||
|
||||
uses Side from PCollection
|
||||
|
||||
|
||||
raises NoSuchObject from Standard,
|
||||
NoMoreObject from Standard
|
||||
|
||||
|
||||
|
||||
class AVLNode inherits PManaged
|
||||
uses Side from PCollection
|
||||
is
|
||||
|
||||
---Purpose: Private class. This class provides tools to manipulate
|
||||
-- an AVLSearchTree node.
|
||||
|
||||
Create( theItem: Item)
|
||||
returns mutable AVLNode ;
|
||||
|
||||
RightChild( me) returns mutable AVLNode;
|
||||
---Purpose: Reads the value of MyRightChild.
|
||||
|
||||
LeftChild( me) returns mutable AVLNode;
|
||||
---Purpose: Reads the value of MyLeftChild.
|
||||
|
||||
Value( me) returns any Item;
|
||||
---Purpose: Reads TheItem.
|
||||
|
||||
GetMultiplicity( me)
|
||||
---Purpose: Returns number of occurences of Item contained
|
||||
-- by <me>.
|
||||
returns Integer from Standard;
|
||||
|
||||
|
||||
SetRightChild( me:mutable; theNode: AVLNode);
|
||||
---Purpose: Modifies the value of MyRightChild.
|
||||
|
||||
SetLeftChild( me:mutable; theNode: AVLNode);
|
||||
---Purpose: Modifies the value of MyLeftChild.
|
||||
|
||||
SetChild ( me: mutable; theNode: AVLNode;
|
||||
theSide: Side from PCollection);
|
||||
---Purpose: Modifies the value of right or left child.
|
||||
|
||||
SetValue( me:mutable; theValue: Item);
|
||||
---Purpose: Modifies the value of TheItem.
|
||||
|
||||
SetMultiplicity( me:mutable; theCount: Integer from Standard);
|
||||
---Purpose: Modifies the value of Count.
|
||||
|
||||
Copy(me)
|
||||
returns mutable AVLNode
|
||||
is private;
|
||||
|
||||
-- REDEFINED
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Purpose: ShallowCopy redefinition.
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Purpose: ShallowDump redefinition.
|
||||
---C++: function call
|
||||
|
||||
|
||||
fields
|
||||
MyRightChild: AVLNode;
|
||||
MyLeftChild : AVLNode;
|
||||
MyItem : Item;
|
||||
Count : Integer from Standard;
|
||||
|
||||
friends class HAVLSearchTree from PCollection
|
||||
|
||||
end;
|
||||
|
||||
class AVLNodeStack instantiates HStack(AVLNode);
|
||||
|
||||
class AVLIterator
|
||||
|
||||
raises NoMoreObject from Standard, NoSuchObject from Standard
|
||||
is
|
||||
---Purpose: This class provides to iterate on an AVLSearchTree.
|
||||
-- The type of traversal is the in-order traversal.
|
||||
-- Example : If the AVLTree is the following:
|
||||
-- 5
|
||||
-- 2 7
|
||||
-- 1 3 6 8
|
||||
--
|
||||
-- The result is:
|
||||
-- 1 2 3 5 6 7 8
|
||||
--
|
||||
|
||||
Create( aTree: HAVLSearchTree)
|
||||
---Purpose: Creates an iterator on <aTree>.
|
||||
---Level: Public
|
||||
returns AVLIterator;
|
||||
|
||||
More( me)
|
||||
---Purpose: Returns True if there is still an element to be read.
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next( me: in out) raises NoMoreObject from Standard;
|
||||
---Purpose: Goes to next element of <me>.
|
||||
---Level: Public
|
||||
|
||||
Value( me)
|
||||
returns mutable AVLNode
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me: in out);
|
||||
---Purpose: Empties my structure, so that if next call on <me>,
|
||||
-- it will raise an exception NoMoreObject.
|
||||
---Level: Public
|
||||
|
||||
Append (me: in out; ANode:AVLNode)
|
||||
---Purpose: Adds Nodes to <CurrentStack> from <ANode>.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RecursiveAppend (me: in out; ANode:AVLNode)
|
||||
---Purpose: Called by Append to add <ANode> to
|
||||
-- <CurrentStack>, and goes down to left
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RecursiveRemove (me: in out; ANode:AVLNode)
|
||||
---Purpose: Called by Next to remove <ANode> and
|
||||
-- the Node which is before in CurrentStack.
|
||||
-- If <ANode> was its rightChild.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
CurrentNode : AVLNode;
|
||||
CurrentStack : AVLNodeStack;
|
||||
HasMore : Boolean;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
|
||||
Create( aComparator: Comparator)
|
||||
---Purpose: Creates an empty tree (root points to NULL).
|
||||
returns mutable HAVLSearchTree;
|
||||
|
||||
|
||||
IsEmpty( me)
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Extent( me)
|
||||
---Purpose: Returns number of different items contained by <me>
|
||||
---Level: Public
|
||||
returns Integer from Standard;
|
||||
|
||||
TotalExtent( me)
|
||||
---Purpose: Returns total number of items (considers account of each Node)
|
||||
---Level: Public
|
||||
returns Integer from Standard;
|
||||
|
||||
Find( me; theItem: Item)
|
||||
---Purpose: Returns the Node containing <theItem>.
|
||||
---Level: Public
|
||||
returns AVLNode;
|
||||
|
||||
GetRoot( me)
|
||||
returns AVLNode;
|
||||
---Level: Public
|
||||
|
||||
|
||||
Insert( me: mutable; theItem: Item);
|
||||
---Purpose: Inserts <theItem> at the right place; if it's
|
||||
-- already in <me>, only changes its <count>.
|
||||
-- Level: Public
|
||||
-- Example:
|
||||
-- Before
|
||||
-- me = ( i5( i3( i1)) -i7) and theItem = i2
|
||||
-- After
|
||||
-- me = ( i5( i2( i1 -i3)) -i7))
|
||||
-- ( i means LeftChild, -i means RightChild)
|
||||
|
||||
InsertOnce(me: mutable; theItem: Item)
|
||||
---Purpose: Inserts <theItem> at the right place, but only if
|
||||
-- it isn't already in <me>; returns False if already there.
|
||||
-- Level: Public
|
||||
-- Example:
|
||||
-- Before
|
||||
-- me = ( i5( i3( i1)) -i7) and theItem = i3
|
||||
-- After
|
||||
-- me = ( i5( i3( i1)) -i7) and return False
|
||||
returns Boolean from Standard;
|
||||
|
||||
Remove( me : mutable; theItem : Item)
|
||||
---Purpose: Removes from <me> the Node containing <theItem>,
|
||||
-- if its count=1, or reduces its count if count>1;
|
||||
-- in this aim, calls the recursive method
|
||||
-- RecursiveRemove, with <forAll>=False;
|
||||
-- Level: Public
|
||||
-- Example:
|
||||
-- Before
|
||||
-- me = ( i5( i3( i1)) -i7) and theItem = i7
|
||||
-- After
|
||||
-- me = ( i3( i1 -i5)) if count(i7)=1
|
||||
-- Or
|
||||
-- me = ( i5( i3( i1)) -i7) if count(i7)>1
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
RemoveAll( me: mutable; theItem: Item)
|
||||
---Purpose: Removes from <me> the Node containing <theItem>;
|
||||
-- in this aim, calls the recursive method
|
||||
-- RecursiveRemove, with <forAll>=True;
|
||||
-- Level: Public
|
||||
-- Example
|
||||
-- Before
|
||||
-- me = ( i5( i3( i1)) -i7) and theItem = i7
|
||||
-- After
|
||||
-- me = ( i3( i1 -i5))
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Merge (me; another:HAVLSearchTree)
|
||||
---Purpose: Creates a third one from <me> and <another>.
|
||||
---Level: Public
|
||||
returns mutable HAVLSearchTree;
|
||||
|
||||
Copy(me)
|
||||
returns mutable HAVLSearchTree
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
SetRoot( me: mutable; theNode: mutable AVLNode)
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RotateLeft( me; theNode : in out mutable AVLNode)
|
||||
---Purpose: right child A of <theNode> becomes the parent, and
|
||||
-- <theNode> becomes its left child; left child of A
|
||||
-- becomes the right child of <theNode>. This
|
||||
-- rotation will permit to balance <me> after a
|
||||
-- pertubating action ( insert or remove) on it.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RotateRight( me; theNode : in out mutable AVLNode)
|
||||
---Purpose: left child A of <theNode> becomes the parent, and
|
||||
-- <theNode> becomes its right child; right child of
|
||||
-- A becomes the left child of <theNode>. This
|
||||
-- rotation will permit to balance <me> after a
|
||||
-- pertubating action ( insert or remove) on it.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
LeftBalance( me; theNode : in out mutable AVLNode)
|
||||
---Purpose: Called after inserting or removing an item, if the
|
||||
-- left branch of <theNode> is too long
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RightBalance( me; theNode : in out mutable AVLNode)
|
||||
---Purpose: Called after inserting or removing an item, if the
|
||||
-- right branch of <theNode> is too long.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
InsertBalance( me; theNode : in out mutable AVLNode;
|
||||
theFather: mutable AVLNode;
|
||||
theSide : Side from PCollection)
|
||||
---Purpose: Balances <me> after inserting an item.
|
||||
returns Boolean from Standard
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RemoveBalance( me; theNode : in out mutable AVLNode;
|
||||
theFather: mutable AVLNode;
|
||||
theSide : Side from PCollection)
|
||||
---Purpose: Balances <me> after inserting an item.
|
||||
---Level: Internal
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
RecursiveInsert( me; theNode : in out mutable AVLNode;
|
||||
theFather: mutable AVLNode;
|
||||
theSide : Side from PCollection;
|
||||
theItem : Item;
|
||||
forOnce : in out Boolean from Standard)
|
||||
---Purpose: Recursive method to insert a new Node OR to find
|
||||
-- the existing one containing <theItem> and increase its count.
|
||||
-- Returns True when a new Node has been created to
|
||||
-- know it needs to be balanced, and then returns
|
||||
-- False again.
|
||||
---Level: Internal
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
RecursiveRemove( me; theNode : in out mutable AVLNode;
|
||||
theFather: mutable AVLNode;
|
||||
theSide : Side from PCollection;
|
||||
theItem : Item;
|
||||
forAll : Boolean from Standard)
|
||||
---Purpose: Recursive method to find the Node containing
|
||||
-- <theItem>. In case it's <theNode>, removes it if
|
||||
-- <forAll> is True, or reduces its count if <forAll> is False.
|
||||
-- Returns True when theItem has been found
|
||||
---Level: Internal
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
fields
|
||||
|
||||
TheRoot : AVLNode;
|
||||
TheComparator : Comparator;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
445
src/PCollection/PCollection_HAVLSearchTree.gxx
Executable file
445
src/PCollection/PCollection_HAVLSearchTree.gxx
Executable file
@@ -0,0 +1,445 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_HAVLSearchTree.gxx
|
||||
// Created: Thu May 23 16:57:42 1991
|
||||
// Author: Annick PANCHER
|
||||
// <apc>
|
||||
// Revised by: Jean-Pierre TIRAULT,Mireille MERCIEN
|
||||
// May,14 1992
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <PCollection_Side.hxx>
|
||||
typedef PCollection_Side Side;
|
||||
typedef PCollection_AVLNode Node;
|
||||
typedef Handle(PCollection_AVLNode) Handle(Node);
|
||||
typedef PCollection_HAVLSearchTree Tree;
|
||||
typedef Handle(PCollection_HAVLSearchTree) Handle(Tree);
|
||||
typedef PCollection_AVLIterator AVLIterator;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Internal function Height : returns the height of an AVLtree
|
||||
//-----------------------------------------------------------------------------
|
||||
static Integer Height(const Handle(Node)& ANode)
|
||||
{
|
||||
// ... Length of the longest child
|
||||
if(ANode.IsNull()) return 0;
|
||||
return (1 + Max( Height(ANode->LeftChild()),
|
||||
Height(ANode->RightChild()) ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Create : creates an empty AVLSearchTree
|
||||
//-----------------------------------------------------------------------------
|
||||
PCollection_HAVLSearchTree::
|
||||
PCollection_HAVLSearchTree(const Comparator& AComparator)
|
||||
{
|
||||
TheComparator = AComparator;
|
||||
Handle(Node) NullNode;
|
||||
NullNode.Nullify();
|
||||
TheRoot = NullNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsEmpty : Is the current tree empty ?
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_HAVLSearchTree::IsEmpty () const
|
||||
{
|
||||
return (TheRoot.IsNull());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GetRoot : Returns the root of the current tree
|
||||
//-----------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_HAVLSearchTree::GetRoot () const
|
||||
{
|
||||
return TheRoot;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SetRoot : Replaces the root of the current tree
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::SetRoot(const Handle(Node)& ANode)
|
||||
{
|
||||
TheRoot = ANode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Extent : Number of different items in the current tree
|
||||
//-----------------------------------------------------------------------------
|
||||
// ... Management tools to have the number of nodes from a given one
|
||||
static Integer RecursiveExtent(const Handle(Node)& ANode)
|
||||
{
|
||||
if (ANode.IsNull()) return 0;
|
||||
return (1 + RecursiveExtent(ANode->LeftChild())
|
||||
+ RecursiveExtent(ANode->RightChild()) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Integer PCollection_HAVLSearchTree::Extent () const
|
||||
{
|
||||
return RecursiveExtent(TheRoot);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Extent : Number of different items in the current tree according to
|
||||
// the multiplicity
|
||||
//-----------------------------------------------------------------------------
|
||||
// ... Management tools to have the number of nodes from a given one
|
||||
static Integer RecursiveTotalExtent(const Handle(Node)& ANode)
|
||||
{
|
||||
if ( ANode.IsNull()) return 0;
|
||||
return ( RecursiveTotalExtent(ANode->LeftChild()) +
|
||||
RecursiveTotalExtent(ANode->RightChild()) +
|
||||
ANode->GetMultiplicity() );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Integer PCollection_HAVLSearchTree::TotalExtent () const
|
||||
{
|
||||
return RecursiveTotalExtent(TheRoot);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find : Find the node containing an item
|
||||
//-----------------------------------------------------------------------------
|
||||
// ... Management tools
|
||||
static Handle(Node) RecursiveFind( const Comparator& Comp,
|
||||
const Handle(Node)& SubRoot,
|
||||
const Item& TheItem)
|
||||
{
|
||||
if ( SubRoot.IsNull() ) return SubRoot;
|
||||
if ( Comp.IsLower(TheItem, SubRoot->Value()) ) {
|
||||
return RecursiveFind(Comp, SubRoot->LeftChild(), TheItem);
|
||||
}
|
||||
if (Comp.IsGreater(TheItem, SubRoot->Value()) ) {
|
||||
return RecursiveFind(Comp, SubRoot->RightChild(), TheItem);
|
||||
}
|
||||
return SubRoot;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Handle(Node) PCollection_HAVLSearchTree::Find(const Item& TheItem) const
|
||||
{
|
||||
return RecursiveFind(TheComparator, TheRoot, TheItem);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// RotateRight
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::RotateRight(Handle(Node)& TheNode) const
|
||||
{
|
||||
// the left child becomes the parent...
|
||||
Handle(Node) Temp = TheNode->LeftChild();
|
||||
TheNode->SetLeftChild(Temp->RightChild());
|
||||
Temp->SetRightChild(TheNode);
|
||||
TheNode = Temp;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RotateLeft
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::
|
||||
RotateLeft(Handle(Node)& TheNode) const
|
||||
{
|
||||
// the right child becomes the parent...
|
||||
Handle(Node) Temp = TheNode->RightChild();
|
||||
TheNode->SetRightChild(Temp->LeftChild());
|
||||
Temp->SetLeftChild(TheNode);
|
||||
TheNode = Temp;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// LeftBalance
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::LeftBalance(Handle(Node)& Root) const
|
||||
{
|
||||
Handle(Node) TheNode = Root->LeftChild();
|
||||
if( Height(TheNode->LeftChild()) >= Height(TheNode->RightChild()) ) {
|
||||
RotateRight(Root);
|
||||
return;
|
||||
}
|
||||
RotateLeft(TheNode);
|
||||
Root->SetLeftChild(TheNode);
|
||||
RotateRight(Root);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// RightBalance
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::RightBalance(Handle(Node)& Root) const
|
||||
{
|
||||
Handle(Node) TheNode = Root->RightChild();
|
||||
if( Height(TheNode->RightChild()) >= Height(TheNode->LeftChild())) {
|
||||
RotateLeft(Root);
|
||||
return;
|
||||
}
|
||||
RotateRight(TheNode);
|
||||
Root->SetRightChild(TheNode);
|
||||
RotateLeft(Root);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// InsertBalance
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_HAVLSearchTree::InsertBalance(Handle(Node)& Child,
|
||||
const Handle(Node)& Father,
|
||||
const Side theSide) const
|
||||
{
|
||||
// Balance after insertion
|
||||
switch (Height(Child->LeftChild()) - Height(Child->RightChild())) {
|
||||
case 2 : LeftBalance(Child);
|
||||
if (!Father.IsNull()) Father->SetChild(Child, theSide);
|
||||
return False;
|
||||
case -2 : RightBalance(Child);
|
||||
if (!Father.IsNull()) Father->SetChild(Child, theSide);
|
||||
return False;
|
||||
case 0 : return False;
|
||||
default : return True;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// RemoveBalance
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_HAVLSearchTree::
|
||||
RemoveBalance(Handle(Node)& Child,
|
||||
const Handle(Node)& Father,
|
||||
const Side theSide) const
|
||||
{
|
||||
// Balance after Remove
|
||||
switch (Height(Child->LeftChild()) - Height(Child->RightChild())) {
|
||||
case 2 : LeftBalance(Child);
|
||||
if (!Father.IsNull()) Father->SetChild(Child, theSide);
|
||||
return True;
|
||||
case -2 : RightBalance(Child);
|
||||
if (!Father.IsNull()) Father->SetChild(Child, theSide);
|
||||
return True;
|
||||
default : return True;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// RecursiveInsert
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_HAVLSearchTree::
|
||||
RecursiveInsert(Handle(Node)& Child,
|
||||
const Handle(Node)& Father,
|
||||
const Side theSide,
|
||||
const Item& theItem,
|
||||
Boolean& forOnce) const
|
||||
{
|
||||
// FINDS WHERE TO INSERT theItem AND DOES IT
|
||||
Handle(Node) Temp;
|
||||
Boolean Result = False;
|
||||
Integer Number;
|
||||
if(TheComparator.IsLower(theItem, Child->Value())) {
|
||||
Temp = Child->LeftChild();
|
||||
if (Temp.IsNull()) {
|
||||
Child->SetLeftChild( new Node(theItem));
|
||||
return True;
|
||||
}
|
||||
Result = RecursiveInsert( Temp, Child, PCollection_Left,
|
||||
theItem, forOnce);
|
||||
if(Result) return InsertBalance(Child, Father, theSide) ;
|
||||
else return False;
|
||||
}
|
||||
else if (TheComparator.IsGreater(theItem, Child->Value())) {
|
||||
Temp = Child->RightChild();
|
||||
if (Temp.IsNull()) {
|
||||
Child->SetRightChild( new Node(theItem));
|
||||
return True;
|
||||
}
|
||||
Result = RecursiveInsert( Temp, Child, PCollection_Right,
|
||||
theItem, forOnce);
|
||||
if(Result) return InsertBalance(Child, Father, theSide);
|
||||
else return False;
|
||||
}
|
||||
else {
|
||||
// ITEM FOUND // SET MULTIPLICITY
|
||||
if (forOnce) {
|
||||
forOnce = False;
|
||||
}
|
||||
else {
|
||||
Number = Child->GetMultiplicity();
|
||||
Child->SetMultiplicity(++Number);
|
||||
}
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RecursiveRemove
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Boolean PCollection_HAVLSearchTree::RecursiveRemove(
|
||||
Handle(Node)& Child,
|
||||
const Handle(Node)& Father,
|
||||
const Side theSide,
|
||||
const Item& TheItem,
|
||||
const Boolean ForAll) const
|
||||
{
|
||||
|
||||
Boolean Result;
|
||||
Integer Number;
|
||||
// ITEM NOT FOUND
|
||||
if (Child.IsNull()) NoSuchObject::Raise();
|
||||
Handle(Node) TheLeft = Child->LeftChild();
|
||||
Handle(Node) TheRight = Child->RightChild();
|
||||
if (TheComparator.IsLower(TheItem, Child->Value())) {
|
||||
Result = RecursiveRemove( TheLeft, Child,
|
||||
PCollection_Left,
|
||||
TheItem, ForAll);
|
||||
}
|
||||
|
||||
else if (TheComparator.IsGreater(TheItem, Child->Value())) {
|
||||
Result = RecursiveRemove( TheRight, Child,
|
||||
PCollection_Right,
|
||||
TheItem, ForAll);
|
||||
}
|
||||
else {
|
||||
// theItem IS FOUND
|
||||
Number = Child->GetMultiplicity();
|
||||
Child->SetMultiplicity(--Number);
|
||||
// SOMETIMES IT'S NOT NECESSARY REMOVING theItem
|
||||
if (!ForAll && Number > 0) return True;
|
||||
// IF IT IS, LOOKING FOR THE NEW VALUE OF Child
|
||||
if (! TheLeft.IsNull() && ! TheRight.IsNull()) {
|
||||
// Child HAS TWO CHILDREN
|
||||
Handle(Node) T;
|
||||
Handle(Node) Temp = TheRight;
|
||||
while (! Temp.IsNull()) {
|
||||
T = Temp;
|
||||
Temp = Temp->LeftChild();
|
||||
}
|
||||
// WE HAVE FOUND THE GOOD NODE
|
||||
Child->SetValue(T->Value());
|
||||
Child->SetMultiplicity(T->GetMultiplicity());
|
||||
|
||||
|
||||
const Item anItem = Child->Value();
|
||||
|
||||
Result = RecursiveRemove( TheRight, Child, PCollection_Right,
|
||||
//JPT/RBA on sait pas pourquoi ? Child->Value(), ForAll);
|
||||
anItem, ForAll);
|
||||
}
|
||||
else {
|
||||
// ONLY ONE CHILD, SO IT'S THE GOOD ONE
|
||||
// Mip-12-janv-93 : integration de la gestion memoire
|
||||
// if (TheLeft.IsNull())
|
||||
// Child = TheRight;
|
||||
// else
|
||||
// Child = TheLeft;
|
||||
Child.Delete();
|
||||
if (TheLeft.IsNull()) {
|
||||
Child = TheRight;
|
||||
}
|
||||
else {
|
||||
Child = TheLeft;
|
||||
}
|
||||
Father->SetChild(Child, theSide);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
if (Result) return RemoveBalance(Child, Father, theSide);
|
||||
return False; // Child has not been found for now
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Insert
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::Insert (const Item& theItem)
|
||||
{
|
||||
if (TheRoot.IsNull()) {
|
||||
TheRoot = new Node(theItem);
|
||||
return;
|
||||
}
|
||||
Handle(Node) Bid;
|
||||
Boolean forOnce = False;
|
||||
RecursiveInsert( TheRoot, Bid, PCollection_Left, theItem, forOnce);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// InsertOnce
|
||||
//-----------------------------------------------------------------------------
|
||||
Boolean PCollection_HAVLSearchTree::InsertOnce (const Item& theItem)
|
||||
{
|
||||
if (TheRoot.IsNull()) {
|
||||
TheRoot = new Node(theItem);
|
||||
return True;
|
||||
}
|
||||
Handle(Node) Bid;
|
||||
Boolean forOnce = True;
|
||||
RecursiveInsert( TheRoot, Bid, PCollection_Left, theItem, forOnce);
|
||||
return forOnce;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Remove
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::Remove (const Item& theItem)
|
||||
{
|
||||
Handle(Node) Bid;
|
||||
RecursiveRemove( TheRoot, Bid, PCollection_Left, theItem, False);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// RemoveAll
|
||||
//-----------------------------------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::RemoveAll (const Item& theItem)
|
||||
{
|
||||
Handle(Node) Bid;
|
||||
RecursiveRemove( TheRoot, Bid, PCollection_Left, theItem, True);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Copy
|
||||
//-----------------------------------------------------------------------------
|
||||
Handle(Tree) PCollection_HAVLSearchTree::Copy() const
|
||||
{
|
||||
Handle(Tree) aTree = new Tree(TheComparator);
|
||||
aTree->SetRoot(TheRoot->Copy());
|
||||
return aTree;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Merge
|
||||
//-----------------------------------------------------------------------------
|
||||
Handle(Tree) PCollection_HAVLSearchTree::Merge(const Handle(Tree)& aTree) const
|
||||
{
|
||||
Item theItem;
|
||||
AVLIterator Iter( aTree);
|
||||
Handle(Tree) newTree = Copy();
|
||||
while( Iter.More()) {
|
||||
theItem = Iter.Value()->Value();
|
||||
newTree->Insert(theItem);
|
||||
Iter.Next();
|
||||
}
|
||||
return newTree;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------
|
||||
//
|
||||
// These methods must be implemented
|
||||
//
|
||||
// ----------------------------------------------------------
|
||||
|
||||
Handle(Standard_Persistent) PCollection_HAVLSearchTree::ShallowCopy() const
|
||||
{
|
||||
|
||||
cout << "HAVLSearchTree::ShallowCopy Not yet implemented" << endl;
|
||||
return This();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
//
|
||||
// ShallowDump
|
||||
// ----------------------------------------------------
|
||||
void PCollection_HAVLSearchTree::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
cout << "HAVLSearchTree::ShallowDump Not yet implemented" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
458
src/PCollection/PCollection_HArbitraryTree.cdl
Executable file
458
src/PCollection/PCollection_HArbitraryTree.cdl
Executable file
@@ -0,0 +1,458 @@
|
||||
-- File: HArbitraryTree.cdl
|
||||
-- Created: Thu Jun 20 14:45:39 1991
|
||||
-- Author: Annick PANCHER
|
||||
-- <apc@topsn2>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
-- Revised: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class HArbitraryTree from PCollection (
|
||||
Item as Storable)
|
||||
|
||||
|
||||
---Purpose: Description of a tree with an arbitrary number of
|
||||
-- children at each level. Each 'node' is an
|
||||
-- ArbitraryTree which knows its parent and its children.
|
||||
-- An ArbitraryTree can't contain an empty child. To
|
||||
-- separate a part B from an ArbitraryTree A, it's
|
||||
-- possible to swap B with a Null tree: the parent A will
|
||||
-- remove its child B, which is returned.
|
||||
--
|
||||
-- There are three iterators known for an ArbitraryTree(
|
||||
-- PreOrder, PostOrder and InOrder). Each of them
|
||||
-- manages a stack whose depth is always less or equal to
|
||||
-- the tree's height, and which describes the way from
|
||||
-- the root to the current tree.
|
||||
-- Warning: It could be a bad choice to use an ArbitraryTree for
|
||||
-- a great number of items if it's frequently necessary
|
||||
-- to search them, for there is no optimisation to find
|
||||
-- an item in an unordered tree.
|
||||
-- The same item can be stored several times in several places.
|
||||
|
||||
inherits Persistent
|
||||
raises IsNotRoot ,
|
||||
IsNullTree ,
|
||||
IsContained ,
|
||||
NoMoreObject from Standard,
|
||||
NoSuchObject from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
|
||||
class SeqArbitraryTree instantiates
|
||||
HSequence from PCollection(HArbitraryTree);
|
||||
class StackArbitraryTree instantiates
|
||||
HStack from PCollection(HArbitraryTree);
|
||||
|
||||
class ATPreOrderIterator
|
||||
|
||||
---Purpose: Permits to iterate through an ArbitraryTree so that,
|
||||
-- from the root, it reads each element on the left,
|
||||
-- until the first leave, then goes to its rightSibling
|
||||
-- and upward.
|
||||
-- IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
-- THEN it will read ( A B C D E F G H I J K)
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create( theTree : HArbitraryTree)
|
||||
---Purpose: Creates an iterator on <theTree>.
|
||||
returns ATPreOrderIterator;
|
||||
|
||||
More( me)
|
||||
---Purpose: Returns True if there is at least one element to be read.
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next( me : in out) raises NoMoreObject from Standard;
|
||||
---Purpose: Manages currentStack which always contains
|
||||
-- the way from the root to the next leaf to be
|
||||
-- visited. Updates currentTree.
|
||||
---Level: Public
|
||||
|
||||
Value( me )
|
||||
---Purpose: Returns the current element.
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear( me : in out);
|
||||
---Purpose: Empties <me>, so that More() will answer False.
|
||||
---Level: Public
|
||||
|
||||
|
||||
|
||||
RecursiveRemove( me : in out; aTree : HArbitraryTree)
|
||||
---Purpose: Removes the end of currentStack until finding a
|
||||
-- tree having a right sibling: removes it too, and returns it.
|
||||
returns mutable HArbitraryTree
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
HasMore : Boolean from Standard;
|
||||
CurrentTree : HArbitraryTree;
|
||||
CurrentStack: StackArbitraryTree;
|
||||
end;
|
||||
|
||||
|
||||
class ATPostOrderIterator
|
||||
|
||||
---Purpose: Permits to iterate through an ArbitraryTree beginning by
|
||||
-- the most left leave and its rightSibling, then upward to its parent.
|
||||
-- IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
-- THEN it will read ( C D E B F I J K H G A)
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create( theTree : HArbitraryTree)
|
||||
---Purpose: Creates an iterator on the tree theTree
|
||||
returns ATPostOrderIterator;
|
||||
|
||||
More( me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if there is at least one element to
|
||||
-- be read.
|
||||
---Level: Public
|
||||
|
||||
Next( me : in out) raises NoMoreObject from Standard;
|
||||
---Purpose: Sets the iterator on the next element
|
||||
---Level: Public
|
||||
|
||||
Value( me)
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear( me : in out);
|
||||
---Purpose: Empties <me>, so that More() will answer False
|
||||
---Level: Public
|
||||
|
||||
RecursiveAppend( me : in out; aTree : HArbitraryTree)
|
||||
---Purpose: adds a new branch to currentStack, until
|
||||
-- reaching a leaf; the branch's parent is <aTree>
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
HasMore : Boolean from Standard;
|
||||
CurrentTree : HArbitraryTree;
|
||||
CurrentStack: StackArbitraryTree;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
class ATInOrderIterator
|
||||
|
||||
---Purpose: Permits to iterate through an ArbitraryTree so that, from
|
||||
-- the most left leave, it reads it, then its parent, then in
|
||||
-- the same order what is on its right.
|
||||
-- IF theTree is ( A (B (C D E)) F G (H (I J K)))
|
||||
-- THEN it will read ( C B D E A F I H J K G)
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create( theTree : HArbitraryTree)
|
||||
---Purpose: Create an iterator on the tree theTree
|
||||
returns ATInOrderIterator;
|
||||
|
||||
More( me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if there is at least one element to be read.
|
||||
---Level: Public
|
||||
|
||||
Next( me : in out) raises NoMoreObject from Standard;
|
||||
---Purpose: Sets the iterator to the next element.
|
||||
---Level: Public
|
||||
|
||||
Value( me)
|
||||
returns mutable HArbitraryTree
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
Clear( me : in out);
|
||||
---Purpose: Empties <me>, so that More() will answer False.
|
||||
---Level: Public
|
||||
|
||||
RecursiveAppend( me : in out; aTree : HArbitraryTree)
|
||||
---Purpose: Adds to currentStack a new branch of the tree,
|
||||
-- which has not been visited; this branch's parent is <aTree>.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
RecursiveRemove( me : in out; aTree : HArbitraryTree)
|
||||
---Purpose: Removes from currentStack one or more trees,
|
||||
-- which have already been visited and have no
|
||||
-- more children not visited; the first tree
|
||||
-- removed is <aTree>.
|
||||
---Level: Internal
|
||||
returns mutable HArbitraryTree
|
||||
is private;
|
||||
|
||||
fields
|
||||
HasMore : Boolean from Standard;
|
||||
CurrentTree : HArbitraryTree;
|
||||
CurrentStack: StackArbitraryTree;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create ( TheItem : Item)
|
||||
---Purpose: Creation of a root tree of value Item with no child(e.g. a leaf)
|
||||
-- Example:
|
||||
-- if <TheItem> = i0
|
||||
-- returns
|
||||
-- ( i0 )
|
||||
-- The field <MyParent> is Null and so is <MyChildren>.
|
||||
returns mutable HArbitraryTree;
|
||||
|
||||
Children( me)
|
||||
---Purpose: Reads all children of <me>, to be able to know the
|
||||
-- location of one of them.
|
||||
---Level: Internal
|
||||
returns mutable SeqArbitraryTree
|
||||
is private;
|
||||
|
||||
Child( me; Index : Integer from Standard)
|
||||
---Purpose: Returns the child of <me> at the range <Index>.
|
||||
-- Raises an exception if <Index> is out of range.
|
||||
-- Example:Before
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ), Index = 2
|
||||
-- After
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
-- returns (i2)
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
Value( me) returns any Item;
|
||||
---Purpose: Returns the value of <me>.
|
||||
-- Example:Before and After
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
-- returns i0
|
||||
---Level: Public
|
||||
|
||||
NbChildren( me) returns Integer from Standard;
|
||||
---Purpose: Returns the number of children of me.
|
||||
-- Example: me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
-- returns 3
|
||||
---Level: Public
|
||||
|
||||
IsLeaf( me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if the tree <me> is a leaf.
|
||||
-- Example: me = ( i0 )
|
||||
-- returns True
|
||||
---Level: Public
|
||||
|
||||
Parent( me)
|
||||
---Purpose: Returns the father of <me>.
|
||||
-- The returned ArbitraryTree can be Null.
|
||||
-- Example: if T = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ) and
|
||||
-- me = ( i1 (i4 i5) )
|
||||
-- returns T.
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree;
|
||||
|
||||
IsRoot( me)
|
||||
---Purpose: Returns True if <me> has no father.
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Root( me)
|
||||
---Purpose: Returns the root of the tree <me>.
|
||||
-- If <me> is a root, returns <me>
|
||||
-- Example: if T = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ) and
|
||||
-- me = (i1( i4 i5 )) and T->IsRoot == True
|
||||
-- returns T
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree ;
|
||||
|
||||
LeftSibling( me)
|
||||
---Purpose: Returns the left neighbour of the tree <me>.
|
||||
-- May return a Null tree.
|
||||
-- if T = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
-- and me = (i2)
|
||||
-- returns ( i1 (i4 i5) )
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree;
|
||||
|
||||
RightSibling( me)
|
||||
---Purpose: Returns the right neighbour of the tree <me>.
|
||||
-- May return a Null tree.
|
||||
-- Example: if T = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
-- and me = (i2)
|
||||
-- returns ( i3 (i6 i7) )
|
||||
---Level: Public
|
||||
returns mutable HArbitraryTree;
|
||||
|
||||
Contains( me; aTree: HArbitraryTree)
|
||||
---Purpose: Checks <aTree> is contained by <me>.
|
||||
---Level: Public
|
||||
returns Boolean from Standard
|
||||
raises IsNullTree ;
|
||||
|
||||
SetValue( me : mutable ; theItem : Item) ;
|
||||
---Purpose: Changes the value of MyItem.
|
||||
-- Example: before
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ), theItem= i10
|
||||
-- after
|
||||
-- me = ( i10 (i1 (i4 i5) i2 i3 (i6 i7) ) )
|
||||
---Level: Public
|
||||
|
||||
SwapChild( me : mutable ; Index : Integer from Standard;
|
||||
WithTree : in out mutable HArbitraryTree)
|
||||
---Purpose: Replaces the child of <me> at range <Index> by <WithTree>
|
||||
-- and conversely.
|
||||
-- Only removes Child at range <Index> if <WithTree> is Null.
|
||||
-- Trigger: Raises an exception if <Index> is greater than NbChildren;
|
||||
-- raises IsNotRoot if <WithTree> is not a root;
|
||||
-- Example: Before
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ),
|
||||
-- Index = 2, WithTree = ( i8 (i9 i10) )
|
||||
-- After
|
||||
-- me = ( i0 (i1 (i4 i5) i8 (i9 i10) i3 (i6 i7) ) )
|
||||
-- WithTree = (i2)
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard,
|
||||
IsNotRoot;
|
||||
|
||||
SwapChildren( me : mutable ; subtree1, subtree2 : mutable HArbitraryTree)
|
||||
---Purpose: TradeOff between two subtrees of <me>.
|
||||
-- Example: Before
|
||||
-- me = ( i0 (i1 (i4 i5) i2 i3 (i6 i7) ) ),
|
||||
-- subtree1 = (i4), subtree2 = (i3 (i6 i7)),
|
||||
-- After
|
||||
-- me = ( i0 (i1 ( i3 (i6 i7) i5) i2 i4))
|
||||
-- Trigger:Raises an exception if <subtree1> or <subtree2>
|
||||
-- are not subtrees of <me>.
|
||||
-- Raises an exception if one of the two subtrees is
|
||||
-- contained by the other one.For instance :
|
||||
-- Example: IF subtree1 = (i3( i6 i7)) and subtree2 = (i6).
|
||||
-- Raises an exception if one of the two subtrees is null.
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard,
|
||||
NoSuchObject from Standard,
|
||||
IsContained,
|
||||
IsNullTree;
|
||||
|
||||
AppendChild( me: mutable; theTree: HArbitraryTree)
|
||||
---Purpose: Appends <theTree> as last child of <me>
|
||||
-- Example:
|
||||
-- Before
|
||||
-- me = ( i0 ( i1 i2 i3))
|
||||
-- theTree = ( i4)
|
||||
-- After
|
||||
-- me = ( i0 ( i1 i2 i3 i4))
|
||||
-- Trigger: Raises IsNotRoot if <theTree> is not a root.
|
||||
-- Raises IsNullTree if <theTree> is Null.
|
||||
---Level: Public
|
||||
raises IsNotRoot,
|
||||
IsNullTree;
|
||||
|
||||
PrependChild( me: mutable; theTree: HArbitraryTree)
|
||||
---Purpose: Appends <theTree> as first child of <me>.
|
||||
-- Example:
|
||||
-- Before
|
||||
-- me = ( i0 ( i1 i2 i3))
|
||||
-- theTree = ( i4)
|
||||
-- After
|
||||
-- me = ( i0 ( i4 i1 i2 i3))
|
||||
-- Trigger: Raises IsNotRoot if <theTree> is not a root.
|
||||
-- Raises IsNullTree if <theTree> is Null.
|
||||
---Level: Public
|
||||
raises IsNotRoot,
|
||||
IsNullTree;
|
||||
|
||||
InsertChildBefore( me : mutable; Index : Integer from Standard;
|
||||
theTree: HArbitraryTree)
|
||||
---Purpose: Adds <theTree> to the field <MyChildren>, at
|
||||
-- <Index>, and all children from <Index> pushed on
|
||||
-- the right.
|
||||
-- Example: Before
|
||||
-- me = ( i0 ( i1 i2 i3))
|
||||
-- theTree = ( i4), Index = 2
|
||||
-- After
|
||||
-- me = ( i0 ( i1 i4 i2 i3))
|
||||
-- Trigger: Raises OutOfRange if <Index> is greater than
|
||||
-- NbChildren.
|
||||
-- Raises IsNotRoot if <theTree> is not a root.
|
||||
-- Raises IsNullTree if <theTree> is Null.
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard,
|
||||
IsNotRoot,
|
||||
IsNullTree;
|
||||
|
||||
InsertChildAfter( me: mutable; Index: Integer from Standard;
|
||||
theTree: HArbitraryTree)
|
||||
---Purpose: Adds <theTree> to <MyChildren>, at <Index>+1, and
|
||||
-- all children from <Index>+1 pushed on the right.
|
||||
-- Example: Before
|
||||
-- me = ( i0 ( i1 i2 i3))
|
||||
-- theTree = ( i4), Index = 2
|
||||
-- After
|
||||
-- me = ( i0 ( i1 i2 i4 i3))
|
||||
-- Trigger: Raises OutOfRange if <Index> is greater than NbChildren
|
||||
-- Raises IsNotRoot if <theTree> is not a root
|
||||
-- Raises IsNullTree if <theTree> is Null
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard,
|
||||
IsNotRoot,
|
||||
IsNullTree;
|
||||
|
||||
RemoveChild( me : mutable; Index: Integer from Standard)
|
||||
---Purpose: Removes from <MyChildren> the ArbitraryTree at range <Index>.
|
||||
-- Example: Before
|
||||
-- me = ( i0 ( i1 i2 i3 i4)) and Index = 2
|
||||
-- After
|
||||
-- me = ( i0 ( i1 i3 i4))
|
||||
-- Trigger: Raises OutOfRange if <Index> is greater than NbChildren
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
RemoveAllChildren( me: mutable);
|
||||
---Purpose: Removes all my children.
|
||||
---Level: Public
|
||||
|
||||
RemoveChildren( me: mutable; FromIndex, ToIndex : Integer from Standard)
|
||||
---Purpose: Removes from <MyChildren> all the ArbitraryTree
|
||||
-- located from range <FromIndex> to <ToIndex>.
|
||||
-- Example: Before
|
||||
-- me = ( i0 ( i1 i2 i3 i4))
|
||||
-- FromIndex = 2 and ToIndex = 4
|
||||
-- After
|
||||
-- me = ( i0 ( i1))
|
||||
-- Trigger: Raises OutOfRange if <FromIndex> or <ToIndex> is
|
||||
-- greater than NbChildren.
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
SetParent( me : mutable; theTree : HArbitraryTree)
|
||||
---Purpose: Changes the value of MyParent.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
fields
|
||||
|
||||
MyParent : HArbitraryTree;
|
||||
MyItem : Item;
|
||||
MyChildren: SeqArbitraryTree;
|
||||
end;
|
308
src/PCollection/PCollection_HArbitraryTree.gxx
Executable file
308
src/PCollection/PCollection_HArbitraryTree.gxx
Executable file
@@ -0,0 +1,308 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <PCollection_IsNotRoot.hxx>
|
||||
#include <PCollection_IsNullTree.hxx>
|
||||
#include <PCollection_IsContained.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_HArbitraryTree.gxx
|
||||
// Created: Aug, 5 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// -----------
|
||||
// constructor :
|
||||
// -----------
|
||||
PCollection_HArbitraryTree::PCollection_HArbitraryTree(const Item& T)
|
||||
{
|
||||
MyItem = T;
|
||||
MyChildren = new PCollection_SeqArbitraryTree;
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// Children : Returns the list of children of me
|
||||
// -----------------------------------------------
|
||||
Handle(PCollection_SeqArbitraryTree)
|
||||
PCollection_HArbitraryTree::Children() const
|
||||
{
|
||||
return MyChildren;
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// Child : returns a child
|
||||
// ----------------------
|
||||
Handle(PCollection_HArbitraryTree)
|
||||
PCollection_HArbitraryTree::Child(const Standard_Integer Index) const
|
||||
{
|
||||
return MyChildren->Value(Index);
|
||||
}
|
||||
|
||||
// ----------------------------------------------
|
||||
// Value : returns the value of the current tree
|
||||
// ----------------------------------------------
|
||||
Item PCollection_HArbitraryTree::Value() const
|
||||
{
|
||||
return MyItem;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// NbChildren : Number of children in the current tree
|
||||
// ----------------------------------------------------
|
||||
Standard_Integer PCollection_HArbitraryTree::NbChildren() const
|
||||
{
|
||||
return (MyChildren->Length());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// IsLeaf : Returns True if the current tree has no child
|
||||
// -------------------------------------------------------
|
||||
Standard_Boolean PCollection_HArbitraryTree::IsLeaf() const
|
||||
{
|
||||
return (MyChildren->IsEmpty());
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// Parent
|
||||
// ----------------------
|
||||
Handle(PCollection_HArbitraryTree) PCollection_HArbitraryTree::Parent() const
|
||||
{
|
||||
return MyParent;
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// IsRoot
|
||||
// ---------------------
|
||||
Standard_Boolean PCollection_HArbitraryTree::IsRoot() const
|
||||
{
|
||||
return (MyParent.IsNull());
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Root : Returns the root of the current tree
|
||||
// ---------------------------------------------
|
||||
Handle(PCollection_HArbitraryTree) PCollection_HArbitraryTree::Root() const
|
||||
{
|
||||
Handle(PCollection_HArbitraryTree) AParent;
|
||||
AParent = this;
|
||||
while ( !AParent->IsRoot() ) AParent = AParent->Parent();
|
||||
return AParent;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// LeftSibling : returns the left neighbour of the current tree
|
||||
// ----------------------------------------------------------------
|
||||
Handle(PCollection_HArbitraryTree) PCollection_HArbitraryTree::LeftSibling() const
|
||||
{
|
||||
Handle(PCollection_HArbitraryTree) MySelf,TheParent,NullTree;
|
||||
Handle(PCollection_SeqArbitraryTree) TheBrothers;
|
||||
NullTree.Nullify();
|
||||
MySelf = this;
|
||||
if (MySelf->IsRoot()) return NullTree;
|
||||
TheBrothers = (MySelf->Parent())->Children();
|
||||
Standard_Integer TheIndex = TheBrothers->Location(1,MySelf);
|
||||
if (TheIndex <= 1)
|
||||
return NullTree;
|
||||
else
|
||||
return (TheBrothers->Value(TheIndex-1));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// RightSibling : returns the right neighbour of the current tree
|
||||
// ---------------------------------------------------------------
|
||||
Handle(PCollection_HArbitraryTree) PCollection_HArbitraryTree::RightSibling() const
|
||||
{
|
||||
Handle(PCollection_HArbitraryTree) MySelf,TheParent,NullTree;
|
||||
Handle(PCollection_SeqArbitraryTree) TheBrothers;
|
||||
NullTree.Nullify();
|
||||
MySelf = this;
|
||||
if (MySelf->IsRoot()) return NullTree;
|
||||
TheBrothers = (MySelf->Parent())->Children();
|
||||
Standard_Integer TheIndex = TheBrothers->Location(1,MySelf);
|
||||
if (TheIndex == TheBrothers->Length())
|
||||
return NullTree;
|
||||
else
|
||||
return (TheBrothers->Value(TheIndex+1));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Contains : checks if the tree Atree is contained by the current one
|
||||
// --------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HArbitraryTree::Contains
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree) const
|
||||
{
|
||||
if (ATree.IsNull()) PCollection_IsNullTree::Raise();
|
||||
Handle(PCollection_HArbitraryTree) MySelf = this;
|
||||
Standard_Boolean IsFound = Standard_False;
|
||||
PCollection_ATPreOrderIterator Iter(MySelf);
|
||||
while (!IsFound && Iter.More()) {
|
||||
if (Iter.Value() == ATree) IsFound = Standard_True;
|
||||
Iter.Next();
|
||||
}
|
||||
return IsFound;
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// SetValue : changes the value of the current tree
|
||||
// -------------------------------------------------
|
||||
void PCollection_HArbitraryTree::SetValue(const Item& T)
|
||||
{
|
||||
MyItem = T;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// SetParent : changes the parent value of the current tree
|
||||
// ---------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::SetParent
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
MyParent = ATree;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// SwapChild : replace, in the current tree, the child at the range
|
||||
// <Index> by the tree <ATree> and conversely
|
||||
// ---------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::SwapChild
|
||||
(const Standard_Integer Index,Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
if (!ATree.IsNull() && !ATree->IsRoot()) PCollection_IsNotRoot::Raise();
|
||||
Handle (PCollection_HArbitraryTree) TempTree = ATree;
|
||||
Handle (PCollection_HArbitraryTree) NullTree;
|
||||
NullTree.Nullify();
|
||||
// ... Update the returned tree
|
||||
ATree = Child(Index);
|
||||
ATree->SetParent(NullTree);
|
||||
// ... Update the current tree
|
||||
if (! TempTree.IsNull()) InsertChildAfter(Index,TempTree);
|
||||
MyChildren->Remove(Index);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// SwapChildren : TradeOff between two subtrees in the current tree
|
||||
// -----------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::SwapChildren
|
||||
( const Handle(PCollection_HArbitraryTree)& Subtree1,
|
||||
const Handle(PCollection_HArbitraryTree)& Subtree2 )
|
||||
{
|
||||
if (Subtree1.IsNull() || Subtree2.IsNull())
|
||||
PCollection_IsNullTree::Raise();
|
||||
if (!Contains(Subtree1) || !Contains(Subtree2))
|
||||
Standard_NoSuchObject::Raise();
|
||||
if (Subtree1->Contains(Subtree2) || Subtree1->Contains(Subtree2))
|
||||
PCollection_IsContained::Raise();
|
||||
Handle(PCollection_HArbitraryTree) Parent1 = Subtree1->Parent();
|
||||
Handle(PCollection_HArbitraryTree) Parent2 = Subtree2->Parent();
|
||||
Handle(PCollection_SeqArbitraryTree)
|
||||
Children1 = Parent1->Children();
|
||||
Handle(PCollection_SeqArbitraryTree)
|
||||
Children2 = Parent2->Children();
|
||||
|
||||
// ... Searching the index of the subtrees.
|
||||
Standard_Integer Ind1 = Children1->Location(1,Subtree1);
|
||||
Standard_Integer Ind2 = Children2->Location(1,Subtree2);
|
||||
// ... Insertion of Subtree2
|
||||
Handle(PCollection_HArbitraryTree) NullTree;
|
||||
NullTree.Nullify();
|
||||
Subtree2->SetParent(NullTree);
|
||||
Parent1->InsertChildAfter(Ind1,Subtree2);
|
||||
Children1->Remove(Ind1);
|
||||
// ... Insertion of Subtree1
|
||||
Subtree1->SetParent(NullTree);
|
||||
Parent2->InsertChildAfter(Ind2,Subtree1);
|
||||
Children2->Remove(Ind2);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// AppendChild : appends the tree <Atree> as last child of the current tree
|
||||
// -----------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::AppendChild
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
if (ATree.IsNull()) PCollection_IsNullTree::Raise();
|
||||
if (!ATree->IsRoot()) PCollection_IsNotRoot::Raise();
|
||||
|
||||
Handle (PCollection_HArbitraryTree) MySelf = this;
|
||||
ATree->SetParent(MySelf);
|
||||
MyChildren->Append(ATree);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// PrependChild : appends the tree <ATree> as first child of the current tree
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::PrependChild
|
||||
(const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
if (ATree.IsNull()) PCollection_IsNullTree::Raise();
|
||||
if (!ATree->IsRoot()) PCollection_IsNotRoot::Raise();
|
||||
|
||||
Handle (PCollection_HArbitraryTree) MySelf = this;
|
||||
ATree->SetParent(MySelf);
|
||||
MyChildren->Prepend(ATree);
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// InsertChildBefore : adds the child <ATree> at the index <Index> in the
|
||||
// current tree
|
||||
// -----------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::InsertChildBefore
|
||||
(const Standard_Integer Index ,
|
||||
const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
if (ATree.IsNull()) PCollection_IsNullTree::Raise();
|
||||
if (!ATree->IsRoot()) PCollection_IsNotRoot::Raise();
|
||||
|
||||
Handle (PCollection_HArbitraryTree) MySelf = this;
|
||||
ATree->SetParent(MySelf);
|
||||
MyChildren->InsertBefore(Index,ATree);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// InsertChildAfter : adds the child <ATree> at the index <Index+1> in the
|
||||
// current tree
|
||||
// ------------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::InsertChildAfter
|
||||
(const Standard_Integer Index ,
|
||||
const Handle(PCollection_HArbitraryTree)& ATree)
|
||||
{
|
||||
if (ATree.IsNull()) PCollection_IsNullTree::Raise();
|
||||
if (!ATree->IsRoot()) PCollection_IsNotRoot::Raise();
|
||||
|
||||
Handle (PCollection_HArbitraryTree) MySelf = this;
|
||||
ATree->SetParent(MySelf);
|
||||
MyChildren->InsertAfter(Index,ATree);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// RemoveChild : removes the child at range <Index> in the current tree
|
||||
// ---------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::RemoveChild(const Standard_Integer Index)
|
||||
{
|
||||
MyChildren->Remove(Index);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// RemoveAllChildren : removes all children of the current tree
|
||||
// -------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::RemoveAllChildren()
|
||||
{
|
||||
MyChildren->Clear();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// RemoveChildren : removes the children in range <FromIndex,ToIndex> in the
|
||||
// current tree
|
||||
// --------------------------------------------------------------------------
|
||||
void PCollection_HArbitraryTree::RemoveChildren
|
||||
(const Standard_Integer FromIndex , const Standard_Integer ToIndex)
|
||||
{
|
||||
MyChildren->Remove(FromIndex,ToIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
118
src/PCollection/PCollection_HArray1.cdl
Executable file
118
src/PCollection/PCollection_HArray1.cdl
Executable file
@@ -0,0 +1,118 @@
|
||||
-- File: PCollection_HArray1.cdl
|
||||
-- Created: Wed Nov 25 17:47:24 1992
|
||||
-- Author: Jean Pierre TIRAULT
|
||||
-- <jpt@sdsun4>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
generic class HArray1 from PCollection (Item as Storable)
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: The class HArray1 represents unidimensionnal
|
||||
-- array of fixed size known at run time.
|
||||
-- The range of the index is user defined.
|
||||
-- Warning: Programs clients of such class must be independent
|
||||
-- of the range of the first element. Then, a C++ for
|
||||
-- loop must be written like this
|
||||
-- for (i = A->Lower(); i <= A->Upper(); i++)
|
||||
uses
|
||||
Integer from Standard,
|
||||
Address from Standard
|
||||
|
||||
raises
|
||||
OutOfRange from Standard,
|
||||
RangeError from Standard
|
||||
|
||||
class FieldOfHArray1 instantiates VArray from DBC (Item);
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create (Low, Up: Integer from Standard) returns mutable HArray1
|
||||
raises RangeError from Standard;
|
||||
---Purpose: Creates an array of lower bound <Low> and
|
||||
-- upper bound <Up>. Range error is raised
|
||||
-- when <Up> is less than <Low>.
|
||||
|
||||
Create (Low, Up: Integer from Standard ; V : Item)
|
||||
returns mutable HArray1
|
||||
raises RangeError from Standard;
|
||||
---Purpose: Creates an array of lower bound <Low> and
|
||||
-- upper bound <Up>. Range error is raised
|
||||
-- when <Up> is less than <Low>.
|
||||
-- The Array is initialized with V
|
||||
|
||||
Length (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the number of elements of <me>.
|
||||
---Level: Public
|
||||
---C++: inline
|
||||
|
||||
Lower (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the lower bound.
|
||||
---Level: Public
|
||||
---C++: inline
|
||||
|
||||
SetValue (me : mutable; Index: Integer from Standard; Value: Item)
|
||||
---Purpose: Assigns Value to the Index-th element of this array.
|
||||
-- Example
|
||||
-- PCollection_HArray1
|
||||
-- myTable(1,100);
|
||||
-- myTable->SetValue(3, 1551);
|
||||
-- assert (myTable(3) == 1551);
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is not within the bounds of this array
|
||||
raises OutOfRange from Standard
|
||||
is static ;
|
||||
---Purpose: Set the <Index>th element of the array to <Value>.
|
||||
---Level: Public
|
||||
|
||||
Upper (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the upper bound.
|
||||
---Level: Public
|
||||
---C++: inline
|
||||
|
||||
Value (me; Index: Integer from Standard) returns any Item
|
||||
raises OutOfRange from Standard
|
||||
is static;
|
||||
---Purpose: Returns the value of the <Index>th element of the array.
|
||||
-- Example
|
||||
-- PCollection_HArray1
|
||||
-- myTable(1,100);
|
||||
-- myTable->SetValue(3, 1551);
|
||||
-- Standard_Integer myItem =
|
||||
-- myTable->Value(3);
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is not within the bounds of this array.
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Purpose: Returns a new array containing a copy
|
||||
-- of the values (of the elements) in this array.
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
Field (me)returns FieldOfHArray1
|
||||
---Level: Internal
|
||||
is private;
|
||||
---Purpose: Private method that returns the field Data.
|
||||
|
||||
Datas(me) returns Address
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
|
||||
LowerBound : Integer from Standard ;
|
||||
UpperBound : Integer from Standard ;
|
||||
Data : FieldOfHArray1 ;
|
||||
|
||||
end HArray1 ;
|
||||
|
||||
|
124
src/PCollection/PCollection_HArray1.gxx
Executable file
124
src/PCollection/PCollection_HArray1.gxx
Executable file
@@ -0,0 +1,124 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_RangeError.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// HArray1 implementation:
|
||||
//
|
||||
// Last Revision : Feb,10 1992 J.P Tirault
|
||||
// Implementation of ShallowCopy, ShallowDump
|
||||
// methods.
|
||||
// ----------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
PCollection_HArray1::PCollection_HArray1
|
||||
(const Standard_Integer First,
|
||||
const Standard_Integer Last) : Data (Last-First+1)
|
||||
{
|
||||
Standard_Integer Size = Last-First+1;
|
||||
if( Size <= 0 ) Standard_RangeError::Raise();
|
||||
LowerBound = First ;
|
||||
UpperBound = Last ;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// datas
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Standard_Address PCollection_HArray1::Datas() const
|
||||
{
|
||||
return ((Standard_Address)Data.Lock());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
PCollection_HArray1::PCollection_HArray1
|
||||
(const Standard_Integer First,
|
||||
const Standard_Integer Last,
|
||||
const Item& V) :Data (Last-First+1) {
|
||||
|
||||
Standard_Integer Size = Last-First+1;
|
||||
if( Size <= 0 ) Standard_RangeError::Raise();
|
||||
LowerBound = First ;
|
||||
UpperBound = Last ;
|
||||
for(Standard_Integer I = 0 ; I < Size ; I++) Data.SetValue(I, V);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Destructor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
void PCollection_HArray1::~PCollection_HArray1 ()
|
||||
{
|
||||
delete Data ;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// ShallowCopy
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Handle(Standard_Persistent) PCollection_HArray1::ShallowCopy() const
|
||||
{
|
||||
PCollection_HArray1* TheCopy = new PCollection_HArray1(*this);
|
||||
// PCollection_FieldOfHArray1 DataCopy (Data);
|
||||
// TheCopy->Data = DataCopy;
|
||||
return TheCopy;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void PCollection_HArray1::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
::ShallowDump(Data,S);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Anciens INLINE */
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// SetValue
|
||||
// ----------------------------------------------------------------------
|
||||
void PCollection_HArray1::SetValue
|
||||
( const Standard_Integer Index, const Item& Value)
|
||||
{
|
||||
Standard_OutOfRange_Raise_if((Index < LowerBound || Index > UpperBound),
|
||||
"Index out of range in HArray1::SetValue");
|
||||
Data.SetValue(Index-LowerBound, Value) ;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Value
|
||||
// ----------------------------------------------------------------------
|
||||
Item PCollection_HArray1::Value
|
||||
( const Standard_Integer Index) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if((Index < LowerBound || Index > UpperBound),
|
||||
"Index out of range in HArray1::operator()");
|
||||
|
||||
return Data(Index-LowerBound);
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
PCollection_FieldOfHArray1 PCollection_HArray1::Field () const
|
||||
{
|
||||
return Data ;
|
||||
}
|
||||
|
33
src/PCollection/PCollection_HArray1.lxx
Executable file
33
src/PCollection/PCollection_HArray1.lxx
Executable file
@@ -0,0 +1,33 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray1::Length () const
|
||||
{
|
||||
return UpperBound-LowerBound+1 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray1::Lower () const
|
||||
{
|
||||
return LowerBound ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray1::Upper () const
|
||||
{
|
||||
return UpperBound ;
|
||||
}
|
||||
|
||||
|
||||
|
139
src/PCollection/PCollection_HArray2.cdl
Executable file
139
src/PCollection/PCollection_HArray2.cdl
Executable file
@@ -0,0 +1,139 @@
|
||||
generic class HArray2 from PCollection (Item as Storable)
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: The class HArray2 represents bi-dimensionnal
|
||||
-- arrays fixed size known at run time.
|
||||
-- The range of the index is user defined.
|
||||
-- Warning: Programs clients of such class must be independant
|
||||
-- of the range of the first element. Then, a C++ for
|
||||
-- loop must be written like this
|
||||
-- for (i = A->LowerRow(); i <= A->UpperRow(); i++)
|
||||
-- for (j = A->LowerCol(); j <= A->UpperCol(); j++)
|
||||
|
||||
raises
|
||||
RangeError from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
|
||||
class FieldOfHArray2 instantiates VArray from DBC (Item);
|
||||
|
||||
is
|
||||
|
||||
Create (R1, R2, C1, C2: Integer from Standard)
|
||||
returns mutable HArray2 from PCollection
|
||||
raises RangeError from Standard;
|
||||
---Purpose: Creates an array of lower bound <R1><C1> and
|
||||
-- upper bound <R2><C2>. Range Error is raised
|
||||
-- when <R2> is less than <R1> or <C2> is less than <C1>.
|
||||
|
||||
Create (R1, R2, C1, C2: Integer from Standard ; V : Item)
|
||||
returns mutable HArray2 from PCollection
|
||||
raises RangeError from Standard;
|
||||
---Purpose: Creates an array of lower bound <R1><C1> and
|
||||
-- upper bound <R2><C2>. RangeError is raised
|
||||
-- when <R2> is less than <R1> or <C2> is less
|
||||
-- than <C1>.
|
||||
-- The array is initialized with V.
|
||||
|
||||
ColLength (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the number of rows of <me>.
|
||||
--Example
|
||||
-- PCollection_HArray2
|
||||
-- myTable(1,100, 1, 50);
|
||||
-- Standard_Integer noOfRows =
|
||||
-- myTable->ColLength();
|
||||
|
||||
LowerCol (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the lower column number of the array.
|
||||
---Level: Public
|
||||
---C++: inline
|
||||
|
||||
LowerRow (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Purpose: Returns the lower row number of the array.
|
||||
---Level: Public
|
||||
---C++: inline
|
||||
|
||||
RowLength (me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the number of columns of <me>.
|
||||
-- Example
|
||||
-- PCollection_HArray2
|
||||
-- myTable(1,100, 1, 50);
|
||||
-- Standard_Integer noOfColumns =
|
||||
-- myTable->RowLength();
|
||||
|
||||
SetValue (me : mutable; Row, Col: Integer from Standard; Value: Item)
|
||||
raises OutOfRange from Standard
|
||||
is static ;
|
||||
---Level: Public
|
||||
---Purpose: Assigns Value to the element which is at index
|
||||
-- (Row, Column) of this array.
|
||||
-- Example
|
||||
-- PCollection_HArray2
|
||||
-- myTable(1,100,1,50);
|
||||
-- myTable->SetValue(3,5, 1551);
|
||||
-- assert (myTable(3,5) == 1551);
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if the index (Row,
|
||||
-- Column) is not within the bounds of this array.
|
||||
|
||||
UpperCol (me) returns Integer from Standard
|
||||
is static ;
|
||||
---Level: Public
|
||||
---Purpose: Returns the upper column number of the array.
|
||||
---C++: inline
|
||||
|
||||
UpperRow (me) returns Integer from Standard
|
||||
---Level: Public
|
||||
is static ;
|
||||
---Level: Public
|
||||
---Purpose: Returns the upper row number of the array.
|
||||
---C++: inline
|
||||
|
||||
Value (me; Row,Col: Integer from Standard) returns any Item
|
||||
raises OutOfRange from Standard
|
||||
is static;
|
||||
---Purpose: Returns the value of the element at index (Row,
|
||||
-- Column) of this array.
|
||||
-- Example
|
||||
-- PCollection_HArray2
|
||||
-- myTable(1,100,1,50);
|
||||
-- myTable->SetValue(3,5,1551);
|
||||
-- Standard_Integer myItem = myTable->Value(3,5);
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if the index (Row,
|
||||
-- Column) is not within the bounds of this array.
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Purpose: Returns a new array containing a copy of the
|
||||
-- values (of the elements) in this array.
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
Field (me) returns FieldOfHArray2
|
||||
is private;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the field Data. Private method.
|
||||
|
||||
Datas(me) returns Address
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
|
||||
myLowerRow : Integer from Standard ;
|
||||
myLowerCol : Integer from Standard ;
|
||||
myUpperRow : Integer from Standard ;
|
||||
myUpperCol : Integer from Standard ;
|
||||
Data : FieldOfHArray2 ;
|
||||
|
||||
end HArray2 ;
|
144
src/PCollection/PCollection_HArray2.gxx
Executable file
144
src/PCollection/PCollection_HArray2.gxx
Executable file
@@ -0,0 +1,144 @@
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// HArray2 Implementation :
|
||||
//
|
||||
// Last Revision : Feb,10 1992 J.P Tirault
|
||||
// Implementation of ShallowCopy, ShallowDump
|
||||
// methods.
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Exceptions raised
|
||||
// --------------------------------------------------------------------
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_RangeError.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Constructor
|
||||
// --------------------------------------------------------------------
|
||||
PCollection_HArray2::PCollection_HArray2
|
||||
(const Standard_Integer R1,
|
||||
const Standard_Integer R2,
|
||||
const Standard_Integer C1,
|
||||
const Standard_Integer C2) : Data( (C2-C1+1)*(R2-R1+1) )
|
||||
{
|
||||
Standard_RangeError_Raise_if((C2-C1+1 <= 0 || R2-R1+1 <= 0 ),
|
||||
"Attempt to create a Double Array with negative size");
|
||||
|
||||
myLowerRow = R1;
|
||||
myLowerCol = C1;
|
||||
myUpperRow = R2;
|
||||
myUpperCol = C2;
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// datas
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Standard_Address PCollection_HArray2::Datas() const
|
||||
{
|
||||
return ((Standard_Address)Data.Lock());
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Constructor
|
||||
// --------------------------------------------------------------------
|
||||
PCollection_HArray2::PCollection_HArray2
|
||||
(const Standard_Integer R1,
|
||||
const Standard_Integer R2,
|
||||
const Standard_Integer C1,
|
||||
const Standard_Integer C2,
|
||||
const Item& V) : Data ( (C2-C1+1)*(R2-R1+1) )
|
||||
{
|
||||
Standard_RangeError_Raise_if((C2-C1+1 <= 0 || R2-R1+1 <= 0 ),
|
||||
"Attempt to create a Double Array with negative size");
|
||||
|
||||
myLowerRow = R1;
|
||||
myLowerCol = C1;
|
||||
myUpperRow = R2;
|
||||
myUpperCol = C2;
|
||||
Standard_Integer Size = Data.Length();
|
||||
|
||||
for (Standard_Integer I = 0; I < Size ; I++) Data.SetValue(I,V);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Destructor : Not Implemented
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
void PCollection_HArray2::~PCollection_HArray2 ()
|
||||
{
|
||||
delete Data ;
|
||||
}
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ShallowCopy
|
||||
// --------------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HArray2::ShallowCopy() const
|
||||
{
|
||||
PCollection_HArray2* TheCopy = new PCollection_HArray2(*this);
|
||||
// PCollection_FieldOfHArray2 DataCopy (Data);
|
||||
// TheCopy->Data = DataCopy;
|
||||
return TheCopy;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
// --------------------------------------------------------------------
|
||||
void PCollection_HArray2::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
::ShallowDump(Data,S);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Anciens INLINE */
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// SetValue
|
||||
// --------------------------------------------------------------------
|
||||
void PCollection_HArray2::SetValue ( const Standard_Integer Row,
|
||||
const Standard_Integer Col,
|
||||
const Item& Value)
|
||||
{
|
||||
Standard_OutOfRange_Raise_if((Row <myLowerRow || Row > myUpperRow ||
|
||||
Col <myLowerCol || Col > myUpperCol),
|
||||
"Index out of range in HArray2::SetValue");
|
||||
|
||||
Data.SetValue((Row-myLowerRow)*(myUpperCol-myLowerCol+1)+
|
||||
(Col-myLowerCol), Value) ;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Value
|
||||
// --------------------------------------------------------------------
|
||||
Item PCollection_HArray2::Value (const Standard_Integer Row,
|
||||
const Standard_Integer Col) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if((Row <myLowerRow || Row > myUpperRow ||
|
||||
Col <myLowerCol || Col > myUpperCol),
|
||||
"Index out of range in HArray2::SetValue");
|
||||
|
||||
return Data((Row-myLowerRow) * (myUpperCol-myLowerCol+1) +
|
||||
(Col-myLowerCol)) ;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
PCollection_FieldOfHArray2 PCollection_HArray2::Field () const
|
||||
{
|
||||
return Data ;
|
||||
}
|
||||
|
64
src/PCollection/PCollection_HArray2.lxx
Executable file
64
src/PCollection/PCollection_HArray2.lxx
Executable file
@@ -0,0 +1,64 @@
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
inline Standard_Integer PCollection_HArray2::ColLength () const
|
||||
{
|
||||
return myUpperRow - myLowerRow + 1 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray2::LowerCol () const
|
||||
{
|
||||
return myLowerCol ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray2::UpperCol () const
|
||||
{
|
||||
return myUpperCol ;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray2::LowerRow () const
|
||||
{
|
||||
return myLowerRow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray2::RowLength () const
|
||||
{
|
||||
return myUpperCol - myLowerCol + 1 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
inline Standard_Integer PCollection_HArray2::UpperRow () const
|
||||
{
|
||||
return myUpperRow ;
|
||||
}
|
||||
|
||||
|
||||
|
468
src/PCollection/PCollection_HAsciiString.cdl
Executable file
468
src/PCollection/PCollection_HAsciiString.cdl
Executable file
@@ -0,0 +1,468 @@
|
||||
-- File: PCollection_HAsciiString.cdl
|
||||
-- Created: Wed Feb 10 18:03:38 1993
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun4>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
class HAsciiString from PCollection
|
||||
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: Describes a persistent ASCII character string of variable length.
|
||||
|
||||
uses VArrayOfCharacter from DBC,
|
||||
HExtendedString from PCollection,
|
||||
AsciiString from TCollection
|
||||
|
||||
raises OutOfRange from Standard,
|
||||
NegativeValue from Standard,
|
||||
NumericError from Standard
|
||||
is
|
||||
|
||||
|
||||
Create(S : CString)
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Purpose: Creation and initialization with the string S.
|
||||
|
||||
Create(S : AsciiString from TCollection)
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Purpose: Creation and initialization with the string S from TCollection.
|
||||
|
||||
Create(C : Character from Standard)
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Purpose: Creation and initialization with the character C.
|
||||
|
||||
Create(S : HAsciiString from PCollection;
|
||||
FromIndex, ToIndex : Integer from Standard)
|
||||
returns mutable HAsciiString from PCollection
|
||||
raises NegativeValue from Standard;
|
||||
---Purpose: Creation of a sub-string of the string S.
|
||||
-- The sub-string starts at the index FromIndex and ends
|
||||
-- at the index ToIndex
|
||||
---Trigger: Raises an exception if ToIndex is less than FromIndex .
|
||||
---Example: before
|
||||
-- S = "abcdefg", FromIndex=3, ToIndex=6
|
||||
-- after
|
||||
-- S = "abcdefg"
|
||||
-- returns
|
||||
-- "cdef"
|
||||
|
||||
Create(S : HExtendedString from PCollection)
|
||||
returns mutable HAsciiString from PCollection
|
||||
raises OutOfRange from Standard;
|
||||
---Purpose: Creation by converting an extended string to a normal
|
||||
-- string. Raises OutOfRange if the String is not in the "Ascii range".
|
||||
|
||||
Create(R : Real from Standard ; F : CString = "%f")
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Purpose: Creation and initialization by converting the real
|
||||
-- value into a string.
|
||||
-- F describes a format using "C" conventions.
|
||||
|
||||
Create(I : Integer from Standard ; F : CString = "%d")
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Purpose: Creation and initialization by converting the Integer
|
||||
-- value into a string.
|
||||
-- F describes a format using "C" conventions.
|
||||
|
||||
Append(me : mutable; S : HAsciiString from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string at the end of the string me
|
||||
---Example:
|
||||
-- before
|
||||
-- me = "abcd" , S = "ef"
|
||||
-- after
|
||||
-- me = "abcdef" , S = "ef"
|
||||
|
||||
Capitalize(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Converts the first character into its corresponding
|
||||
-- upper-case character and the other characters into lowercase
|
||||
---Example: before
|
||||
-- me = "hellO "
|
||||
-- after
|
||||
-- me = "Hello "
|
||||
|
||||
Center(me : mutable;
|
||||
Width : Integer from Standard;
|
||||
Filler : Character from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: center
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler
|
||||
-- Raises an exception if Width is less than zero
|
||||
-- if Width < Length nothing happens
|
||||
---Example: before
|
||||
-- me = "abcdef" , Width = 9 , Filler = ' '
|
||||
-- after
|
||||
-- me = " abcdef "
|
||||
|
||||
ChangeAll(me : mutable;
|
||||
C, NewC : Character from Standard;
|
||||
CaseSensitive : Boolean from Standard);
|
||||
---Level: Public
|
||||
---Purpose: Substitutes all the characters equal to C by NewC in the
|
||||
-- string <me>.The substition can be case sensitive.
|
||||
---Example: before
|
||||
-- me = "HetTo" , C = 't' , NewC = 'l' ,
|
||||
-- CaseSensitive = True
|
||||
-- after
|
||||
-- me = "HelTo"
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Remove all characters in the string <me>.
|
||||
-- Length is equal to zero now.
|
||||
|
||||
Convert(me) returns AsciiString from TCollection;
|
||||
---Level: Public
|
||||
---Purpose: Converts a persistent HAsciiString to a non
|
||||
-- persistent AsciiString.
|
||||
|
||||
FirstLocationInSet(me; Set : HAsciiString from PCollection;
|
||||
FromIndex : Integer from Standard;
|
||||
ToIndex : Integer from Standard)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the first character of <Set> founded in <me>.
|
||||
-- The search begins to the index FromIndex and ends to the
|
||||
-- the index ToIndex.
|
||||
-- Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
---Example: before
|
||||
-- me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7
|
||||
-- after
|
||||
-- me = "aabAcAa"
|
||||
-- returns
|
||||
-- 4
|
||||
|
||||
FirstLocationNotInSet(me; Set : HAsciiString from PCollection;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer) returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the first character of <me>
|
||||
-- that is not present in the set <Set>.
|
||||
-- The search begins to the index FromIndex and ends to the
|
||||
-- the index ToIndex in <me>.
|
||||
-- Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
---Example: before
|
||||
-- me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7
|
||||
-- after
|
||||
-- me = "aabAcAa"
|
||||
-- returns
|
||||
-- 3
|
||||
|
||||
InsertAfter(me : mutable; Index : Integer;
|
||||
S : HAsciiString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string after a specific index in the string <me>.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
---Example: before
|
||||
-- me = "cde" , Index = 0 , S = "ab"
|
||||
-- after
|
||||
-- me = "abcde" , S = "ab"
|
||||
|
||||
InsertBefore(me : mutable; Index : Integer;
|
||||
S : HAsciiString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string before a specific index in the string <me>
|
||||
-- Raises an exception if Index is out of bounds
|
||||
---Example: before
|
||||
-- me = "cde" , Index = 1 , S = "ab"
|
||||
-- after
|
||||
-- me = "abcde" , S = "ab"
|
||||
|
||||
IntegerValue(me) returns Integer
|
||||
raises NumericError from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the integer value corresponding to the string <me>
|
||||
-- Raises an exception if the string does not correspond to
|
||||
-- an integer value.
|
||||
---Example: me = " 10 " -> 10
|
||||
|
||||
IsDifferent (me ; other : HAsciiString) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Test if characters are different
|
||||
-- between <me> and <other>.
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the string <me> contains zero character
|
||||
|
||||
IsGreater (me ; other : HAsciiString) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if <me> is 'ASCII' greater than <other>.
|
||||
|
||||
IsIntegerValue(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the string contains an integer value.
|
||||
---Example: me = "3.14 " -> False
|
||||
-- me = "123" -> True
|
||||
|
||||
IsLess (me ; other : HAsciiString) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if <me> is 'ASCII' less than <other>.
|
||||
|
||||
IsRealValue(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the string contains an Real value.
|
||||
---Example: me = "3.14 " -> True
|
||||
-- me = "123" -> True
|
||||
-- me = "3.14a" -> False
|
||||
|
||||
IsSameString(me ; S : HAsciiString from PCollection)
|
||||
---Level: Public
|
||||
---Purpose: Returns True if two strings are equal.
|
||||
-- The comparison is case sensitive.
|
||||
returns Boolean from Standard;
|
||||
|
||||
IsSameString(me; S : HAsciiString from PCollection;
|
||||
CaseSensitive : Boolean from Standard)
|
||||
returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if two strings are equal.
|
||||
-- The comparison is case sensitive if the flag is set.
|
||||
|
||||
LeftAdjust(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all space characters in the begining of the
|
||||
-- string.
|
||||
|
||||
LeftJustify(me : mutable; Width : Integer;
|
||||
Filler : Character from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Left justify.
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler.
|
||||
-- If Width < Length nothing happens.
|
||||
-- Raises an exception if Width is less than zero.
|
||||
---Example: before
|
||||
-- me = "abcdef" , Width = 9 , Filler = ' '
|
||||
-- after
|
||||
-- me = "abcdef "
|
||||
|
||||
Length(me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Number of characters of the String.
|
||||
|
||||
Location(me; N : Integer; C : Character from Standard;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the character C
|
||||
-- in the string <me> from the starting index FromIndex to the
|
||||
-- ending index ToIndex.
|
||||
-- Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
---Example: before
|
||||
-- me = "aabAa", N = 3, C = 'a', FromIndex = 1, ToIndex = 5
|
||||
-- after
|
||||
-- me = "aabAa"
|
||||
-- returns
|
||||
-- 5
|
||||
|
||||
Location(me; S : HAsciiString from PCollection;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns an index in the string <me> of the first occurence
|
||||
-- of the string S in the string <me> from the starting index
|
||||
-- FromIndex to the ending index ToIndex
|
||||
-- returns zero if failure
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
---Example: before
|
||||
-- me = "aabAaAa", S = "Aa", FromIndex = 1, ToIndex = 7
|
||||
-- after
|
||||
-- me = "aabAaAa"
|
||||
-- returns
|
||||
-- 4
|
||||
|
||||
Lowercase(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Converts any upper-case character to its corresponding
|
||||
-- lower-case character in the string <me>. If there is no
|
||||
-- corresponding lower-case character, the character is
|
||||
-- unchanged
|
||||
-- before
|
||||
-- me = "aBAcd123"
|
||||
-- after
|
||||
-- me = "abacd123"
|
||||
|
||||
Prepend(me : mutable; S : HAsciiString from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string at the begining of the string <me>
|
||||
-- before
|
||||
-- me = "cde" , S = "ab"
|
||||
-- after
|
||||
-- me = "abcde" , S = "ab"
|
||||
|
||||
Print(me ; S : in out OStream);
|
||||
---Level: Public
|
||||
---Purpose: Prints the content of <me> on the stream S.
|
||||
|
||||
RealValue(me) returns Real from Standard
|
||||
raises NumericError from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the real value corresponding to the string <me>.
|
||||
-- Raises an exception if the string does not correspond to a real value.
|
||||
---Example: me = " 10 " returns 10.0
|
||||
|
||||
Remove(me : mutable; Index : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Removes the character located at the index Index in the string.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
Remove(me : mutable; FromIndex, ToIndex : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Removes all the characters from the index FromIndex to the
|
||||
-- index ToIndex.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of bounds.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
RemoveAll(me : mutable; C : Character from Standard;
|
||||
CaseSensitive : Boolean from Standard);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the occurences of the character C in the string
|
||||
---Example: before
|
||||
-- me = "HellLLo", C = 'L' , CaseSensitive = True
|
||||
-- after
|
||||
-- me = "Hello"
|
||||
|
||||
RightAdjust(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all space characters at the end of the string.
|
||||
|
||||
RightJustify(me : mutable;
|
||||
Width : Integer;
|
||||
Filler : Character from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Right justify.
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler.
|
||||
-- If Width < Length nothing happens.
|
||||
-- Raises an exception if Width is less than zero.
|
||||
---Example: before
|
||||
-- me = "abcdef" , Width = 9 , Filler = ' '
|
||||
-- after
|
||||
-- me = " abcdef"
|
||||
|
||||
SetValue(me : mutable; Index : Integer; C : Character from Standard)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Substitutes the character located to the position Index
|
||||
-- by the character C.
|
||||
-- Raises an exception if the Index is out of bounds.
|
||||
---Example: before
|
||||
-- me = "Helll" , Index = 5 , C = 'o'
|
||||
-- after
|
||||
-- me = "Hello"
|
||||
|
||||
SetValue(me : mutable; Index : Integer;
|
||||
S : HAsciiString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Substitutes from the index Index to the end by the string S.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
---Example: before
|
||||
-- me = "abcde" , Index = 3 , S = "wxyz"
|
||||
-- after
|
||||
-- me = "abwxyz" , S = "wxyz"
|
||||
|
||||
Split(me : mutable; Index : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Splits a string of characters into two sub-strings.
|
||||
returns mutable HAsciiString from PCollection
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
SubString(me; FromIndex, ToIndex : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Creation of a sub-string of the string <me>.
|
||||
-- The sub-string starts to the index Fromindex and ends
|
||||
-- to the index ToIndex.
|
||||
-- Raises an exception if ToIndex or FromIndex is out of bounds.
|
||||
---Example: before
|
||||
-- me = "abcdefg", ToIndex=3, FromIndex=6
|
||||
-- after
|
||||
-- me = "abcdefg"
|
||||
-- returns
|
||||
-- "cdef"
|
||||
returns mutable HAsciiString from PCollection
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
Token (me ; separators : CString=" \t" ; whichone : Integer=1)
|
||||
returns mutable HAsciiString from PCollection;
|
||||
---Level: Public
|
||||
---Purpose: Extracts <aString> token from <me>.
|
||||
-- The token extracted is the indice number <num>.
|
||||
|
||||
Uppercase(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Transforms all the characters into upper-case.
|
||||
-- If there is no corresponding upper-case character, the
|
||||
-- character is unchanged.
|
||||
---Example: before
|
||||
-- me = "aBAcd"
|
||||
-- after
|
||||
-- me = "ABACD"
|
||||
|
||||
UsefullLength(me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Length of the string ignoring all spaces (' ') and the
|
||||
-- control character at the end.
|
||||
|
||||
Value(me ; Index : Integer) returns Character from Standard
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the character of index Index of the string
|
||||
---Example: me = "abcd", Index = 2, Value returns 'b'.
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
Assign(me : mutable ;TheData : VArrayOfCharacter) is private;
|
||||
---Level: Internal
|
||||
---Purpose : Assigns the field of the current structure with
|
||||
-- the given value.Private method.
|
||||
|
||||
|
||||
fields
|
||||
Data : VArrayOfCharacter from DBC;
|
||||
end HAsciiString;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
744
src/PCollection/PCollection_HAsciiString.cxx
Executable file
744
src/PCollection/PCollection_HAsciiString.cxx
Executable file
@@ -0,0 +1,744 @@
|
||||
|
||||
#include <PCollection_HAsciiString.ixx>
|
||||
#include <PCollection_HExtendedString.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <Standard_NumericError.hxx>
|
||||
#include <Standard_NegativeValue.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#if defined(HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#if defined(HAVE_LIBC_H)
|
||||
# include <libc.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------
|
||||
// Conversion functions and variables
|
||||
//------------------------------------
|
||||
|
||||
#define MAXLENGTH 80
|
||||
static char cnvbuf[MAXLENGTH];
|
||||
static Standard_Integer cnvint;
|
||||
static Standard_Real cnvreal;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// intstr
|
||||
//-----------------------------------------------------------------------
|
||||
static int intstr(Standard_Integer V,Standard_CString F)
|
||||
{
|
||||
sprintf(cnvbuf,F,V);
|
||||
return strlen(cnvbuf);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// realstr
|
||||
//----------------------------------------------------------------------
|
||||
static int realstr(Standard_Real V, Standard_CString F)
|
||||
{
|
||||
sprintf(cnvbuf,F,V);
|
||||
return strlen(cnvbuf);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Create : from a CString
|
||||
//-----------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString(const Standard_CString S)
|
||||
: Data(strlen(S))
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length() ; i++)
|
||||
Data.SetValue(i, S[i]) ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from an AsciiString of TCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString
|
||||
(const TCollection_AsciiString& S):Data(S.Length())
|
||||
{
|
||||
for( Standard_Integer i = 1; i <= Data.Length() ; i++)
|
||||
Data.SetValue(i-1, S.Value(i)) ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from a Character
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString(const Standard_Character C)
|
||||
: Data(1)
|
||||
{
|
||||
Data.SetValue(0, C);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from a range of an HAsciiString of PCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString
|
||||
(const Handle(PCollection_HAsciiString)& S,
|
||||
const Standard_Integer FromIndex, const Standard_Integer ToIndex) : Data(ToIndex-FromIndex+1)
|
||||
{
|
||||
for( Standard_Integer i = 0 , k = FromIndex; i < Data.Length() ; i++, k++)
|
||||
Data.SetValue(i, S->Value(k));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from an HExtendedString from PCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString
|
||||
(const Handle(PCollection_HExtendedString)& S) : Data(S->Length())
|
||||
{
|
||||
if (!S->IsAscii()) Standard_OutOfRange::Raise();
|
||||
for( Standard_Integer i = 1; i <= Data.Length() ; i++) {
|
||||
// convert the character i of S
|
||||
Standard_Character val = ToCharacter(S->Value(i)) ;
|
||||
Data.SetValue(i-1,val ) ;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from a Real by converting it
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString
|
||||
(const Standard_Real R , const Standard_CString F) : Data(realstr(R,F))
|
||||
{
|
||||
for( Standard_Integer i =0 ; i < Data.Length() ; i++)
|
||||
Data.SetValue(i,cnvbuf[i] );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from an Integer by converting it
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HAsciiString::PCollection_HAsciiString
|
||||
(const Standard_Integer I, const Standard_CString F) : Data(intstr(I,F))
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length() ; i++)
|
||||
Data.SetValue(i,cnvbuf[i]) ;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Append
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Append
|
||||
(const Handle(PCollection_HAsciiString)& S)
|
||||
{
|
||||
InsertAfter(Length(),S);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Capitalize
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Capitalize ()
|
||||
{
|
||||
for (Standard_Integer i = 0 ; i < Length() ; i++) {
|
||||
if( i == 0) Data.SetValue(i, UpperCase(Data(i)) );
|
||||
else Data.SetValue(i, LowerCase(Data(i)) );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Center
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Center
|
||||
(const Standard_Integer Width, const Standard_Character Filler)
|
||||
{
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Standard_Integer size2 = size1 + ((Width - size1)/2);
|
||||
LeftJustify(size2,Filler);
|
||||
RightJustify(Width,Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// ChangeAll
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::ChangeAll
|
||||
(const Standard_Character C, const Standard_Character NewC, const Standard_Boolean CaseSensitive)
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length(); i++) {
|
||||
if (CaseSensitive) {
|
||||
if(Data(i) == C) Data.SetValue(i, NewC);
|
||||
}
|
||||
else {
|
||||
if(UpperCase(Data(i)) == UpperCase(C)) Data.SetValue(i, NewC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Clear
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Clear ()
|
||||
{
|
||||
Data.Resize(0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Convert
|
||||
//------------------------------------------------------------------------
|
||||
TCollection_AsciiString PCollection_HAsciiString::Convert() const
|
||||
{
|
||||
Standard_Integer L = Length();
|
||||
TCollection_AsciiString TString (L,' ');
|
||||
for (Standard_Integer i = 1 ; i <= L ; i++) {
|
||||
TString.SetValue(i,Value(i));
|
||||
}
|
||||
return TString;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// FirstLocationInSet
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::FirstLocationInSet
|
||||
(const Handle(PCollection_HAsciiString)& Set,
|
||||
const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || Set->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++)
|
||||
for(Standard_Integer j = 1; j <= Set->Length(); j++)
|
||||
if(Data(i) == Set->Value(j)) return (i+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// FirstLocationNotInset
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::FirstLocationNotInSet
|
||||
(const Handle(PCollection_HAsciiString)& Set, const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || Set->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Standard_Boolean find;
|
||||
for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++) {
|
||||
find = Standard_False;
|
||||
for(Standard_Integer j = 1; j <= Set->Length(); j++) {
|
||||
if (Data(i) == Set->Value(j)) find = Standard_True;
|
||||
}
|
||||
if (!find) return (i+1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// InsertAfter
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::InsertAfter
|
||||
(const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
Data.Resize(size1+size2);
|
||||
for( i = size1-1 ; i >= Index; i--) Data.SetValue(size2+i,Data(i));
|
||||
for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-1,S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// InsertBefore
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::InsertBefore
|
||||
(const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
Data.Resize(size1+size2);
|
||||
for( i = size1-1 ; i >= Index-1 ; i--)
|
||||
Data.SetValue(size2+i,Data(i));
|
||||
for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IntegerValue
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::IntegerValue () const
|
||||
{
|
||||
if (!IsIntegerValue()) Standard_NumericError::Raise();
|
||||
return cnvint;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsDifferent
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsDifferent
|
||||
(const Handle(PCollection_HAsciiString)& S) const
|
||||
{
|
||||
Standard_Integer size = Length();
|
||||
if( size != S->Length()) return Standard_True;
|
||||
Standard_Integer i = 1 ;
|
||||
Standard_Boolean different = Standard_False;
|
||||
while (i <= size && !different) {
|
||||
if (Data(i-1) != S->Value(i)) different = Standard_True;
|
||||
i++;
|
||||
}
|
||||
return different;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsEmpty
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsEmpty () const
|
||||
{
|
||||
return (Data.Length() == 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsGreater
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsGreater
|
||||
(const Handle(PCollection_HAsciiString)& S) const
|
||||
{
|
||||
TCollection_AsciiString TMe = Convert();
|
||||
TCollection_AsciiString TS = S->Convert();
|
||||
return TMe.IsGreater(TS);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsIntegervalue
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsIntegerValue () const
|
||||
{
|
||||
Standard_Integer i ;
|
||||
#if defined(__osf__) || defined(DECOSF1)
|
||||
#ifdef OBJS
|
||||
#pragma pointer_size (save)
|
||||
#pragma pointer_size (long)
|
||||
char *ptr;
|
||||
#pragma pointer_size (restore)
|
||||
#else
|
||||
char *ptr;
|
||||
#endif
|
||||
#else
|
||||
char *ptr;
|
||||
#endif
|
||||
#ifndef NOBOUNDCHECK
|
||||
if ( Data.Length() > MAXLENGTH ) return Standard_False;
|
||||
#endif
|
||||
Handle(TCollection_HAsciiString) astring;
|
||||
astring = new TCollection_HAsciiString (this->Convert());
|
||||
astring->LeftAdjust();
|
||||
astring->RightAdjust();
|
||||
for(i = 0; i < astring->Length(); i++)
|
||||
cnvbuf[i] = astring->Value(i+1);
|
||||
cnvbuf[i] = 0;
|
||||
cnvint = strtol(cnvbuf,&ptr,10);
|
||||
if (ptr < cnvbuf+astring->Length()) return Standard_False;
|
||||
else return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Isless
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsLess
|
||||
(const Handle(PCollection_HAsciiString)& S) const
|
||||
{
|
||||
TCollection_AsciiString TMe = Convert();
|
||||
TCollection_AsciiString TS = S->Convert();
|
||||
return TMe.IsLess(TS);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsRealValue
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsRealValue () const
|
||||
{
|
||||
Standard_Integer i ;
|
||||
#if defined(__osf__) || defined(DECOSF1)
|
||||
#ifdef OBJS
|
||||
#pragma pointer_size (save)
|
||||
#pragma pointer_size (long)
|
||||
char *ptr;
|
||||
#pragma pointer_size (restore)
|
||||
#else
|
||||
char *ptr;
|
||||
#endif
|
||||
#else
|
||||
char *ptr;
|
||||
#endif
|
||||
#ifndef NOBOUNDCHECK
|
||||
if ( Data.Length() > MAXLENGTH ) return Standard_False;
|
||||
#endif
|
||||
Handle(TCollection_HAsciiString) astring;
|
||||
astring = new TCollection_HAsciiString (this->Convert());
|
||||
astring->LeftAdjust();
|
||||
astring->RightAdjust();
|
||||
for(i = 0; i < astring->Length(); i++)
|
||||
cnvbuf[i] = astring->Value(i+1);
|
||||
cnvbuf[i] = 0;
|
||||
cnvreal = strtod(cnvbuf,&ptr);
|
||||
if (ptr < cnvbuf+astring->Length()) return Standard_False;
|
||||
else return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsSameString
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsSameString
|
||||
(const Handle(PCollection_HAsciiString)& S) const
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer size1 = Length();
|
||||
if( size1 != S->Length()) return Standard_False;
|
||||
for( i = 1 ; i <= size1; i++) {
|
||||
if(Data(i-1) != S->Value(i)) return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsSameString
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HAsciiString::IsSameString
|
||||
(const Handle(PCollection_HAsciiString)& S, const Standard_Boolean CaseSensitive) const
|
||||
{
|
||||
Standard_Integer size1 = Length();
|
||||
if( size1 != S->Length()) return Standard_False;
|
||||
for( Standard_Integer i = 1 ; i <= size1; i++) {
|
||||
if(CaseSensitive){
|
||||
if(Data(i-1) != S->Value(i)) return Standard_False;
|
||||
}
|
||||
else {
|
||||
if(UpperCase(Data(i-1)) != UpperCase(S->Value(i))) return Standard_False;
|
||||
}
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// LeftAdjust
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::LeftAdjust ()
|
||||
{
|
||||
Standard_Integer i ;
|
||||
for(i = 0 ; i < Data.Length() ; i ++) if(!IsSpace(Data(i))) break;
|
||||
if( i > 0 ) Remove(1,i);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// LeftJustify
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::LeftJustify
|
||||
(const Standard_Integer Width, const Standard_Character Filler)
|
||||
{
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Data.Resize(Width);
|
||||
for(Standard_Integer i = size1; i < Width ; i++) Data.SetValue(i, Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Length
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::Length () const
|
||||
{
|
||||
return Data.Length();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Location
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::Location
|
||||
(const Standard_Integer N, const Standard_Character C,
|
||||
const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1, count = 0; i <= ToIndex-1; i++)
|
||||
if(Data(i) == C) {
|
||||
count++;
|
||||
if ( count == N ) return (i+1);
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Location
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::Location
|
||||
(const Handle(PCollection_HAsciiString)& S, const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || S->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1, k = 1, l = FromIndex-2; i < ToIndex; i++){
|
||||
if(Data(i) == S->Value(k)) {
|
||||
k++;
|
||||
if ( k > S->Length()) return l + 2;
|
||||
}
|
||||
else {
|
||||
k = 1;
|
||||
l = i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Lowercase
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Lowercase ()
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length() ; i++) {
|
||||
Data.SetValue(i, LowerCase(Data(i)));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Prepend
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Prepend
|
||||
(const Handle(PCollection_HAsciiString)& S)
|
||||
{
|
||||
InsertAfter(0,S);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Print
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Print (Standard_OStream& S) const
|
||||
{
|
||||
Standard_Integer len = Data.Length() ;
|
||||
for(Standard_Integer i = 0; i < len ; i++) {
|
||||
S << Data(i);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RealValue
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Real PCollection_HAsciiString::RealValue () const
|
||||
{
|
||||
if(!IsRealValue()) Standard_NumericError::Raise();
|
||||
return cnvreal;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Remove
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Remove (const Standard_Integer Index)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Remove(Index,Index);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Remove
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Remove
|
||||
(const Standard_Integer FromIndex, const Standard_Integer ToIndex)
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
for( Standard_Integer i = ToIndex, j = FromIndex-1; i < size1 ; i++, j++)
|
||||
Data.SetValue(j,Data(i));
|
||||
Data.Resize(size1-(ToIndex-FromIndex+1));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RemoveAll
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::RemoveAll
|
||||
(const Standard_Character C, const Standard_Boolean CaseSensitive)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer j ;
|
||||
Standard_Integer size1 = Length();
|
||||
for( i = 0, j = 0; i < size1 ; i++){
|
||||
if(CaseSensitive){
|
||||
if(Data(i) == C) continue;
|
||||
}
|
||||
else {
|
||||
if(UpperCase(Data(i)) == UpperCase(C)) continue;
|
||||
}
|
||||
Data.SetValue(j++, Data(i));
|
||||
}
|
||||
Data.Resize(j);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RightAdjust
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::RightAdjust ()
|
||||
{
|
||||
Standard_Integer i ;
|
||||
for( i = Data.Length()-1 ; i >= 0 ; i--) if(!IsSpace(Data(i))) break;
|
||||
if( i < Data.Length()-1 ) Remove(i+2,Data.Length());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RightJustify
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::RightJustify
|
||||
(const Standard_Integer Width, const Standard_Character Filler)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer k ;
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Data.Resize(Width);
|
||||
for ( i = size1-1, k = Width-1 ; i >= 0 ; i--, k--)
|
||||
Data.SetValue(k, Data(i));
|
||||
for(; k >= 0 ; k--) Data.SetValue(k, Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SetValue
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::SetValue
|
||||
(const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S)
|
||||
{
|
||||
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
Standard_Integer size3 = size2 + Index - 1;
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
if(size1 != size3) Data.Resize(size3);
|
||||
for( Standard_Integer i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SetValue
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::SetValue
|
||||
(const Standard_Integer Index, const Standard_Character C)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Data(Index-1) = C;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Split
|
||||
//------------------------------------------------------------------------
|
||||
Handle(PCollection_HAsciiString) PCollection_HAsciiString::Split
|
||||
(const Standard_Integer Index)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Handle(PCollection_HAsciiString) S2;
|
||||
if (Index != Length()) {
|
||||
S2 = SubString(Index+1,Length());
|
||||
Data.Resize(Index);
|
||||
}
|
||||
else {
|
||||
#ifndef OBJS
|
||||
S2 = new PCollection_HAsciiString("");
|
||||
#else
|
||||
S2 = new (os_segment::of(this)) PCollection_HAsciiString("");
|
||||
#endif
|
||||
}
|
||||
return S2;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SubString
|
||||
//------------------------------------------------------------------------
|
||||
Handle(PCollection_HAsciiString) PCollection_HAsciiString::SubString
|
||||
(const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Handle(PCollection_HAsciiString) S1;
|
||||
Handle(PCollection_HAsciiString) S2;
|
||||
S2 = this;
|
||||
#ifndef OBJS
|
||||
S1 = new PCollection_HAsciiString(S2,FromIndex,ToIndex);
|
||||
#else
|
||||
S1 = new (os_segment::of(this)) PCollection_HAsciiString(S2,FromIndex,ToIndex);
|
||||
|
||||
#endif
|
||||
return S1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Token
|
||||
//------------------------------------------------------------------------
|
||||
Handle(PCollection_HAsciiString) PCollection_HAsciiString::Token
|
||||
(const Standard_CString separators ,
|
||||
const Standard_Integer whichone) const
|
||||
{
|
||||
TCollection_AsciiString TMe = Convert();
|
||||
Handle(PCollection_HAsciiString)
|
||||
#ifndef OBJS
|
||||
TheToken = new PCollection_HAsciiString(TMe.Token(separators,whichone));
|
||||
#else
|
||||
TheToken = new (os_segment::of(this)) PCollection_HAsciiString(TMe.Token(separators,whichone));
|
||||
#endif
|
||||
return TheToken;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Uppercase
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Uppercase ()
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length() ; i++)
|
||||
Data.SetValue(i, UpperCase(Data(i)));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// UsefullLength
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HAsciiString::UsefullLength () const
|
||||
{
|
||||
Standard_Integer i ;
|
||||
for( i = Data.Length() -1 ; i >= 0 ; i--)
|
||||
if(IsGraphic(Data(i))) break;
|
||||
return (i+1) ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// value
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Character PCollection_HAsciiString::Value (const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
return Data(Index-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Assign
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::Assign(const DBC_VArrayOfCharacter& TheField)
|
||||
|
||||
{
|
||||
Data = TheField;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HAsciiString::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class HAsciiString " << endl;
|
||||
::ShallowDump(Data, S);
|
||||
S << "end class HAsciiString" << endl;
|
||||
}
|
224
src/PCollection/PCollection_HDataMap.cdl
Executable file
224
src/PCollection/PCollection_HDataMap.cdl
Executable file
@@ -0,0 +1,224 @@
|
||||
-- File: PCollection_HDataMap.cdl
|
||||
-- Created: Wed Feb 19 14:24:56 1992
|
||||
-- Author: Jean Pierre TIRAULT
|
||||
-- <jpt@topsn1>
|
||||
-- Revised: Thu Jan 7 17:26:12 1993
|
||||
-- By : Mireille MERCIEN
|
||||
-- <mip@sdsun4>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
generic class HDataMap from PCollection (Key as Storable;
|
||||
Item as Storable;
|
||||
FH as Hash(Key) )
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: A map is a Collection of bindings
|
||||
-- between two objects. One is considered as
|
||||
-- the key and a hash code value must be
|
||||
-- computed for it.
|
||||
|
||||
|
||||
raises MultiplyDefined from Standard,
|
||||
NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
|
||||
|
||||
|
||||
class MapNode inherits PManaged
|
||||
---Purpose: This class is used in the implementation of Map class.
|
||||
is
|
||||
|
||||
Create( aKey : Key ; anItem : Item ; aNext : MapNode)
|
||||
returns mutable MapNode from PCollection;
|
||||
|
||||
GetKey (me) returns any Key is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns myKey
|
||||
|
||||
Value(me) returns any Item is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns myItem.
|
||||
|
||||
Next(me) returns mutable MapNode is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns myNext.
|
||||
|
||||
SetKey (me : mutable ; aKey : Key) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Modifies myKey.
|
||||
|
||||
SetValue( me : mutable; anItem: Item) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Modifies myItem.
|
||||
|
||||
SetNext( me : mutable; aNode: MapNode) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Modifies myNext.
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Level: Internal
|
||||
---Purpose: ShallowCopy redefinition
|
||||
---C++: function call
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Internal
|
||||
---Purpose: ShallowDump redefinition
|
||||
---C++: function call
|
||||
|
||||
fields
|
||||
|
||||
myKey : Key;
|
||||
myItem : Item;
|
||||
myNext : MapNode;
|
||||
|
||||
end;
|
||||
|
||||
class Array instantiates HArray1 from PCollection(MapNode);
|
||||
|
||||
class MapIterator
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
---Purpose: This class provides to iterate on a Map from the
|
||||
-- first bucket entry to the last one in the table;
|
||||
-- Going through the associated list for each bucket entry.
|
||||
|
||||
Create( aMap: HDataMap)
|
||||
---Purpose: Creates an iterator on <aMap> .
|
||||
returns MapIterator;
|
||||
|
||||
More( me)
|
||||
---Level: Public
|
||||
---Purpose: Returns True if there is still an element to be read.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next( me: in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Goes to next element of <me>.
|
||||
|
||||
Value( me)
|
||||
---Level: Public
|
||||
returns any Item
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
GetKey( me)
|
||||
---Level: Public
|
||||
returns Key
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
Buckets : Array;
|
||||
NbBuck : Integer;
|
||||
Index : Integer;
|
||||
Node : MapNode;
|
||||
HasMore : Boolean;
|
||||
end;
|
||||
|
||||
is
|
||||
Create(NbBuckets : Integer ; F : FH) returns mutable HDataMap;
|
||||
---Purpose: Creation of a map of NbBuckets entries.
|
||||
-- the table is empty.
|
||||
-- If NbBuckets eq. 0 an exception will be raised.
|
||||
|
||||
NbBuckets(me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of entries in the table.
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns true if the table is empty.
|
||||
|
||||
Extent(me) returns Integer from Standard ;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of elements in the table.
|
||||
---Example: if me is the hash table ((a x)(b y)(c z)) Extent
|
||||
-- returns 3
|
||||
|
||||
IsBound(me; K : Key) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if an element is bounded to K
|
||||
|
||||
Find(me; K : Key) returns any Item raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Returns the element bounded to K.
|
||||
-- Raises an exception if the binding does not exist.
|
||||
---Example: before
|
||||
-- me = ((a x)(b y)(c z)) , K = b
|
||||
-- returns y
|
||||
|
||||
Clear(me:mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the element in the table.
|
||||
---Example: before
|
||||
-- me = ((a x)(b y)(c z))
|
||||
-- after
|
||||
-- me = ()
|
||||
|
||||
Bind(me:mutable; K : Key; T : Item)
|
||||
raises MultiplyDefined;
|
||||
---Level: Public
|
||||
---Purpose: Creates a binding between a key K and an item T.
|
||||
-- Raises an exception if the binding already exists.
|
||||
---Example: before
|
||||
-- me = ((a x)(b y)) , K = c , T = z
|
||||
-- after
|
||||
-- me = ((a x)(b y)(c z))
|
||||
|
||||
Rebind(me:mutable; K : Key; T : Item) raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Replaces the object binded to the key K by T.
|
||||
-- Raises an exception if the binding does not exist.
|
||||
---Example: before
|
||||
-- me = ((a x)(b y)) , K = b , T = z
|
||||
-- after
|
||||
-- me = ((a x)(b z))
|
||||
|
||||
Unbind(me:mutable; K : Key) raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Removes the binding keyed by K.
|
||||
-- Raises an exception if the binding does not exist.
|
||||
---Example: before
|
||||
-- me = ((a x)(b y)(c z)) , K = b
|
||||
-- after
|
||||
-- me = ((a x)(c z))
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---Purpose: ShallowCopy redefinition
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---Purpose: ShallowDump redefinition
|
||||
---C++: function call
|
||||
|
||||
|
||||
GetArray (me) returns Array is private;
|
||||
---Level: Internal
|
||||
---Purpose :Returns the field Buckets associated to the object.
|
||||
---C++: inline
|
||||
|
||||
GetFH (me) returns FH is private;
|
||||
---Level: Internal
|
||||
---Purpose :Returns the field Hash associated to the object.
|
||||
---C++: inline
|
||||
|
||||
fields
|
||||
Buckets : Array;
|
||||
Hash : FH;
|
||||
|
||||
friends class MapIterator from PCollection
|
||||
|
||||
end HDataMap;
|
||||
|
||||
|
||||
|
||||
|
248
src/PCollection/PCollection_HDataMap.gxx
Executable file
248
src/PCollection/PCollection_HDataMap.gxx
Executable file
@@ -0,0 +1,248 @@
|
||||
#include <Standard_MultiplyDefined.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// Map implementation:
|
||||
//
|
||||
// Last Revision : Jan,8 1993 M. Mercien
|
||||
// The class SingleList is no more referenced in the
|
||||
// implementation of Map.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------
|
||||
PCollection_HDataMap::PCollection_HDataMap(const Integer NbBuckets,
|
||||
const FH& F)
|
||||
{
|
||||
Buckets = new PCollection_Array( 1 , NbBuckets);
|
||||
Hash = F;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------ READING --------------------------------
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// NbBuckets : Return the number of buckets
|
||||
//-----------------------------------------------------------------
|
||||
Integer PCollection_HDataMap::NbBuckets() const
|
||||
{
|
||||
return Buckets->Length();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// IsEmpty : Return TRUE if the map is empty
|
||||
//-----------------------------------------------------------------
|
||||
Boolean PCollection_HDataMap::IsEmpty() const
|
||||
{
|
||||
Handle(PCollection_MapNode) aNode;
|
||||
Boolean Empty = True;
|
||||
for (Integer i = 1 ; i <= Buckets->Length() ; i++) {
|
||||
aNode = Buckets->Value(i);
|
||||
if ( !aNode.IsNull() ) Empty = False;
|
||||
}
|
||||
return Empty;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Extent : Returns the number of couples (item,key) contained in
|
||||
// the map.
|
||||
//-----------------------------------------------------------------
|
||||
Integer PCollection_HDataMap::Extent() const
|
||||
{
|
||||
Integer Number = 0;
|
||||
Handle(PCollection_MapNode) aNode;
|
||||
for (Integer i = 1 ; i <= Buckets->Length() ; i++) {
|
||||
aNode = Buckets->Value(i);
|
||||
while ( !aNode.IsNull() ) {
|
||||
Number++;
|
||||
aNode = aNode->Next();
|
||||
}
|
||||
}
|
||||
return Number;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// IsBound : Returns TRUE if an element is bounded by K
|
||||
//-----------------------------------------------------------------
|
||||
Boolean PCollection_HDataMap::IsBound(const Key& K ) const
|
||||
{
|
||||
Integer Res;
|
||||
Key TheKey;
|
||||
Handle(PCollection_MapNode) aNode;
|
||||
Res = Hash.HashCode (K,Buckets->Length());
|
||||
aNode = Buckets->Value(Res);
|
||||
while ( !aNode.IsNull() ) {
|
||||
TheKey = aNode->GetKey();
|
||||
if ( Hash.Compare(TheKey,K) ) return True;
|
||||
else aNode = aNode->Next();
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Find : Returns the element bounded by K
|
||||
//-----------------------------------------------------------------
|
||||
Item PCollection_HDataMap::Find(const Key& K ) const
|
||||
{
|
||||
Integer Res;
|
||||
Key TheKey;
|
||||
Handle(PCollection_MapNode) aNode;
|
||||
Res = Hash.HashCode (K,Buckets->Length());
|
||||
aNode = Buckets->Value(Res);
|
||||
while ( ! aNode.IsNull() ) {
|
||||
TheKey = aNode->GetKey();
|
||||
if ( Hash.Compare(TheKey,K) ) return aNode->Value();
|
||||
else aNode = aNode->Next();
|
||||
}
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
// ------------------------ WRITING --------------------------------
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Clear : Remove all couples (item,key) from the map.
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_HDataMap::Clear()
|
||||
{
|
||||
Handle(PCollection_MapNode) aNode1,aNode2;
|
||||
for (Integer i = 1 ; i <= Buckets->Length() ; i++) {
|
||||
aNode1 = Buckets->Value(i);
|
||||
aNode2.Nullify();
|
||||
Buckets->SetValue(i,aNode2);
|
||||
while ( ! aNode1.IsNull() ) {
|
||||
aNode2 = aNode1->Next();
|
||||
aNode1.Delete();
|
||||
aNode1 = aNode2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- ----------------------------------------------------------------
|
||||
// Bind : Add a new couple (Item,Key) in the map. The entry point in
|
||||
// the map corresponds to the result of Hashcode function (i.e
|
||||
// HashCode (key)).
|
||||
//- ----------------------------------------------------------------
|
||||
void PCollection_HDataMap::Bind(const Key& K , const Item& T)
|
||||
{
|
||||
Integer Res ;
|
||||
Key TheKey;
|
||||
Handle(PCollection_MapNode) aNode1,aNode2,pnul;
|
||||
pnul.Nullify();
|
||||
aNode1 = new PCollection_MapNode ( K , T , pnul) ;
|
||||
Res = Hash.HashCode (K,Buckets->Length());
|
||||
aNode2 = Buckets->Value(Res);
|
||||
if ( ! aNode2.IsNull()) {
|
||||
while ( ! aNode2.IsNull() ) {
|
||||
TheKey = aNode2->GetKey();
|
||||
if ( Hash.Compare(TheKey,K) ) MultiplyDefined::Raise();
|
||||
aNode2 = aNode2->Next();
|
||||
}
|
||||
aNode2 = Buckets->Value(Res);
|
||||
aNode1->SetNext(aNode2);
|
||||
}
|
||||
Buckets->SetValue(Res,aNode1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Rebind : For an existant couple (Key,AnItem) in the map change
|
||||
// le value of the item.
|
||||
// If the couple does not exist raise an exception
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_HDataMap::Rebind(const Key& K , const Item& T)
|
||||
{
|
||||
Integer Res ;
|
||||
Key TheKey;
|
||||
Handle(PCollection_MapNode) aNode;
|
||||
Res = Hash.HashCode (K,Buckets->Length());
|
||||
aNode = Buckets->Value(Res);
|
||||
while ( ! aNode.IsNull() ) {
|
||||
TheKey = aNode->GetKey();
|
||||
if ( Hash.Compare(TheKey,K) ) {
|
||||
aNode->SetValue(T);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
aNode = aNode->Next();
|
||||
}
|
||||
}
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Unbind : Remove the couple keyed by K
|
||||
// If the couple does not exist raise an exception
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_HDataMap::Unbind(const Key& K)
|
||||
{
|
||||
Integer Res ;
|
||||
Key TheKey;
|
||||
Handle(PCollection_MapNode) aNode,pnul,previous,next;
|
||||
Res = Hash.HashCode (K,Buckets->Length());
|
||||
aNode = Buckets->Value(Res);
|
||||
pnul.Nullify();
|
||||
previous.Nullify();
|
||||
while ( ! aNode.IsNull() ) {
|
||||
TheKey = aNode->GetKey();
|
||||
if ( Hash.Compare(TheKey,K) ) {
|
||||
next = aNode->Next();
|
||||
if (previous.IsNull() && next.IsNull()) { // liste de 1 elt
|
||||
Buckets->SetValue(Res,pnul);
|
||||
aNode.Delete();
|
||||
|
||||
} else if (previous.IsNull()) { // 1er elt de liste
|
||||
Buckets->SetValue(Res,next);
|
||||
aNode.Delete();
|
||||
next.Nullify();
|
||||
|
||||
} else if (next.IsNull()) { // dernier de liste
|
||||
previous->SetNext(pnul);
|
||||
aNode.Delete();
|
||||
|
||||
} else { // milieu de liste
|
||||
previous->SetNext(next);
|
||||
aNode.Delete();
|
||||
next.Nullify();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
else { // pas le bon noeud
|
||||
previous = aNode;
|
||||
aNode = aNode->Next();
|
||||
}
|
||||
}
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// ShallowCopy : ShallowCopy redefinition
|
||||
//-----------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HDataMap::ShallowCopy() const
|
||||
{
|
||||
PCollection_HDataMap* TheCopy = new PCollection_HDataMap (*this);
|
||||
TheCopy->Buckets =
|
||||
Handle(PCollection_Array)::DownCast(::ShallowCopy(Buckets));
|
||||
return TheCopy;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// ShallowDump : ShallowDump redefinition
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_HDataMap::ShallowDump(OStream& S) const
|
||||
{
|
||||
S << "begin class Map "<< endl;
|
||||
if (!IsEmpty())
|
||||
Buckets->ShallowDump(S);
|
||||
else
|
||||
S << "Empty Map." << endl;
|
||||
S << "end of class Map." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
22
src/PCollection/PCollection_HDataMap.lxx
Executable file
22
src/PCollection/PCollection_HDataMap.lxx
Executable file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// inline methods for HMap class from PCollection.
|
||||
// Written by JPT FEB,24 1992
|
||||
// Copyright matra datavision 1992
|
||||
//
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
// Returns the field Buckets associated to the object
|
||||
// --------------------------------------------------
|
||||
inline Handle(PCollection_Array) PCollection_HDataMap::GetArray() const {
|
||||
return Buckets;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Returns the field FH associated to the object
|
||||
// --------------------------------------------------
|
||||
inline FH PCollection_HDataMap::GetFH() const {
|
||||
return Hash;
|
||||
}
|
||||
|
||||
|
696
src/PCollection/PCollection_HDirectedGraph.cdl
Executable file
696
src/PCollection/PCollection_HDirectedGraph.cdl
Executable file
@@ -0,0 +1,696 @@
|
||||
-- File: PCollection_HDirectedGraph.cdl
|
||||
-- Created: Wed Apr 24 16:53:50 1991
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@topsn2>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
---Copyright: Matra Datavision 1991
|
||||
-- Revised: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class HDirectedGraph from PCollection (
|
||||
Item as Storable ;
|
||||
Attribute as Storable)
|
||||
|
||||
---Purpose: Definition of a generic directed graph for a type of
|
||||
-- Item associated to a vertex, and a type of Attribute
|
||||
-- associated to an Edge. A Directed Graph is a
|
||||
-- collection that includes a set of Vertices and a set
|
||||
-- of Edges. A vertex, also called a "Node", forms the
|
||||
-- basic structural element of the graph. Each edge,
|
||||
-- also called an "Arc" defines an oriented link between
|
||||
-- two vertices. In the scheme A->B, vertex A is called
|
||||
-- the SOURCE of the link, B its DESTINATION, and B is
|
||||
-- ADJACENT to A. If there is no edge which destinates
|
||||
-- to a vertex, this vertex is a ROOT of the graph. If
|
||||
-- there is no edge which originates from a vertex, this
|
||||
-- vertex is a LEAF of the graph.
|
||||
|
||||
---Keywords: SOURCE vertex, DESTINATION Vertex, ROOT vertex, LEAF
|
||||
-- vertex, ADJACENT vertex. Depth-first search, breadth, first Search.
|
||||
|
||||
---References: Software Components with ADA (The Benjamin/Cummings
|
||||
-- Company, Inc. 1986).
|
||||
|
||||
|
||||
|
||||
inherits Persistent
|
||||
raises NoSuchObject from Standard,
|
||||
NoMoreObject from Standard
|
||||
|
||||
|
||||
class Edge inherits Persistent
|
||||
|
||||
---Purpose: Defines nested class Edge of a Directed Graph.
|
||||
-- An Edge is an oriented link between two vertices.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create (Source,Destination : Vertex; Value : Attribute)
|
||||
---Purpose: Creates an oriented link between <source> and
|
||||
-- <destination> with an associated attribute. To
|
||||
-- be used only by DirectedGraph methods to
|
||||
-- create and add an edge to a given graph.
|
||||
returns mutable Edge;
|
||||
|
||||
GetAttribute (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns attribute associated to <me>.
|
||||
returns Attribute;
|
||||
|
||||
SetAttribute (me : mutable; Value : Attribute)
|
||||
---Level: Internal
|
||||
---Purpose: To associate an attribute to <me>.
|
||||
is private;
|
||||
|
||||
Source (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex which originates from <me>.
|
||||
returns mutable Vertex;
|
||||
|
||||
SetSource (me :mutable; V: Vertex)
|
||||
---Level: Internal
|
||||
---Purpose: Sets the vertex which originates from <me>.
|
||||
is private;
|
||||
|
||||
Destination (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex which destinates to <me>.
|
||||
returns mutable Vertex;
|
||||
|
||||
SetDestination (me :mutable ; V: Vertex)
|
||||
---Level: Internal
|
||||
---Purpose: Sets the vertex which destinates to <me>.
|
||||
is private;
|
||||
|
||||
Reverse (me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Reverse the orientation of <me>.
|
||||
-- The source vertex becomes the destination vertex, and
|
||||
-- the destination becomes the source.
|
||||
|
||||
IsLoop (me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the fields <MyDestination> and
|
||||
-- <Mysource> are equal.
|
||||
|
||||
fields
|
||||
MyAttribute : Attribute;
|
||||
MySource : Vertex;
|
||||
MyDestination : Vertex;
|
||||
|
||||
friends class HDirectedGraph from PCollection,
|
||||
class Vertex from PCollection
|
||||
|
||||
end;
|
||||
|
||||
class SetOfEdge instantiates HSet from PCollection(Edge);
|
||||
---Purpose: Defines nested class SetOfEdge used as field of
|
||||
-- Vertex and DirectedGraph.
|
||||
|
||||
class SetOfVertex instantiates HSet from PCollection(Vertex);
|
||||
---Purpose: Defines nested class SetOfVertex used as field of a
|
||||
-- DirectedGraph.
|
||||
|
||||
class StackOfVertex instantiates HStack from PCollection(Vertex);
|
||||
---Purpose: Defines nested class StackOfVertex used as field of
|
||||
-- DepthFirstIterator class.
|
||||
|
||||
|
||||
class QueueOfVertex instantiates HQueue from PCollection(Vertex);
|
||||
---Purpose: Defines nested class QueueOfVertex used as field of
|
||||
-- BreadthFirstIterator.
|
||||
|
||||
class FrontEdgesIterator
|
||||
---Purpose: Defines nested class FrontEdgesIterator, to visit
|
||||
-- every edge that originates from a given vertex.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create (aVertex : Vertex) returns FrontEdgesIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other edges.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Set the iterator to the next Edge.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the edge value for the current
|
||||
-- position of the iterator.
|
||||
returns any Edge
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting all edges.
|
||||
|
||||
fields
|
||||
MyEdgeIterator : SetIteratorOfSetOfEdge;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class BackEdgesIterator
|
||||
---Purpose: Defines nested class BackEdgesIterator, to visit
|
||||
-- every edge that destinates to a given vertex.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aVertex : Vertex) returns BackEdgesIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other edges.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next edge.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the edge value for the current
|
||||
-- position of the iterator.
|
||||
returns any Edge
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting all edges.
|
||||
|
||||
fields
|
||||
MyEdgeIterator : SetIteratorOfSetOfEdge;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class DepthFirstIterator
|
||||
---Purpose: Defines nested class DepthFirstIterator, to visit
|
||||
-- every vertex that depends of a given one. Depth
|
||||
-- First Search is functionnally the equivalent of a
|
||||
-- preorder tree traversal. We start at a given
|
||||
-- Vertex V and recursively visit all adjacent
|
||||
-- unvisited Vertices.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create (aVertex : Vertex) returns DepthFirstIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting
|
||||
-- all vertices.
|
||||
|
||||
fields
|
||||
Visited : SetOfVertex;
|
||||
Ready : StackOfVertex;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class BreadthFirstIterator
|
||||
---Purpose: Defines nested class BreadthFirstIterator, to visit
|
||||
-- every vertex that depends of a given one. We start
|
||||
-- at a given vertex V, visit all its adjacent
|
||||
-- vertices, and then recursively visit the unvisited
|
||||
-- adjacent vertices of these previous ones.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create (aVertex : Vertex) returns BreadthFirstIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting
|
||||
-- all vertices.
|
||||
|
||||
fields
|
||||
Visited : SetOfVertex;
|
||||
Ready : QueueOfVertex;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class AdjacentVerticesIterator
|
||||
|
||||
---Purpose: Defines nested class AdjacentVerticesIterator, to
|
||||
-- visit every adjacent vertex of a given one
|
||||
-- (Destination vertices of its front edges).
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aVertex : Vertex) returns AdjacentVerticesIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting all vertices.
|
||||
|
||||
fields
|
||||
MyEdgeIterator : SetIteratorOfSetOfEdge;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
----------------------- Class Vertex ----------------------------------
|
||||
|
||||
class Vertex inherits Persistent
|
||||
---Purpose: Defines nested class vertex of a DirectedGraph. The
|
||||
-- Vertex is the basic element of a graph.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create (Value : Item ; InGraph : HDirectedGraph)
|
||||
---Purpose: Creates a vertex with an associated item. To
|
||||
-- be used only by DirectedGraph methods to
|
||||
-- create and add a vertex to a given graph.
|
||||
returns mutable Vertex;
|
||||
|
||||
GetItem (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns item associated to <me>.
|
||||
returns any Item;
|
||||
|
||||
SetItem (me : mutable; value : Item)
|
||||
---Level: Internal
|
||||
---Purpose: Associates an item to <me>.
|
||||
is private;
|
||||
|
||||
GetGraph (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the HDirectedGraph which owns <me>.
|
||||
returns HDirectedGraph;
|
||||
|
||||
AddFrontEdge (me : mutable; anEdge : Edge)
|
||||
---Level: Internal
|
||||
---Purpose: To add an edge that destinates to <me>.
|
||||
-- To be used only by editing methods of a DirectedGraph.
|
||||
-- Returns False if the edge already exists.
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
RemoveFrontEdge (me : mutable; anEdge : Edge)
|
||||
---Level: Internal
|
||||
---Purpose: To remove an edge that originates from <me>.
|
||||
-- To be used only by editing methods of a DirectedGraph.
|
||||
-- An exception is raised if <anEdge> doesn't belong to
|
||||
-- myFrontEdges field.
|
||||
raises NoSuchObject from Standard
|
||||
is private;
|
||||
|
||||
NbFrontEdges (me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of edges which originates from <me>.
|
||||
|
||||
GetFrontEdges (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns "myFrontEdges" Field for Iterator.
|
||||
returns SetOfEdge
|
||||
is private;
|
||||
|
||||
AddBackEdge (me : mutable; anEdge : Edge)
|
||||
---Level: Internal
|
||||
---Purpose: To add an edge that destinates to <me>. To be
|
||||
-- used only by editing methods of a
|
||||
-- DirectedGraph, to update it after
|
||||
-- modifications. Returns False if the edge already exists.
|
||||
returns Boolean from Standard
|
||||
is private;
|
||||
|
||||
RemoveBackEdge (me : mutable; anEdge : Edge)
|
||||
---Level: Internal
|
||||
---Purpose: To remove an edge that destinates to <me>. To
|
||||
-- be used only by editing methods of a
|
||||
-- DirectedGraph, to update it after
|
||||
-- modifications. An exception is raised if
|
||||
-- <anEdge> doesn't belong to myBackEdges field.
|
||||
raises NoSuchObject from Standard
|
||||
is private;
|
||||
|
||||
NbBackEdges (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of edge which destinates to <me>.
|
||||
returns Integer from Standard;
|
||||
|
||||
GetBackEdges (me)
|
||||
---Level: Internal
|
||||
---Purpose: Returns "myBackEdges" field for Iterator.
|
||||
returns SetOfEdge
|
||||
is private;
|
||||
|
||||
IsRoot (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if NbBackEdges = 0.
|
||||
returns Boolean from Standard;
|
||||
|
||||
IsLeaf (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if NbFrontEdges = 0.
|
||||
returns Boolean from Standard;
|
||||
|
||||
IsDestination (me; aVertex : Vertex)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if it exists an edge which
|
||||
-- originates from <me> and destinates to <aVertex>.
|
||||
returns Boolean from Standard;
|
||||
|
||||
IsSource (me; aVertex : Vertex)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if it exists an edge which
|
||||
-- originates from <aVertex> and destinates to <me>.
|
||||
returns Boolean from Standard;
|
||||
|
||||
fields
|
||||
MyItem : Item;
|
||||
MyGraph : HDirectedGraph;
|
||||
MyFrontEdges : SetOfEdge;
|
||||
MyBackEdges : SetOfEdge;
|
||||
|
||||
friends class HDirectedGraph from PCollection,
|
||||
class Edge from PCollection,
|
||||
class BackEdgesIterator from PCollection,
|
||||
class FrontEdgesIterator from PCollection,
|
||||
class DepthFirstIterator from PCollection,
|
||||
class BreadthFirstIterator from PCollection,
|
||||
class AdjacentVerticesIterator from PCollection
|
||||
end;
|
||||
|
||||
|
||||
class VerticesIterator
|
||||
---Purpose: Defines nested class VerticesIterator, to visit
|
||||
-- every vertex of a given directed graph.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aGraph : HDirectedGraph) returns VerticesIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting
|
||||
-- all vertices.
|
||||
|
||||
fields
|
||||
MyVertexIterator : SetIteratorOfSetOfVertex;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class RootsIterator
|
||||
---Purpose: Defines nested class RootsIterator, to visit every
|
||||
-- "root" vertex of a directed graph.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aGraph : HDirectedGraph) returns RootsIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting
|
||||
-- all vertices.
|
||||
|
||||
fields
|
||||
MyVertexIterator : SetIteratorOfSetOfVertex;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class LeavesIterator
|
||||
---Purpose: Defines nested class LeavesIterator, to visit every
|
||||
-- "leaf" vertex of a directed graph.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aGraph : HDirectedGraph) returns LeavesIterator;
|
||||
|
||||
More (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Set the iterator to the next vertex.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
returns any Vertex
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting
|
||||
-- all vertices.
|
||||
|
||||
fields
|
||||
MyVertexIterator : SetIteratorOfSetOfVertex;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
class EdgesIterator
|
||||
---Purpose: Defines nested class EdgesIterator, to visit every
|
||||
-- edge of a directed graph.
|
||||
|
||||
raises NoMoreObject from Standard ,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
Create (aGraph : HDirectedGraph) returns EdgesIterator;
|
||||
|
||||
More (me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if there are other edges.
|
||||
|
||||
Next (me : in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next edge.
|
||||
|
||||
Value (me)
|
||||
---Level: Public
|
||||
---Purpose: Returns the edge value for the current
|
||||
-- position of the iterator.
|
||||
returns any Edge
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Clear (me : in out);
|
||||
---Level: Public
|
||||
---Purpose: To clear the iterator before having visiting all edges.
|
||||
|
||||
fields
|
||||
MyEdgeIterator : SetIteratorOfSetOfEdge;
|
||||
HasMore : Boolean from Standard;
|
||||
end;
|
||||
|
||||
--------------------- class HDirectedGraph -----------------------------
|
||||
|
||||
is
|
||||
|
||||
Create returns mutable HDirectedGraph;
|
||||
---Purpose: Creates an empty Directed Graph.
|
||||
|
||||
NumberOfVertices (me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
|
||||
NumberOfEdges (me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
|
||||
NumberOfLeaves (me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of "leaf" vertices of <me>.
|
||||
|
||||
NumberOfRoots (me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of "root" vertices of <me>.
|
||||
|
||||
IsEmpty (me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
Clear (me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all edges and vertices of <me>.
|
||||
|
||||
IsMember (me; aVertex : Vertex) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
IsMember (me; anEdge : Edge) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
Add (me : mutable; Value : Item)
|
||||
---Level: Public
|
||||
---Purpose: Creates and Adds a vertex, with a given value
|
||||
-- <value>, to <me>. Of course this new Vertex is a
|
||||
-- "root" and "leaf" vertex of <me> because it has no
|
||||
-- connexion with other vertices of the directed graph.
|
||||
returns mutable Vertex;
|
||||
|
||||
Remove (me : mutable; aVertex : mutable Vertex)
|
||||
---Level: Public
|
||||
---Purpose: Removes <aVertex> from <me>. Removes also all the
|
||||
-- edges of <me> which reference <aVertex>; Updates
|
||||
-- Source and Destination vertices of each of these
|
||||
-- edges . Raises an exception if <aVertex> is not
|
||||
-- member of <me>.
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Add (me : mutable; Source : mutable Vertex;
|
||||
Destination : mutable Vertex; Value : Attribute)
|
||||
---Level: Public
|
||||
---Purpose: Creates and adds an edge from <source> to
|
||||
-- <destination>, with the attribute <value>, to
|
||||
-- <me>. Updates Source and Destination Vertices of
|
||||
-- this new edge. Raises an exception if <source> or
|
||||
-- <destination> are not members of <me>.
|
||||
returns mutable Edge
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Remove (me : mutable; AnEdge : mutable Edge)
|
||||
---Level: Public
|
||||
---Purpose: Removes <anEdge> from <me>. And Updates Source
|
||||
-- and Destination Vertices of <anEdge>. Raises an
|
||||
-- exception if <Edge> is not member of <me>.
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
GetVertices (me)
|
||||
---Level: Internal
|
||||
---Purpose: Returns "myVertices" field for Iterator.
|
||||
returns SetOfVertex
|
||||
is private;
|
||||
|
||||
GetEdges (me)
|
||||
---Level: Internal
|
||||
---Purpose: Returns "myEdges" field for Iterator.
|
||||
returns SetOfEdge
|
||||
is private;
|
||||
|
||||
ShallowCopy(me) returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
fields
|
||||
MyVertices : SetOfVertex;
|
||||
MyEdges : SetOfEdge;
|
||||
|
||||
friends class VerticesIterator from PCollection,
|
||||
class RootsIterator from PCollection,
|
||||
class LeavesIterator from PCollection,
|
||||
class EdgesIterator from PCollection
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
180
src/PCollection/PCollection_HDirectedGraph.gxx
Executable file
180
src/PCollection/PCollection_HDirectedGraph.gxx
Executable file
@@ -0,0 +1,180 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_HDirectedGraph.gxx
|
||||
// Created: Wed May 29 17:06:01 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised: Mireille MERCIEN
|
||||
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
PCollection_HDirectedGraph::PCollection_HDirectedGraph ()
|
||||
{
|
||||
MyVertices = new PCollection_SetOfVertex;
|
||||
MyEdges = new PCollection_SetOfEdge;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Integer PCollection_HDirectedGraph::NumberOfVertices () const
|
||||
{
|
||||
return MyVertices->Extent();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Integer PCollection_HDirectedGraph::NumberOfEdges () const
|
||||
{
|
||||
return MyEdges->Extent();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Integer PCollection_HDirectedGraph::NumberOfLeaves () const
|
||||
{
|
||||
Integer nb = 0;
|
||||
PCollection_SetIteratorOfSetOfVertex It (MyVertices);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Vertex) V = It.Value();
|
||||
if (V->IsLeaf()) nb++;
|
||||
It.Next();
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Integer PCollection_HDirectedGraph::NumberOfRoots () const
|
||||
{
|
||||
Integer nb = 0;
|
||||
PCollection_SetIteratorOfSetOfVertex It(MyVertices);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Vertex) V = It.Value();
|
||||
if (V->IsRoot()) nb++;
|
||||
It.Next();
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Boolean PCollection_HDirectedGraph::IsEmpty () const
|
||||
{
|
||||
return (MyVertices->Extent() == 0);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
void PCollection_HDirectedGraph::Clear ()
|
||||
{
|
||||
MyVertices = new PCollection_SetOfVertex;
|
||||
MyEdges = new PCollection_SetOfEdge;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Boolean PCollection_HDirectedGraph::IsMember
|
||||
(const Handle(PCollection_Vertex)& V) const
|
||||
{
|
||||
return MyVertices->Contains(V);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Boolean PCollection_HDirectedGraph::IsMember
|
||||
(const Handle(PCollection_Edge)& E) const
|
||||
{
|
||||
return MyEdges->Contains(E);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_HDirectedGraph::Add
|
||||
(const Item& val)
|
||||
{
|
||||
Handle(PCollection_Vertex) V = new PCollection_Vertex (val,this);
|
||||
MyVertices->Add(V);
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
void PCollection_HDirectedGraph::Remove (const Handle(PCollection_Vertex)& V)
|
||||
{
|
||||
if (IsMember(V)) {
|
||||
PCollection_BackEdgesIterator ItBack(V);
|
||||
while (ItBack.More()) {
|
||||
Handle(PCollection_Edge) BE = ItBack.Value();
|
||||
if (BE->Source() != V) BE->Source()->RemoveFrontEdge(BE);
|
||||
MyEdges->Remove(BE);
|
||||
ItBack.Next();
|
||||
}
|
||||
PCollection_FrontEdgesIterator ItFront(V);
|
||||
while (ItFront.More()) {
|
||||
Handle(PCollection_Edge) FE = ItFront.Value();
|
||||
if (FE->Destination() != V) FE->Destination()->RemoveBackEdge(FE);
|
||||
if (MyEdges->Contains(FE)) MyEdges->Remove(FE);
|
||||
ItFront.Next();
|
||||
}
|
||||
MyVertices->Remove(V);
|
||||
// V->Nullify(); // test Handle nul sur Vertex retire
|
||||
}
|
||||
else {
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Handle(PCollection_Edge) PCollection_HDirectedGraph::Add
|
||||
(const Handle(PCollection_Vertex)& source,
|
||||
const Handle(PCollection_Vertex)& destination,
|
||||
const Attribute& A)
|
||||
{
|
||||
if (IsMember(source) && IsMember(destination)) {
|
||||
Handle(PCollection_Edge) E = new PCollection_Edge (source,destination,A);
|
||||
source->AddFrontEdge (E);
|
||||
destination->AddBackEdge(E);
|
||||
MyEdges->Add (E);
|
||||
return E;
|
||||
}
|
||||
else {
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
void PCollection_HDirectedGraph::Remove (const Handle(PCollection_Edge)& E)
|
||||
{
|
||||
if (IsMember(E)) {
|
||||
(E->Source())->RemoveFrontEdge(E);
|
||||
(E->Destination())->RemoveBackEdge(E);
|
||||
MyEdges->Remove(E);
|
||||
// E->Nullify(); // test Handle nul sur Edge retire
|
||||
}
|
||||
else {
|
||||
NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Handle(PCollection_SetOfVertex) PCollection_HDirectedGraph::GetVertices() const
|
||||
{
|
||||
return MyVertices;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
Handle(PCollection_SetOfEdge) PCollection_HDirectedGraph::GetEdges() const
|
||||
{
|
||||
return MyEdges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
123
src/PCollection/PCollection_HDoubleList.cdl
Executable file
123
src/PCollection/PCollection_HDoubleList.cdl
Executable file
@@ -0,0 +1,123 @@
|
||||
-- File: PCollection_HDoubleList.cdl
|
||||
-- Created: Wed Feb 19 14:24:56 1992
|
||||
-- Author: Jean Pierre TIRAULT
|
||||
-- <jpt@topsn1>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
generic class HDoubleList from PCollection (Item as Storable)
|
||||
inherits PManaged
|
||||
|
||||
|
||||
raises NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
---Purpose: Definition of a double linked list
|
||||
-- Idem to the SingleList with a pointer to the previous node
|
||||
|
||||
|
||||
Create returns mutable HDoubleList;
|
||||
---Purpose: Creation of an empty list
|
||||
|
||||
IsEmpty(me) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the list contains no element.
|
||||
|
||||
Construct(me : mutable; T : Item) returns mutable HDoubleList;
|
||||
---Level: Public
|
||||
---Purpose: Adds T at the begining of me.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- (T A B C)
|
||||
|
||||
Value(me) returns any Item
|
||||
raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Value of the first node of me
|
||||
-- Raises an exception if me is empty
|
||||
---Purpose: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- A
|
||||
|
||||
Tail(me) returns any HDoubleList
|
||||
raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Returns the end of the list <me>.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- (B C)
|
||||
|
||||
Previous(me) returns any HDoubleList
|
||||
raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Previous node of me.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- A list L = (A B C) with me = (B C) a sub-list of L.
|
||||
-- after
|
||||
-- L = (A B C), me = (B C)
|
||||
-- returns
|
||||
-- (A)
|
||||
|
||||
SwapTail(me : mutable; WithList : in out any HDoubleList)
|
||||
raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Exchanges end of me with WithList.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- WithList = (D E)
|
||||
-- after
|
||||
-- me = (A D E)
|
||||
-- WithList = (B C)
|
||||
|
||||
SetValue(me : mutable; T : Item)
|
||||
raises NoSuchObject;
|
||||
---Level: Public
|
||||
---Purpose: Changes the value of the first node of me.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (T B C)
|
||||
|
||||
|
||||
ChangeBackPointer(me : mutable; BackPointer : HDoubleList);
|
||||
---Level: Public
|
||||
---Purpose: Modification of the backward pointer
|
||||
|
||||
ChangeForwardPointer(me : mutable; ForwardPointer :
|
||||
HDoubleList);
|
||||
---Level: Public
|
||||
---Purpose: Modification of the forward pointer
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
Destroy(me : mutable);
|
||||
---C++: alias ~
|
||||
|
||||
fields
|
||||
Data : Item;
|
||||
Next : HDoubleList;
|
||||
Before : HDoubleList;
|
||||
|
||||
end HDoubleList;
|
170
src/PCollection/PCollection_HDoubleList.gxx
Executable file
170
src/PCollection/PCollection_HDoubleList.gxx
Executable file
@@ -0,0 +1,170 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - HDoubleList -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
PCollection_HDoubleList::PCollection_HDoubleList ( ){
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
Handle(PCollection_HDoubleList)
|
||||
PCollection_HDoubleList::Construct(const Item& T)
|
||||
{
|
||||
|
||||
Handle(PCollection_HDoubleList) me , L ;
|
||||
me = this;
|
||||
L = new PCollection_HDoubleList;
|
||||
L->ChangeForwardPointer ( me ); // Pointeur avant de L sur me.
|
||||
Before = L; // Pointer arriere de me sur L.
|
||||
L->SetValue ( T ); // Mettre la valeur de l'item.
|
||||
return L; // C'est L qui est retourne.
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HDoubleList::ShallowCopy() const
|
||||
{
|
||||
|
||||
Handle(PCollection_HDoubleList) TheList, // Traversal depth of <this>
|
||||
TheCopy, // The list returned
|
||||
Pred, // Backward pointer
|
||||
Succ, // Forward pointer
|
||||
Last; // Last cell
|
||||
|
||||
TheCopy = new PCollection_HDoubleList; // Initialization of the list
|
||||
// that will be returned
|
||||
Standard_Boolean FirstTime = Standard_True;
|
||||
|
||||
TheList = this; // Start at the beginning
|
||||
Pred = Succ = TheCopy;
|
||||
|
||||
while ( ! TheList->IsEmpty() ) { // Append each item at the
|
||||
Succ = Succ->Construct(TheList->Value()); // end of the list
|
||||
if ( FirstTime ){
|
||||
FirstTime = Standard_False;
|
||||
TheCopy = Succ;
|
||||
}
|
||||
else{
|
||||
Pred->ChangeForwardPointer(Succ); // Make the link between
|
||||
Succ->ChangeBackPointer(Pred); // Pred and Succ
|
||||
}
|
||||
Pred = Succ;
|
||||
Succ = Succ->Tail();
|
||||
TheList = TheList->Tail();
|
||||
}
|
||||
return TheCopy; // Returns the header
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
void PCollection_HDoubleList::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
Handle(PCollection_HDoubleList) TheList;
|
||||
TheList = this;
|
||||
S << "begin class HDoubleList " << endl;
|
||||
while ( ! TheList->IsEmpty() ) {
|
||||
::ShallowDump(TheList->Value(), S);
|
||||
TheList = TheList->Tail();
|
||||
}
|
||||
S << "end of HDoubleList." << endl;
|
||||
}
|
||||
|
||||
|
||||
/* Anciens INLINE */
|
||||
|
||||
|
||||
void PCollection_HDoubleList::ChangeForwardPointer
|
||||
(const Handle(PCollection_HDoubleList)& L)
|
||||
{
|
||||
Next = L;
|
||||
}
|
||||
|
||||
void PCollection_HDoubleList::ChangeBackPointer
|
||||
(const Handle(PCollection_HDoubleList)& L)
|
||||
{
|
||||
Before = L;
|
||||
}
|
||||
|
||||
|
||||
void PCollection_HDoubleList::SetValue(const Item& T)
|
||||
{
|
||||
Standard_NoSuchObject_Raise_if (IsEmpty(),
|
||||
"Empty Element in HDoubleList::SetValue");
|
||||
Data = T;
|
||||
}
|
||||
|
||||
|
||||
Item PCollection_HDoubleList::Value() const {
|
||||
Standard_NoSuchObject_Raise_if(IsEmpty(),
|
||||
"Empty Element in HDoubleList::Value");
|
||||
return Data;
|
||||
}
|
||||
|
||||
Handle(PCollection_HDoubleList) PCollection_HDoubleList::Previous() const {
|
||||
Standard_NoSuchObject_Raise_if((IsEmpty() && Before.IsNull()),
|
||||
"Empty Element in HDoubleList::Previous");
|
||||
return Before;
|
||||
}
|
||||
|
||||
|
||||
Standard_Boolean PCollection_HDoubleList::IsEmpty()const
|
||||
{
|
||||
return Next.IsNull();
|
||||
}
|
||||
|
||||
|
||||
Handle(PCollection_HDoubleList) PCollection_HDoubleList::Tail() const {
|
||||
Standard_NoSuchObject_Raise_if(IsEmpty(),
|
||||
"Empty Element in HDoubleList::Previous");
|
||||
return Next;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// - -
|
||||
// - -
|
||||
// - -
|
||||
// -----------------------------------------------------------------------
|
||||
void PCollection_HDoubleList::SwapTail(Handle(PCollection_HDoubleList)&
|
||||
WithList)
|
||||
{
|
||||
// Exception si liste vide
|
||||
Standard_NoSuchObject_Raise_if(IsEmpty(),
|
||||
"Empty Element in HDoubleList::SwapTail") ;
|
||||
|
||||
Handle(PCollection_HDoubleList) L = Next;
|
||||
Handle(PCollection_HDoubleList) me ;
|
||||
me = this;
|
||||
WithList->ChangeBackPointer(me);
|
||||
Next = WithList;
|
||||
WithList = L;
|
||||
}
|
||||
|
||||
void PCollection_HDoubleList::Destroy()
|
||||
{
|
||||
#ifdef CSFDB
|
||||
Next.Nullify();
|
||||
#endif
|
||||
}
|
197
src/PCollection/PCollection_HDoubleMap.cdl
Executable file
197
src/PCollection/PCollection_HDoubleMap.cdl
Executable file
@@ -0,0 +1,197 @@
|
||||
---Copyright: Matra Datavision 1992
|
||||
---Version:
|
||||
|
||||
---History:
|
||||
-- Version Date Purpose
|
||||
-- 10/12/92 Creation
|
||||
|
||||
|
||||
generic class HDoubleMap from PCollection ( Key as Storable ;
|
||||
Item as Storable ;
|
||||
KeyHash as Hash(Key) ;
|
||||
ItemHash as Hash(Item) )
|
||||
|
||||
---Purpose: A double map is a Collection of bindings between two objects.
|
||||
-- It can be retrieved either by its Key or its Item;a hash code
|
||||
-- value must be computed for both.
|
||||
|
||||
inherits Persistent from Standard
|
||||
|
||||
raises
|
||||
|
||||
MultiplyDefined from Standard,
|
||||
NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
|
||||
class DoubleMapNode from PCollection inherits PManaged from PMMgt
|
||||
---Purpose: Class used in the implementation of the DoubleMap class. It stores
|
||||
-- Key and Item and two references to DoubleMapNode, one used to make Hashed
|
||||
-- list for Key , the other to make Hashed list for Item.
|
||||
|
||||
is
|
||||
|
||||
Create( aKey : Key ; anItem : Item ; nextKey : DoubleMapNode ;
|
||||
nextItem : DoubleMapNode ) returns mutable DoubleMapNode;
|
||||
---Purpose: Creates a DoubleMapNode.
|
||||
|
||||
SetNextKey ( me : mutable ; aNode : DoubleMapNode ) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the next node of Key hashed list.
|
||||
|
||||
SetNextItem ( me : mutable ; aNode : DoubleMapNode ) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the next node of Item hashed list.
|
||||
|
||||
GetKey ( me ) returns any Key is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the key.
|
||||
|
||||
GetItem ( me ) returns any Item is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the item.
|
||||
|
||||
NextKey ( me ) returns any DoubleMapNode is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the next node of Key hashed list.
|
||||
|
||||
NextItem ( me ) returns any DoubleMapNode is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the next node of Item hashed list.
|
||||
|
||||
fields
|
||||
|
||||
myKey : Key;
|
||||
myItem : Item;
|
||||
myNextKey : DoubleMapNode;
|
||||
myNextItem : DoubleMapNode;
|
||||
|
||||
end DoubleMapNode;
|
||||
|
||||
class ArrayDoubleMap instantiates HArray1 from PCollection (DoubleMapNode);
|
||||
|
||||
|
||||
class DoubleMapIterator
|
||||
|
||||
---Purpose: This class provides services to iterate on all bindings of
|
||||
-- a DoubleMap.
|
||||
|
||||
raises
|
||||
|
||||
NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create ( aDoubleMap : HDoubleMap from PCollection)
|
||||
returns DoubleMapIterator;
|
||||
---Purpose: Creates an iterator of <aDoubleMap>.
|
||||
|
||||
More ( me ) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if there are others couples (Item,Key).
|
||||
|
||||
Next ( me : in out )
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next couple (Item,Key).
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
KeyValue ( me ) returns Key
|
||||
---Level: Public
|
||||
---Purpose: Returns the Key value corresponding to the current position
|
||||
-- of the iterator.
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
ItemValue ( me ) returns Item
|
||||
---Level: Public
|
||||
---Purpose: Returns the Item value corresponding to the current position
|
||||
-- of the iterator.
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
|
||||
myBuckets : ArrayDoubleMap;
|
||||
myCurrentIndex : Integer;
|
||||
myCurrentNode : DoubleMapNode;
|
||||
|
||||
end DoubleMapIterator;
|
||||
|
||||
is
|
||||
|
||||
Create ( NbBuckets : Integer; fhKey : KeyHash; fhItem : ItemHash )
|
||||
returns mutable HDoubleMap;
|
||||
---Purpose: Creates a double map of <NbBuckets> entries.
|
||||
|
||||
NbBuckets ( me ) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of entries in the double map <me>.
|
||||
|
||||
Extent ( me ) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of couples (<Key>,<Item>) stored in <me>.
|
||||
|
||||
Bind ( me : mutable ; aKey : Key; anItem : Item )
|
||||
---Level: Public
|
||||
---Purpose: Adds the pair (<aKey>,<anItem>) to <me>.
|
||||
---Trigger: Raises an exception if the binding already exists.
|
||||
raises MultiplyDefined from Standard;
|
||||
|
||||
FindItem ( me ; aKey : Key ) returns any Item
|
||||
---Level: Public
|
||||
---Purpose: Returns the item bounded by <aKey>.
|
||||
---Trigger: Raises an exception if the binding does not exist.
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
FindKey ( me ; anItem : Item ) returns any Key
|
||||
---Level: Public
|
||||
---Purpose: Returns the key bounded by <anItem>.
|
||||
raises NoSuchObject from Standard;
|
||||
---Trigger: Raises if the binding does not exist.
|
||||
|
||||
UnbindKey ( me : mutable ; aKey : Key )
|
||||
---Level: Public
|
||||
---Purpose: Unbinds the couple keyed by <aKey>.
|
||||
raises NoSuchObject from Standard;
|
||||
---Trigger: Raises if the binding does not exist.
|
||||
|
||||
UnbindItem ( me : mutable ; anItem : Item )
|
||||
---Level: Public
|
||||
---Purpose: Unbinds the couple keyed by <anItem>.
|
||||
raises NoSuchObject from Standard;
|
||||
---Trigger: Raises if the binding does not exist.
|
||||
|
||||
Clear ( me : mutable );
|
||||
---Level: Public
|
||||
---Purpose: Clears the double map.
|
||||
|
||||
IsBoundByKey ( me ; aKey : Key ) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if an element is bound by <aKey>.
|
||||
|
||||
IsBoundByItem ( me ; anItem : Item ) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if an element is bound by <anItem>.
|
||||
|
||||
IsEmpty ( me ) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the DoubleMap <me> is empty.
|
||||
|
||||
GetArrayKey ( me ) returns ArrayDoubleMap is static private;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the ArrayDoubleMap for Key.
|
||||
|
||||
fields
|
||||
|
||||
myNumber : Integer; -- Number of couples
|
||||
myArrayKey : ArrayDoubleMap;
|
||||
myArrayItem : ArrayDoubleMap;
|
||||
myKeyHash : KeyHash;
|
||||
myItemHash : ItemHash;
|
||||
|
||||
friends
|
||||
|
||||
class DoubleMapIterator from PCollection
|
||||
|
||||
end HDoubleMap;
|
||||
|
||||
|
311
src/PCollection/PCollection_HDoubleMap.gxx
Executable file
311
src/PCollection/PCollection_HDoubleMap.gxx
Executable file
@@ -0,0 +1,311 @@
|
||||
//-Copyright: Matra Datavision 1992
|
||||
//-Version:
|
||||
|
||||
//-History:
|
||||
// Version Date Purpose
|
||||
// 14/12/92 Creation
|
||||
|
||||
//-Language C++2.0
|
||||
|
||||
//-Declarations
|
||||
#include <Standard_MultiplyDefined.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
//=======================================================================
|
||||
// Function : HDoubleMap
|
||||
//=======================================================================
|
||||
|
||||
PCollection_HDoubleMap::PCollection_HDoubleMap
|
||||
(
|
||||
const Standard_Integer NbBuckets ,
|
||||
const KeyHash &fhKey,
|
||||
const ItemHash &fhItem )
|
||||
{
|
||||
|
||||
myArrayKey = new PCollection_ArrayDoubleMap(1,NbBuckets);
|
||||
myArrayItem = new PCollection_ArrayDoubleMap(1,NbBuckets);
|
||||
myKeyHash = fhKey;
|
||||
myItemHash = fhItem;
|
||||
myNumber = 0;
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : NbBuckets
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HDoubleMap::NbBuckets() const
|
||||
{
|
||||
return myArrayKey->Length();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Extent
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HDoubleMap::Extent() const
|
||||
{
|
||||
return myNumber;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Bind
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HDoubleMap::Bind (const Key &aKey , const Item &anItem)
|
||||
{
|
||||
Standard_Integer ResHashKey,ResHashItem;
|
||||
Handle(PCollection_DoubleMapNode) theNewNode;
|
||||
|
||||
if ( IsBoundByKey(aKey) || IsBoundByItem(anItem) )
|
||||
Standard_MultiplyDefined::Raise();
|
||||
else {
|
||||
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
|
||||
theNewNode =
|
||||
new PCollection_DoubleMapNode(aKey,anItem,
|
||||
myArrayKey->Value(ResHashKey),
|
||||
myArrayItem->Value(ResHashItem));
|
||||
myArrayKey->SetValue(ResHashKey,theNewNode);
|
||||
myArrayItem->SetValue(ResHashItem,theNewNode);
|
||||
myNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindItem
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_HDoubleMap::FindItem ( const Key &aKey ) const
|
||||
{
|
||||
Standard_Integer ResHashKey;
|
||||
Handle(PCollection_DoubleMapNode) theKeyNode;
|
||||
|
||||
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
theKeyNode = myArrayKey->Value(ResHashKey);
|
||||
while ( ! theKeyNode.IsNull() ) {
|
||||
if ( myKeyHash.Compare(theKeyNode->GetKey(),aKey) )
|
||||
return theKeyNode->GetItem();
|
||||
else theKeyNode = theKeyNode->NextKey();
|
||||
}
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindKey
|
||||
//=======================================================================
|
||||
|
||||
Key PCollection_HDoubleMap::FindKey ( const Item &anItem ) const
|
||||
{
|
||||
Standard_Integer ResHashItem;
|
||||
Handle(PCollection_DoubleMapNode) theItemNode;
|
||||
|
||||
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
|
||||
theItemNode = myArrayItem->Value(ResHashItem);
|
||||
while ( ! theItemNode.IsNull() ) {
|
||||
if ( myItemHash.Compare(theItemNode->GetItem(),anItem) )
|
||||
return theItemNode->GetKey();
|
||||
else theItemNode = theItemNode->NextItem();
|
||||
}
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : UnbindKey
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HDoubleMap::UnbindKey ( const Key &aKey )
|
||||
{
|
||||
Standard_Integer ResHashKey,ResHashItem;
|
||||
Handle(PCollection_DoubleMapNode)
|
||||
currentKeyNode,previousKeyNode,previousItemNode,currentItemNode,nullNode;
|
||||
Standard_Boolean NoKey = Standard_True;
|
||||
Standard_Boolean NoItem = Standard_True;
|
||||
|
||||
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
currentKeyNode = myArrayKey->Value(ResHashKey);
|
||||
while ( NoKey && !currentKeyNode.IsNull() ) {
|
||||
if ( myKeyHash.Compare(currentKeyNode->GetKey(),aKey) )
|
||||
NoKey = Standard_False;
|
||||
else {
|
||||
previousKeyNode = currentKeyNode;
|
||||
currentKeyNode = currentKeyNode->NextKey();
|
||||
}
|
||||
}
|
||||
|
||||
if ( NoKey ) Standard_NoSuchObject::Raise();
|
||||
else {
|
||||
ResHashItem =
|
||||
myItemHash.HashCode(currentKeyNode->GetItem(),myArrayItem->Length());
|
||||
currentItemNode = myArrayItem->Value(ResHashItem);
|
||||
while ( NoItem && !currentItemNode.IsNull() ) {
|
||||
if ( currentItemNode == currentKeyNode ) NoItem = Standard_False;
|
||||
else {
|
||||
previousItemNode = currentItemNode;
|
||||
currentItemNode = currentItemNode->NextItem();
|
||||
}
|
||||
}
|
||||
if ( NoItem ) Standard_NoSuchObject::Raise();
|
||||
else {
|
||||
if ( previousKeyNode.IsNull() )
|
||||
myArrayKey->SetValue(ResHashKey,currentKeyNode->NextKey());
|
||||
else
|
||||
previousKeyNode->SetNextKey(currentKeyNode->NextKey());
|
||||
|
||||
if ( previousItemNode.IsNull() )
|
||||
myArrayItem->SetValue(ResHashItem,currentItemNode->NextItem());
|
||||
else
|
||||
previousItemNode->SetNextItem(currentItemNode->NextItem());
|
||||
|
||||
myNumber--;
|
||||
currentKeyNode->SetNextKey(nullNode);
|
||||
currentKeyNode->SetNextItem(nullNode);
|
||||
currentKeyNode.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : UnbindItem
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HDoubleMap::UnbindItem ( const Item &anItem )
|
||||
{
|
||||
Standard_Integer ResHashKey,ResHashItem;
|
||||
Handle(PCollection_DoubleMapNode)
|
||||
currentKeyNode,previousKeyNode,previousItemNode,currentItemNode,nullNode;
|
||||
Standard_Boolean NoKey = Standard_True;
|
||||
Standard_Boolean NoItem = Standard_True;
|
||||
|
||||
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
|
||||
currentItemNode = myArrayItem->Value(ResHashItem);
|
||||
while ( NoItem && !currentItemNode.IsNull() ) {
|
||||
if ( myItemHash.Compare(currentItemNode->GetItem(),anItem) )
|
||||
NoItem = Standard_False;
|
||||
else {
|
||||
previousItemNode = currentItemNode;
|
||||
currentItemNode = currentItemNode->NextItem();
|
||||
}
|
||||
}
|
||||
|
||||
if ( NoItem ) Standard_NoSuchObject::Raise();
|
||||
else {
|
||||
ResHashKey =
|
||||
myKeyHash.HashCode(currentItemNode->GetKey(),myArrayKey->Length());
|
||||
currentKeyNode = myArrayKey->Value(ResHashKey);
|
||||
while ( NoKey && !currentKeyNode.IsNull() ) {
|
||||
if ( currentKeyNode == currentItemNode ) NoKey = Standard_False;
|
||||
else {
|
||||
previousKeyNode = currentKeyNode;
|
||||
currentKeyNode = currentKeyNode->NextKey();
|
||||
}
|
||||
}
|
||||
if ( NoKey ) Standard_NoSuchObject::Raise();
|
||||
else {
|
||||
if ( previousItemNode.IsNull() )
|
||||
myArrayItem->SetValue(ResHashItem,currentItemNode->NextItem());
|
||||
else
|
||||
previousItemNode->SetNextItem(currentItemNode->NextItem());
|
||||
|
||||
if ( previousKeyNode.IsNull() )
|
||||
myArrayKey->SetValue(ResHashKey,currentKeyNode->NextKey());
|
||||
else
|
||||
previousKeyNode->SetNextKey(currentKeyNode->NextKey());
|
||||
|
||||
myNumber--;
|
||||
currentItemNode->SetNextItem(nullNode);
|
||||
currentItemNode->SetNextKey(nullNode);
|
||||
currentItemNode.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Clear
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HDoubleMap::Clear ()
|
||||
{
|
||||
Handle(PCollection_DoubleMapNode) nullNode,theNode,delNode;
|
||||
Standard_Integer I;
|
||||
|
||||
myNumber = 0;
|
||||
|
||||
for ( I = 1 ; I <= myArrayItem->Length() ; I++ ) {
|
||||
theNode = myArrayItem->Value(I);
|
||||
myArrayKey->SetValue(I,nullNode);
|
||||
myArrayItem->SetValue(I,nullNode);
|
||||
while ( !theNode.IsNull() ) {
|
||||
delNode = theNode;
|
||||
theNode = theNode->NextItem();
|
||||
delNode->SetNextKey(nullNode);
|
||||
delNode->SetNextItem(nullNode);
|
||||
delNode.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : IsBoundByKey
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean PCollection_HDoubleMap::IsBoundByKey ( const Key &aKey ) const
|
||||
{
|
||||
Standard_Integer ResHashKey;
|
||||
Handle(PCollection_DoubleMapNode) theKeyNode;
|
||||
|
||||
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
theKeyNode = myArrayKey->Value(ResHashKey);
|
||||
while ( ! theKeyNode.IsNull() ) {
|
||||
if ( myKeyHash.Compare(theKeyNode->GetKey(),aKey) )
|
||||
return Standard_True;
|
||||
else theKeyNode = theKeyNode->NextKey();
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : IsBoundByItem
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean PCollection_HDoubleMap::IsBoundByItem(const Item &anItem) const
|
||||
{
|
||||
Standard_Integer ResHashItem;
|
||||
Handle(PCollection_DoubleMapNode) theItemNode;
|
||||
|
||||
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
|
||||
theItemNode = myArrayItem->Value(ResHashItem);
|
||||
while ( ! theItemNode.IsNull() ) {
|
||||
if ( myItemHash.Compare(theItemNode->GetItem(),anItem) )
|
||||
return Standard_True;
|
||||
else theItemNode = theItemNode->NextItem();
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : IsEmpty
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean PCollection_HDoubleMap::IsEmpty () const
|
||||
{
|
||||
Standard_Boolean Empty = Standard_True;
|
||||
|
||||
for ( Standard_Integer I = 1 ; I <= myArrayKey->Length() && Empty ; I++ )
|
||||
if ( ! myArrayKey->Value(I).IsNull() ) Empty = Standard_False;
|
||||
|
||||
return Empty;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : GetArrayKey
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_ArrayDoubleMap) PCollection_HDoubleMap::
|
||||
GetArrayKey () const
|
||||
{
|
||||
return myArrayKey;
|
||||
}
|
||||
|
287
src/PCollection/PCollection_HExtendedString.cdl
Executable file
287
src/PCollection/PCollection_HExtendedString.cdl
Executable file
@@ -0,0 +1,287 @@
|
||||
-- File: PCollection_HExtendedString.cdl
|
||||
-- Created: Wed Feb 10 19:03:16 1993
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun4>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
class HExtendedString from PCollection
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: Describes a persistent Unicode character string
|
||||
-- of a variable length.
|
||||
|
||||
|
||||
uses VArrayOfExtCharacter from DBC,
|
||||
ExtendedString from TCollection,
|
||||
HAsciiString from PCollection
|
||||
|
||||
|
||||
raises OutOfRange from Standard,
|
||||
NegativeValue from Standard,
|
||||
NumericError from Standard
|
||||
is
|
||||
|
||||
|
||||
Create(S : ExtendedString from TCollection)
|
||||
returns mutable HExtendedString from PCollection;
|
||||
---Purpose: Creation and initialization with the string S from
|
||||
-- TCollection.
|
||||
|
||||
Create(C : ExtCharacter from Standard)
|
||||
returns mutable HExtendedString from PCollection;
|
||||
---Purpose: Creation and initialisation with the character C
|
||||
|
||||
Create(S : HExtendedString from PCollection;
|
||||
FromIndex, ToIndex : Integer from Standard)
|
||||
returns mutable HExtendedString from PCollection
|
||||
raises NegativeValue from Standard;
|
||||
---Purpose: Creation of a sub-string of the string S
|
||||
-- the sub-string starts at the index Fromindex and ends
|
||||
-- at the index ToIndex.
|
||||
-- Raises an exception if ToIndex is less than FromIndex
|
||||
|
||||
Create( astring : CString)
|
||||
returns mutable HExtendedString from PCollection;
|
||||
---Purpose: Creation by converting a CString to an extended string.
|
||||
|
||||
Create(S : HAsciiString from PCollection)
|
||||
returns mutable HExtendedString from PCollection;
|
||||
---Purpose: Creation by converting a normal Ascii string to an extended string.
|
||||
|
||||
Append(me : mutable; S : HExtendedString from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string at the end of the string me.
|
||||
|
||||
Center(me : mutable; Width : Integer from Standard;
|
||||
Filler : ExtCharacter from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Center.
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler.
|
||||
-- Raises an exception if Width is less than zero.
|
||||
-- If Width < Length nothing happens.
|
||||
|
||||
ChangeAll(me : mutable; C, NewC : ExtCharacter from Standard);
|
||||
---Level: Public
|
||||
---Purpose: Substitutes all the characters equal to C by NewC in the
|
||||
-- string <me>.
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all characters in the string <me>.
|
||||
-- Length is equal to zero now.
|
||||
|
||||
Convert(me) returns ExtendedString from TCollection;
|
||||
---Level: Public
|
||||
---Purpose: Converts a persistent HExtendedString to a non
|
||||
-- persistent ExtendedString.
|
||||
|
||||
FirstLocationInSet(me; Set : HExtendedString from PCollection;
|
||||
FromIndex : Integer from Standard;
|
||||
ToIndex : Integer from Standard)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the first character of <Set> founded in <me>.
|
||||
-- The search begins to the index FromIndex and ends to the index ToIndex.
|
||||
-- Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
|
||||
FirstLocationNotInSet(me; Set : HExtendedString from PCollection;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the first character of <me>
|
||||
-- that is not present in the set <Set>.
|
||||
-- The search begins to the index FromIndex and ends to the
|
||||
-- the index ToIndex in <me>. Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
|
||||
InsertAfter(me : mutable;
|
||||
Index : Integer;
|
||||
S : HExtendedString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string after a specific index in the string <me>.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
|
||||
InsertBefore(me : mutable; Index : Integer;
|
||||
S : HExtendedString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string before a specific index in the string <me>.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
|
||||
IsAscii(me) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the string <me> is in the "Ascii range".
|
||||
|
||||
IsDifferent (me ; other : HExtendedString) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Test if characters are different between <me> and <other>.
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the string <me> contains zero character.
|
||||
|
||||
IsGreater (me ; other : HExtendedString from PCollection)
|
||||
returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if <me> is greater than <other>.
|
||||
|
||||
IsLess (me ; other : HExtendedString from PCollection)
|
||||
returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns TRUE if <me> is less than <other>.
|
||||
|
||||
IsSameString(me; S : HExtendedString from PCollection)
|
||||
returns Boolean from Standard;
|
||||
---Level: Advanced
|
||||
---Purpose: Returns True if two strings are equal.
|
||||
-- The comparison is case sensitive if the flag is set.
|
||||
|
||||
LeftAdjust(me : mutable)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes all space characters in the begining of the string.
|
||||
-- Raises an exception if the string <me> is not in the "Ascii range".
|
||||
|
||||
LeftJustify(me : mutable; Width : Integer;
|
||||
Filler : ExtCharacter from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Left justify.
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler.
|
||||
-- If Width < Length nothing happens.
|
||||
-- Raises an exception if Width is less than zero.
|
||||
|
||||
Length(me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Number of characters of the String
|
||||
|
||||
Location(me; N : Integer; C : ExtCharacter from Standard;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the character C
|
||||
-- in the string <me> from the starting index FromIndex to the
|
||||
-- ending index ToIndex. Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range
|
||||
|
||||
Location(me; S : HExtendedString from PCollection;
|
||||
FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns an index in the string <me> of the first occurence
|
||||
-- of the string S in the string <me> from the starting index.
|
||||
-- FromIndex to the ending index ToIndex.
|
||||
-- Returns zero if failure.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of range.
|
||||
|
||||
Prepend(me : mutable; S : HExtendedString from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushing a string at the begining of the string <me>.
|
||||
|
||||
Print(me ; S : in out OStream);
|
||||
---Level: Public
|
||||
---Purpose: Prints the content of <me> on the stream S.
|
||||
|
||||
Remove(me : mutable; Index : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Removes the character located at the index Index in the string.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
Remove(me : mutable; FromIndex, ToIndex : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Removes all the characters from the index FromIndex to the
|
||||
-- index ToIndex.
|
||||
-- Raises an exception if FromIndex or ToIndex is out of bounds.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
RemoveAll(me : mutable; C : ExtCharacter from Standard);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the occurences of the character C in the string.
|
||||
|
||||
RightAdjust(me : mutable)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes all space characters at the end of the string.
|
||||
-- Raises an exception if the string <me> is not in the Unicod "Ascii range".
|
||||
|
||||
RightJustify(me : mutable; Width : Integer;
|
||||
Filler : ExtCharacter from Standard)
|
||||
raises NegativeValue from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Right justify.
|
||||
-- Length becomes equal to Width and the new characters are
|
||||
-- equal to Filler.
|
||||
-- If Width < Length nothing happens.
|
||||
-- Raises an exception if Width is less than zero.
|
||||
|
||||
SetValue(me : mutable; Index : Integer;
|
||||
C : ExtCharacter from Standard)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Substitutes the character located to the position Index
|
||||
-- by the character C.
|
||||
-- Raises an exception if the Index is out of bounds
|
||||
|
||||
SetValue(me : mutable; Index : Integer;
|
||||
S : HExtendedString from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Substitutes from the index Index to the end by the string S.
|
||||
-- Raises an exception if Index is out of bounds.
|
||||
|
||||
Split(me : mutable; Index : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Splits a string of characters into two sub-strings.
|
||||
returns mutable HExtendedString from PCollection
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
SubString(me; FromIndex, ToIndex : Integer)
|
||||
---Level: Public
|
||||
---Purpose: Creation of a sub-string of the string <me>.
|
||||
-- The sub-string starts to the index FromIndex and ends
|
||||
-- to the index ToIndex.
|
||||
-- Raises an exception if ToIndex or FromIndex is out of bounds.
|
||||
returns mutable HExtendedString from PCollection
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
UsefullLength(me) returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Length of the string ignoring all spaces (' ') and the
|
||||
-- control character at the end.
|
||||
-- Raises an exception if the string <me> is not in the "Ascii range".
|
||||
|
||||
Value(me; Index : Integer) returns ExtCharacter from Standard
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the character of index Index of the string.
|
||||
---Example: me = "abcd", Index = 2, Value returns 'b'
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
Assign(me : mutable ;TheData : VArrayOfExtCharacter) is private;
|
||||
---Level: Internal
|
||||
---Purpose : Assigns the field of the current structure with
|
||||
-- the given value.
|
||||
|
||||
fields
|
||||
Data : VArrayOfExtCharacter from DBC;
|
||||
end HExtendedString;
|
583
src/PCollection/PCollection_HExtendedString.cxx
Executable file
583
src/PCollection/PCollection_HExtendedString.cxx
Executable file
@@ -0,0 +1,583 @@
|
||||
|
||||
#include <PCollection_HExtendedString.ixx>
|
||||
#include <PCollection_HAsciiString.hxx>
|
||||
#include <Standard_ExtString.hxx>
|
||||
#include <Standard_NumericError.hxx>
|
||||
#include <Standard_NegativeValue.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#if defined(HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if defined(HAVE_LIBC_H)
|
||||
# include <libc.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from an ExtendedString of TCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HExtendedString::PCollection_HExtendedString
|
||||
(const TCollection_ExtendedString& S):Data(S.Length())
|
||||
{
|
||||
for( Standard_Integer i = 1; i <= Data.Length() ; i++)
|
||||
Data.SetValue(i-1, S.Value(i)) ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from a ExtCharacter
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HExtendedString::PCollection_HExtendedString
|
||||
(const Standard_ExtCharacter C): Data(1)
|
||||
{
|
||||
Data.SetValue(0, C);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from a range of an HExtendedString of PCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HExtendedString::PCollection_HExtendedString
|
||||
(const Handle(PCollection_HExtendedString)& S,
|
||||
const Standard_Integer FromIndex, const Standard_Integer ToIndex) : Data(ToIndex-FromIndex+1)
|
||||
{
|
||||
for( Standard_Integer i = 0 , k = FromIndex; i < Data.Length() ; i++, k++)
|
||||
Data.SetValue(i, S->Value(k));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Create : from a CString
|
||||
//-----------------------------------------------------------------------
|
||||
PCollection_HExtendedString::PCollection_HExtendedString(const Standard_CString S)
|
||||
: Data(strlen(S))
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length() ; i++) {
|
||||
Standard_ExtCharacter val = ToExtCharacter(S[i]);
|
||||
Data.SetValue(i, val) ;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Create from an HAsciiString from PCollection
|
||||
//------------------------------------------------------------------------
|
||||
PCollection_HExtendedString::PCollection_HExtendedString
|
||||
(const Handle(PCollection_HAsciiString)& S) : Data(S->Length())
|
||||
{
|
||||
for( Standard_Integer i = 1; i <= Data.Length() ; i++) {
|
||||
// convert the character i of S
|
||||
Standard_ExtCharacter val = ToExtCharacter(S->Value(i)) ;
|
||||
Data.SetValue(i-1,val );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Append
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Append
|
||||
(const Handle(PCollection_HExtendedString)& S)
|
||||
{
|
||||
InsertAfter(Length(),S);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Center
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Center
|
||||
(const Standard_Integer Width, const Standard_ExtCharacter Filler)
|
||||
{
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Standard_Integer size2 = size1 + ((Width - size1)/2);
|
||||
LeftJustify(size2,Filler);
|
||||
RightJustify(Width,Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// ChangeAll
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::ChangeAll
|
||||
(const Standard_ExtCharacter C, const Standard_ExtCharacter NewC)
|
||||
{
|
||||
for( Standard_Integer i = 0 ; i < Data.Length(); i++) {
|
||||
if(Data(i) == C) Data.SetValue(i, NewC);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Clear
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Clear ()
|
||||
{
|
||||
Data.Resize(0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Convert
|
||||
//------------------------------------------------------------------------
|
||||
TCollection_ExtendedString PCollection_HExtendedString::Convert() const
|
||||
{
|
||||
Standard_Integer L = Length();
|
||||
TCollection_ExtendedString TString (L,' ');
|
||||
for (Standard_Integer i = 1 ; i <= L ; i++) {
|
||||
TString.SetValue(i,Value(i));
|
||||
}
|
||||
return TString;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// FirstLocationInSet
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::FirstLocationInSet
|
||||
(const Handle(PCollection_HExtendedString)& Set,
|
||||
const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || Set->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++)
|
||||
for(Standard_Integer j = 1; j <= Set->Length(); j++)
|
||||
if(Data(i) == Set->Value(j)) return (i+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// FirstLocationNotInset
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::FirstLocationNotInSet
|
||||
(const Handle(PCollection_HExtendedString)& Set, const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || Set->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Standard_Boolean find;
|
||||
for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++) {
|
||||
find = Standard_False;
|
||||
for(Standard_Integer j = 1; j <= Set->Length(); j++) {
|
||||
if (Data(i) == Set->Value(j)) find = Standard_True;
|
||||
}
|
||||
if (!find) return (i+1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// InsertAfter
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::InsertAfter
|
||||
(const Standard_Integer Index, const Handle(PCollection_HExtendedString)& S)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
Data.Resize(size1+size2);
|
||||
for( i = size1-1 ; i >= Index; i--) Data.SetValue(size2+i,Data(i));
|
||||
for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-1,S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// InsertBefore
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::InsertBefore
|
||||
(const Standard_Integer Index, const Handle(PCollection_HExtendedString)& S)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
Data.Resize(size1+size2);
|
||||
for( i = size1-1 ; i >= Index-1 ; i--)
|
||||
Data.SetValue(size2+i,Data(i));
|
||||
for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsAscii
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsAscii() const
|
||||
{
|
||||
for( Standard_Integer i = 0; i < Data.Length() ; i++) {
|
||||
if (!IsAnAscii(Data(i))) return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsDifferent
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsDifferent
|
||||
(const Handle(PCollection_HExtendedString)& S) const
|
||||
{
|
||||
Standard_Integer size = Length();
|
||||
if( size != S->Length()) return Standard_True;
|
||||
Standard_Integer i = 1 ;
|
||||
Standard_Boolean different = Standard_False;
|
||||
while (i <= size && !different) {
|
||||
if (Data(i-1) != S->Value(i)) different = Standard_True;
|
||||
i++;
|
||||
}
|
||||
return different;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsEmpty
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsEmpty () const
|
||||
{
|
||||
return (Data.Length() == 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IsLess
|
||||
// ----------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsLess(
|
||||
const Handle(PCollection_HExtendedString)& other) const
|
||||
{
|
||||
Standard_Integer mysize = Data.Length();
|
||||
Standard_Integer size = other->Length();
|
||||
Standard_Integer i = 0;
|
||||
Standard_Integer j = 1;
|
||||
while (i < mysize && j <= size) {
|
||||
if (Data(i) < other->Value(j)) return (Standard_True);
|
||||
if (Data(i) > other->Value(j)) return (Standard_False);
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
if (i == mysize && j <= size) return (Standard_True);
|
||||
return (Standard_False);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IsGreater
|
||||
// ----------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsGreater
|
||||
(const Handle(PCollection_HExtendedString)& other) const
|
||||
{
|
||||
Standard_Integer mysize = Data.Length();
|
||||
Standard_Integer size = other->Length();
|
||||
Standard_Integer i = 0;
|
||||
Standard_Integer j = 1;
|
||||
while (i < mysize && j <= size) {
|
||||
if (Data(i) < other->Value(j)) return (Standard_False);
|
||||
if (Data(i) > other->Value(j)) return (Standard_True);
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
if (j == size && j < mysize) return (Standard_True);
|
||||
return (Standard_False);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// IsSameString
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Boolean PCollection_HExtendedString::IsSameString
|
||||
(const Handle(PCollection_HExtendedString)& S) const
|
||||
{
|
||||
Standard_Integer size1 = Length();
|
||||
if( size1 != S->Length()) return Standard_False;
|
||||
for( Standard_Integer i = 1 ; i <= size1; i++) {
|
||||
if(Data(i-1) != S->Value(i)) return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// LeftAdjust
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::LeftAdjust ()
|
||||
{
|
||||
Standard_Integer i ;
|
||||
|
||||
if (!IsAscii()) Standard_OutOfRange::Raise();
|
||||
for ( i = 1 ; i <= Length() ; i ++) {
|
||||
if (!IsSpace((Standard_Character)Value(i))) break;
|
||||
}
|
||||
if( i > 1 ) Remove(1,i-1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// LeftJustify
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::LeftJustify
|
||||
(const Standard_Integer Width, const Standard_ExtCharacter Filler)
|
||||
{
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Data.Resize(Width);
|
||||
for(Standard_Integer i = size1; i < Width ; i++) Data.SetValue(i, Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Length
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::Length () const
|
||||
{
|
||||
return Data.Length();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Location
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::Location
|
||||
(const Standard_Integer N, const Standard_ExtCharacter C,
|
||||
const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1, count = 0; i <= ToIndex-1; i++)
|
||||
if(Data(i) == C) {
|
||||
count++;
|
||||
if ( count == N ) return (i+1);
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Location
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::Location
|
||||
(const Handle(PCollection_HExtendedString)& S, const Standard_Integer FromIndex,
|
||||
const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (Length() == 0 || S->Length() == 0) return 0;
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
for(Standard_Integer i = FromIndex-1, k = 1, l = FromIndex-2; i < ToIndex; i++){
|
||||
if(Data(i) == S->Value(k)) {
|
||||
k++;
|
||||
if ( k > S->Length()) return l + 2;
|
||||
}
|
||||
else {
|
||||
k = 1;
|
||||
l = i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Prepend
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Prepend
|
||||
(const Handle(PCollection_HExtendedString)& S)
|
||||
{
|
||||
InsertAfter(0,S);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Print
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Print (Standard_OStream& S) const
|
||||
{
|
||||
Standard_Integer len = Data.Length() ;
|
||||
for(Standard_Integer i = 0; i < len ; i++) {
|
||||
S.width(4);
|
||||
S.fill('0');
|
||||
S << hex << Data(i);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Remove
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Remove (const Standard_Integer Index)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Remove(Index,Index);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Remove
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Remove
|
||||
(const Standard_Integer FromIndex, const Standard_Integer ToIndex)
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
for( Standard_Integer i = ToIndex, j = FromIndex-1; i < size1 ; i++, j++)
|
||||
Data.SetValue(j,Data(i));
|
||||
Data.Resize(size1-(ToIndex-FromIndex+1));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RemoveAll
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::RemoveAll (const Standard_ExtCharacter C)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer j ;
|
||||
Standard_Integer size1 = Length();
|
||||
for( i = 0, j = 0; i < size1 ; i++) {
|
||||
if (Data(i) == C) continue;
|
||||
Data.SetValue(j++, Data(i));
|
||||
}
|
||||
Data.Resize(j);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RightAdjust
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::RightAdjust ()
|
||||
{
|
||||
Standard_Integer i ;
|
||||
if (! IsAscii()) Standard_OutOfRange::Raise();
|
||||
for ( i = Length() ; i >= 1 ; i --) {
|
||||
if (!IsSpace((Standard_Character)Value(i))) break;
|
||||
}
|
||||
if( i < Length() ) Remove(i+1,Length());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// RightJustify
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::RightJustify
|
||||
(const Standard_Integer Width, const Standard_ExtCharacter Filler)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
Standard_Integer k ;
|
||||
if (Width < 0) Standard_NegativeValue::Raise();
|
||||
Standard_Integer size1 = Length();
|
||||
if(Width > size1) {
|
||||
Data.Resize(Width);
|
||||
for ( i = size1-1, k = Width-1 ; i >= 0 ; i--, k--)
|
||||
Data.SetValue(k, Data(i));
|
||||
for(; k >= 0 ; k--) Data.SetValue(k, Filler);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SetValue
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::SetValue
|
||||
(const Standard_Integer Index, const Standard_ExtCharacter C)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Data(Index-1) = C;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SetValue
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::SetValue
|
||||
(const Standard_Integer Index, const Handle(PCollection_HExtendedString)& S)
|
||||
{
|
||||
|
||||
Standard_Integer size1 = Length();
|
||||
Standard_Integer size2 = S->Length();
|
||||
Standard_Integer size3 = size2 + Index - 1;
|
||||
#ifndef NOBOUNDCHECK
|
||||
if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
|
||||
#endif
|
||||
if(size1 != size3) Data.Resize(size3);
|
||||
for( Standard_Integer i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Split
|
||||
//------------------------------------------------------------------------
|
||||
Handle(PCollection_HExtendedString) PCollection_HExtendedString::Split
|
||||
(const Standard_Integer Index)
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
Handle(PCollection_HExtendedString) S2;
|
||||
if (Index != Length()) {
|
||||
S2 = SubString(Index+1,Length());
|
||||
Data.Resize(Index);
|
||||
}
|
||||
else {
|
||||
#ifndef OBJS
|
||||
Handle(PCollection_HAsciiString) s = new PCollection_HAsciiString("");
|
||||
S2 = new PCollection_HExtendedString(s);
|
||||
#else
|
||||
Handle(PCollection_HAsciiString) s = new (os_segment::of(this)) PCollection_HAsciiString("");
|
||||
S2 = new (os_segment::of(this)) PCollection_HExtendedString(s);
|
||||
#endif
|
||||
}
|
||||
return S2;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// SubString
|
||||
//------------------------------------------------------------------------
|
||||
Handle(PCollection_HExtendedString) PCollection_HExtendedString::SubString
|
||||
(const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
|
||||
{
|
||||
if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
|
||||
Standard_OutOfRange::Raise();
|
||||
Handle(PCollection_HExtendedString) S1;
|
||||
Handle(PCollection_HExtendedString) S2;
|
||||
S2 = this;
|
||||
#ifndef OBJS
|
||||
S1 = new PCollection_HExtendedString(S2,FromIndex,ToIndex);
|
||||
#else
|
||||
S1 = new (os_segment::of(this)) PCollection_HExtendedString(S2,FromIndex,ToIndex);
|
||||
#endif
|
||||
return S1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// UsefullLength
|
||||
//------------------------------------------------------------------------
|
||||
Standard_Integer PCollection_HExtendedString::UsefullLength () const
|
||||
{
|
||||
Standard_Integer i ;
|
||||
if (! IsAscii()) Standard_OutOfRange::Raise();
|
||||
for( i = Length() ; i >= 1 ; i--)
|
||||
if (IsGraphic((Standard_Character)Value(i))) break;
|
||||
return (i);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// value
|
||||
//------------------------------------------------------------------------
|
||||
Standard_ExtCharacter PCollection_HExtendedString::Value
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
return Data(Index-1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class HExtendedString " << endl;
|
||||
::ShallowDump(Data, S);
|
||||
S << "end class HExtendedString" << endl;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Assign
|
||||
//------------------------------------------------------------------------
|
||||
void PCollection_HExtendedString::Assign
|
||||
(const DBC_VArrayOfExtCharacter& TheField)
|
||||
|
||||
{
|
||||
Data = TheField;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
205
src/PCollection/PCollection_HIndexedDataMap.cdl
Executable file
205
src/PCollection/PCollection_HIndexedDataMap.cdl
Executable file
@@ -0,0 +1,205 @@
|
||||
---Copyright: Matra Datavision 1992
|
||||
---Version:
|
||||
|
||||
---History:
|
||||
-- Version Date Purpose
|
||||
-- 18/12/92 Creation
|
||||
|
||||
generic class HIndexedDataMap from PCollection ( Key as Storable;
|
||||
Item as Storable;
|
||||
KeyHash as Hash(Key)
|
||||
)
|
||||
|
||||
---Purpose: The HIndexedDataMap is a hashed set of objects of Type Key, called
|
||||
-- Keys. Keys can be inserted in the Map but not removed. The Map
|
||||
-- keeps the number of keys called NbKeys. Each time a Key is
|
||||
-- inserted the Map tests if this Key is already in the Map. If
|
||||
-- it is, nothing is done. If not, NbKeys is incremented and it's
|
||||
-- value is bound to the Key and called the Index.
|
||||
--
|
||||
-- The Map provides methods to inquire the Index of a Key and to
|
||||
-- retrieve a Key from an Index in the range 1..NbKeys.
|
||||
--
|
||||
-- Another Datum of the type Item can be stored with the Key. The
|
||||
-- Item can be retrieved from the Key and from the Index of the
|
||||
-- Key. The Item stored with a Key can be modified.
|
||||
|
||||
inherits Persistent from Standard
|
||||
|
||||
raises
|
||||
|
||||
OutOfRange from Standard
|
||||
|
||||
|
||||
class IndexedDataMapNode from PCollection inherits PManaged from PMMgt
|
||||
|
||||
---Purpose: This class is used in the implementation of the IndexedDataMap class.
|
||||
-- It stores three elements : a Key, an Item and an Integer Index.
|
||||
-- It also stores two references to IndexedDataMapNode objects,
|
||||
-- IndexedDataMapNode are used to make lists in the Hashed IndexedDataMap.
|
||||
|
||||
is
|
||||
|
||||
Create(aKey : Key; Index : Integer; anItem : Item; NextKey,NextIndex
|
||||
: IndexedDataMapNode )returns mutable IndexedDataMapNode;
|
||||
---Purpose: Creates a IndexedDataMapNode;
|
||||
|
||||
Set(me : mutable; aKey : Key; Index : Integer; anItem : Item;
|
||||
NextK,NextI : IndexedDataMapNode) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the values of <me>.
|
||||
|
||||
SetItem ( me : mutable; anItem : Item) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the item.
|
||||
|
||||
SetNextKey ( me : mutable ; aNode : IndexedDataMapNode ) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the next node of Key hashed list.
|
||||
|
||||
SetNextIndex ( me : mutable ; aNode : IndexedDataMapNode ) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Sets the next node of Key hashed list.
|
||||
|
||||
GetKey ( me ) returns any Key is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the key.
|
||||
|
||||
Index ( me ) returns Integer is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the index.
|
||||
|
||||
GetItem ( me ) returns any Item is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the item.
|
||||
|
||||
IndexAndItem(me; Index : out Integer; theItem : out any Item) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns index and item.
|
||||
|
||||
KeyAndItem(me; theKey : out any Key; theItem : out any Item) is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns key and item.
|
||||
|
||||
NextKey ( me ) returns any IndexedDataMapNode is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the next node of Key hashed list.
|
||||
|
||||
NextIndex ( me ) returns any IndexedDataMapNode is static;
|
||||
---Level: Internal
|
||||
---Purpose: Returns the next node of Index hashed list.
|
||||
|
||||
fields
|
||||
|
||||
myKey : Key;
|
||||
myIndex : Integer;
|
||||
myItem : Item;
|
||||
myNextKey : IndexedDataMapNode;
|
||||
myNextIndex : IndexedDataMapNode;
|
||||
|
||||
end IndexedDataMapNode;
|
||||
|
||||
class ArrayIndexedDataMap instantiates
|
||||
HArray1 from PCollection (IndexedDataMapNode);
|
||||
|
||||
is
|
||||
|
||||
Create ( NbBuckets : Integer; fhKey : KeyHash ) returns mutable HIndexedDataMap;
|
||||
---Purpose: Creates an empty HIndexedDataMap, NbBuckets is an estimation of the
|
||||
-- number of Keys that will be stored in the Map. It is not
|
||||
-- limited, but a too small number may reduce performance.
|
||||
|
||||
NbBuckets ( me ) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of entries in the indexed map.
|
||||
|
||||
NbKeys(me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of Keys stored in the Map.
|
||||
|
||||
Bind(me : mutable ; aKey : Key; anItem : Item; OverWrite : Boolean )
|
||||
returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Adds a new Key and returns the Index.
|
||||
-- If the Key is new in the Map the Item is bound with the Key.
|
||||
-- If the Key is already present the Item replaces the existing
|
||||
-- Item if Overwrite is True.
|
||||
|
||||
FindIndex ( me ; aKey : Key ) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the Index of the Key in the Map. If the Key is not
|
||||
-- stored the returned Index is 0.
|
||||
|
||||
FindKey ( me ; Index : Integer ) returns any Key
|
||||
---Level: Public
|
||||
---Purpose: Returns the Key stored with the Index, Index must be in the
|
||||
-- range 1..NbKeys.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
FindItemFromKey ( me ; aKey : Key ) returns any Item
|
||||
---Level: Public
|
||||
---Purpose: Returns the Item stored with the Key <aKey>.
|
||||
---Trigger: An exception is raised if the key <aKey> is not stored in the Map.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
FindItemFromIndex ( me ; Index : Integer ) returns any Item
|
||||
---Level: Public
|
||||
---Purpose: Returns the Item stored with the index <Index>. This is
|
||||
-- similar to but faster than K = GetKey(Index); GetItem(K,I)
|
||||
---Trigger: An exception is raised if <Index> is not in the range 1..NbKeys.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
FindIndexAndItem(me; aKey : Key; Index : out Integer; theItem : out Item)
|
||||
---Level: Public
|
||||
---Purpose: Returns the index and the item stored with the Key <aKey>.
|
||||
---Trigger: An exception is raised if the key <aKey> is not stored in the Map.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
FindKeyAndItem(me; Index : Integer; theKey : out Key; theItem : out Item)
|
||||
---Level: Public
|
||||
---Purpose: Returns the key and the item stored with the index <Index>.
|
||||
---Trigger: An exception is raised if <Index> is not in the range 1..NbKeys.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
SetItemToKey(me : mutable; aKey : Key; anItem : Item)
|
||||
---Level: Public
|
||||
---Purpose: Modifies the item stored with the key <aKey>.
|
||||
---Trigger: An exception is raised if the key <aKey> is not stored in the Map.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
SetItemToIndex(me : mutable; Index : Integer; anItem : Item)
|
||||
---Level: Public
|
||||
---Purpose: Modifies the item stored with the index <Index>.
|
||||
---Trigger: An exception is raised if <Index> is not in the range 1..NbKeys.
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
Clear ( me : mutable );
|
||||
---Level: Public
|
||||
---Purpose: Clears the Map content.
|
||||
|
||||
IsBound ( me ; aKey : Key) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if an element is bound by <aKey>.
|
||||
|
||||
LocateKey(me; aKey : Key) returns any IndexedDataMapNode
|
||||
---Level: Internal
|
||||
---Purpose: Returns the node containing <aKey>.
|
||||
is static private;
|
||||
|
||||
LocateIndex(me; Index : Integer) returns any IndexedDataMapNode
|
||||
---Level: Internal
|
||||
---Purpose: Returns the node containing <Index>.
|
||||
is static private;
|
||||
|
||||
fields
|
||||
|
||||
myNumber : Integer;
|
||||
myKeyHash : KeyHash;
|
||||
myArrayKey : ArrayIndexedDataMap;
|
||||
myArrayIndices : ArrayIndexedDataMap;
|
||||
|
||||
end HIndexedDataMap;
|
||||
|
||||
|
||||
|
||||
|
299
src/PCollection/PCollection_HIndexedDataMap.gxx
Executable file
299
src/PCollection/PCollection_HIndexedDataMap.gxx
Executable file
@@ -0,0 +1,299 @@
|
||||
//-Copyright: Matra Datavision 1992
|
||||
//-Version:
|
||||
|
||||
//-History:
|
||||
// Version Date Purpose
|
||||
// 14/12/92 Creation
|
||||
|
||||
//-Language C++2.0
|
||||
|
||||
//-Declarations
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
//=======================================================================
|
||||
// Function : PCollection_HIndexedDataMap
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
PCollection_HIndexedDataMap::PCollection_HIndexedDataMap
|
||||
(const Standard_Integer NbBuckets, const KeyHash &fhKey)
|
||||
{
|
||||
myNumber = 0;
|
||||
myArrayKey = new PCollection_ArrayIndexedDataMap(1,NbBuckets);
|
||||
myArrayIndices = new PCollection_ArrayIndexedDataMap(0,NbBuckets-1);
|
||||
myKeyHash = fhKey;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : NbBuckets
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HIndexedDataMap::NbBuckets() const
|
||||
{
|
||||
return myArrayKey->Length();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : NbKeys
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HIndexedDataMap::NbKeys() const
|
||||
{
|
||||
return myNumber;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Bind
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HIndexedDataMap::Bind(const Key& aKey,
|
||||
const Item& anItem,
|
||||
const Standard_Boolean OverWrite)
|
||||
{
|
||||
Standard_Integer theSize = myArrayKey->Length();
|
||||
|
||||
Standard_Integer hcode = myKeyHash.HashCode(aKey,theSize);
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = myArrayKey->Value(hcode);
|
||||
while (! theNode.IsNull()) {
|
||||
if ( myKeyHash.Compare(theNode->GetKey(),aKey)) {
|
||||
// if the Key already exists, update the item and return the index
|
||||
if (OverWrite) {
|
||||
theNode->SetItem(anItem);
|
||||
}
|
||||
return theNode->Index();
|
||||
}
|
||||
else {
|
||||
theNode = theNode->NextKey();
|
||||
}
|
||||
}
|
||||
|
||||
// the Key was not Found, create a new Elem
|
||||
myNumber++;
|
||||
Standard_Integer hint = myNumber % theSize;
|
||||
Handle(PCollection_IndexedDataMapNode) theNewNode =
|
||||
new PCollection_IndexedDataMapNode(aKey, myNumber, anItem,
|
||||
myArrayKey->Value(hcode),
|
||||
myArrayIndices->Value(hint));
|
||||
myArrayKey->SetValue(hcode,theNewNode);
|
||||
myArrayIndices->SetValue(hint,theNewNode);
|
||||
|
||||
return myNumber;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindIndex
|
||||
// Purpose : returns the Index of the Key, 0 if the Key is not stored
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_HIndexedDataMap::FindIndex(const Key& aKey) const
|
||||
{
|
||||
Standard_Integer ResHash;
|
||||
Handle(PCollection_IndexedDataMapNode) theKeyNode;
|
||||
|
||||
// search the Key in the map
|
||||
ResHash = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
theKeyNode = myArrayKey->Value(ResHash);
|
||||
while (! theKeyNode.IsNull()) {
|
||||
if ( myKeyHash.Compare(theKeyNode->GetKey(),aKey))
|
||||
// if the Key already exists stop the search
|
||||
return theKeyNode->Index();
|
||||
|
||||
else
|
||||
// go to next element
|
||||
theKeyNode = theKeyNode->NextKey();
|
||||
}
|
||||
// not found, return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindKey
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Key PCollection_HIndexedDataMap::FindKey(const Standard_Integer Index) const
|
||||
{
|
||||
// search the index
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = LocateIndex(Index);
|
||||
// get the Key
|
||||
return theNode->GetKey();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindItemFromKey
|
||||
// Purpose : return the Item stored with the Key
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_HIndexedDataMap::FindItemFromKey(const Key& aKey) const
|
||||
{
|
||||
// find the Key
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = LocateKey(aKey);
|
||||
|
||||
// get the Item
|
||||
return theNode->GetItem();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindItemFromIndex
|
||||
// Purpose : Find an Item from the index
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_HIndexedDataMap::FindItemFromIndex
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
// search the index
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = LocateIndex(Index);
|
||||
// get the Item
|
||||
return theNode->GetItem();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindIndexAndItem
|
||||
// Purpose : find the index and the Item for a key
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HIndexedDataMap::FindIndexAndItem(const Key& aKey,
|
||||
Standard_Integer& Index,
|
||||
Item& theItem) const
|
||||
{
|
||||
// find the Key
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = LocateKey(aKey);
|
||||
|
||||
// get Index and Item
|
||||
theNode->IndexAndItem(Index,theItem);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : FindKeyAndItem
|
||||
// Purpose : find the Key and the Item for an Index
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HIndexedDataMap::FindKeyAndItem(const Standard_Integer Index,
|
||||
Key& theKey,
|
||||
Item& theItem) const
|
||||
{
|
||||
// find the index
|
||||
Handle(PCollection_IndexedDataMapNode) TheNode = LocateIndex(Index);
|
||||
|
||||
// get Key and Item
|
||||
TheNode->KeyAndItem(theKey,theItem);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetItemToKey
|
||||
// Purpose : change the Item stored with a Key
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HIndexedDataMap::SetItemToKey(const Key& aKey,
|
||||
const Item& anItem)
|
||||
{
|
||||
// find the Key
|
||||
Handle(PCollection_IndexedDataMapNode) TheNode = LocateKey(aKey);
|
||||
|
||||
// set the Item
|
||||
TheNode->SetItem(anItem);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetItemToIndex
|
||||
// Purpose : change the Item stored with an Index
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HIndexedDataMap::SetItemToIndex(const Standard_Integer Index,
|
||||
const Item& anItem)
|
||||
{
|
||||
// find the Key
|
||||
Handle(PCollection_IndexedDataMapNode) TheNode = LocateIndex(Index);
|
||||
|
||||
// set the Item
|
||||
TheNode->SetItem(anItem);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Clear
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_HIndexedDataMap::Clear()
|
||||
{
|
||||
Handle(PCollection_IndexedDataMapNode) nullNode,theNode,delNode;
|
||||
Standard_Integer I;
|
||||
|
||||
myNumber = 0;
|
||||
|
||||
for ( I = 0 ; I < myArrayKey->Length() ; I++ ) {
|
||||
theNode = myArrayKey->Value(I+1);
|
||||
myArrayKey->SetValue(I+1,nullNode);
|
||||
myArrayIndices->SetValue(I,nullNode);
|
||||
while ( !theNode.IsNull() ) {
|
||||
delNode = theNode;
|
||||
theNode = theNode->NextKey();
|
||||
delNode->SetNextKey(nullNode);
|
||||
delNode->SetNextIndex(nullNode);
|
||||
delNode.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : IsBound
|
||||
// Purpose : Standard_True if the Map contains the Key
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean PCollection_HIndexedDataMap::IsBound(const Key& aKey) const
|
||||
{
|
||||
return (FindIndex(aKey) != 0);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : LocateKey
|
||||
// Purpose : find the Map Element containing a Shape, Null if none
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_IndexedDataMapNode)
|
||||
PCollection_HIndexedDataMap::LocateKey(const Key& aKey) const
|
||||
{
|
||||
Standard_Integer ResHash = myKeyHash.HashCode(aKey,myArrayKey->Length());
|
||||
// search the Key in the map
|
||||
Handle(PCollection_IndexedDataMapNode) theNode = myArrayKey->Value(ResHash);
|
||||
while (! theNode.IsNull()) {
|
||||
if ( myKeyHash.Compare(aKey,theNode->GetKey()))
|
||||
// if the Key already exists stop the search
|
||||
return theNode;
|
||||
else
|
||||
// go to next element
|
||||
theNode = theNode->NextKey();
|
||||
}
|
||||
|
||||
// raises Standard_OutOfRange
|
||||
Standard_OutOfRange::Raise("HIndexedDataMap : Key not in Map");
|
||||
return theNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : LocateIndex
|
||||
// Purpose : find the Map Element containing an Index, check bounds
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_IndexedDataMapNode) PCollection_HIndexedDataMap::LocateIndex
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
// check bounds
|
||||
if ((Index < 1)||(Index > myNumber))
|
||||
Standard_OutOfRange::Raise("HIndexedDataMap : Bad Index");
|
||||
// search the Index in the map
|
||||
Handle(PCollection_IndexedDataMapNode) theNode =
|
||||
myArrayIndices->Value(Index % myArrayIndices->Length());
|
||||
// the Index SHOULD be in the list, so no NULL checking
|
||||
while (theNode->Index() != Index)
|
||||
theNode = theNode->NextIndex();
|
||||
|
||||
// return the element
|
||||
return theNode;
|
||||
}
|
||||
|
||||
|
||||
|
149
src/PCollection/PCollection_HQueue.cdl
Executable file
149
src/PCollection/PCollection_HQueue.cdl
Executable file
@@ -0,0 +1,149 @@
|
||||
-- File: PCollection_HQueue.cdl
|
||||
-- Created: Wed Feb 10 18:03:38 1993
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun4>
|
||||
---Copyright: Matra Datavision 1991
|
||||
|
||||
|
||||
generic class HQueue from PCollection (Item as Storable)
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: A queue is a sequence of items in which items
|
||||
-- are added at one end (called the back of the
|
||||
-- queue) and removed at the other end (called
|
||||
-- the front)
|
||||
-- The Queue is empty if there are no elements.
|
||||
|
||||
raises NoSuchObject from Standard
|
||||
|
||||
|
||||
class QueueNode instantiates HSingleList from PCollection(Item);
|
||||
|
||||
class QueueIterator from PCollection
|
||||
|
||||
---Purpose: Iterator of the class Queue.
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create(Q : HQueue from PCollection)
|
||||
returns QueueIterator from PCollection;
|
||||
---Purpose: Creates an iterator on the queue Q.
|
||||
-- Sets the iterator at the beginning of the Queue Q.
|
||||
|
||||
More(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if there are other items.
|
||||
|
||||
Next(me: in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next item.
|
||||
|
||||
Value(me) returns any Item raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the item value corresponding to
|
||||
-- the current position of the iterator.
|
||||
|
||||
fields
|
||||
TheIterator : QueueNode;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
Create returns mutable HQueue from PCollection;
|
||||
---Purpose: Creates an empty queue.
|
||||
|
||||
Length(me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of items in the queue.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- returns 3
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the queue contains no element.
|
||||
|
||||
Front(me) returns any Item raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the item at the front of the queue.
|
||||
-- Raises an exception if the queue is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- A
|
||||
|
||||
FFront(me) returns QueueNode;
|
||||
---Level: Public
|
||||
---Purpose: Returns the field TheFront(the front of the queue).
|
||||
|
||||
FBack(me) returns QueueNode;
|
||||
---Level: Public
|
||||
---Purpose: Returns the field Theback(the back of the queue).
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the elements from the queue
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = ()
|
||||
|
||||
Push(me : mutable; T : Item);
|
||||
---Level: Public
|
||||
---Purpose: Inserts an item at the back of the queue.
|
||||
---Example: before
|
||||
-- me = (A B) , T = C
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
|
||||
Pop(me : mutable) raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes an item from the front of the queue.
|
||||
-- Raises an exception if the queue is empty
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (B C)
|
||||
-- returns
|
||||
-- A
|
||||
|
||||
ChangeFront(me:mutable ; T : Item) raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Replaces the front element of the queue with T.
|
||||
-- Raises an exception if the queue is empty.
|
||||
---Example: before
|
||||
-- me = (A B C) , T = D
|
||||
-- after
|
||||
-- me = (D B C)
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
Destroy(me : mutable);
|
||||
---C++: alias ~
|
||||
|
||||
fields
|
||||
TheFront : QueueNode;
|
||||
TheBack : QueueNode;
|
||||
TheLength : Integer from Standard;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
152
src/PCollection/PCollection_HQueue.gxx
Executable file
152
src/PCollection/PCollection_HQueue.gxx
Executable file
@@ -0,0 +1,152 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ------------
|
||||
// constructor
|
||||
// -----------
|
||||
|
||||
PCollection_HQueue::PCollection_HQueue()
|
||||
{
|
||||
TheLength = 0;
|
||||
TheFront = new PCollection_QueueNode;
|
||||
TheBack = TheFront;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// IsEmpty : is the queue empty ?
|
||||
// -----------------------------
|
||||
Standard_Boolean PCollection_HQueue::IsEmpty() const {
|
||||
return TheLength == 0;
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
// Front : item at the front of the Queue
|
||||
// --------------------------------------
|
||||
Item PCollection_HQueue::Front() const
|
||||
{
|
||||
if (TheFront->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
return TheFront->Value();
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
// Clear : remove all items in the Queue
|
||||
// --------------------------------------
|
||||
void PCollection_HQueue::Clear()
|
||||
{
|
||||
Handle(PCollection_QueueNode) temp;
|
||||
while (TheLength != 0) {
|
||||
temp = TheFront;
|
||||
TheFront = TheFront->Tail();
|
||||
if (TheLength == 1) TheBack = TheFront;
|
||||
temp.Delete();
|
||||
--TheLength;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Push : insert an item at the back
|
||||
// ------------------------------------
|
||||
void PCollection_HQueue::Push(const Item& T)
|
||||
{
|
||||
Handle(PCollection_QueueNode) L;
|
||||
L = new PCollection_QueueNode;
|
||||
if (TheLength == 0)
|
||||
{
|
||||
L->ChangeForwardPointer(TheFront);
|
||||
TheBack = L;
|
||||
TheFront = TheBack;
|
||||
}
|
||||
else
|
||||
{
|
||||
L->ChangeForwardPointer(TheBack->Tail());
|
||||
TheBack->ChangeForwardPointer(L);
|
||||
TheBack = L;
|
||||
};
|
||||
TheBack->SetValue(T);
|
||||
TheLength = TheLength + 1;
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Pop : remove an item from the front
|
||||
// ------------------------------------
|
||||
void PCollection_HQueue::Pop()
|
||||
{
|
||||
if (TheFront->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
Handle(PCollection_QueueNode) temp = TheFront;
|
||||
TheFront = TheFront->Tail();
|
||||
temp.Delete();
|
||||
TheLength = TheLength - 1;
|
||||
if (TheLength == 0) TheBack = TheFront;
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// ChangeFront : replace the front by T
|
||||
// ------------------------------------
|
||||
void PCollection_HQueue::ChangeFront(const Item& T)
|
||||
{
|
||||
if (TheFront->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
TheFront->SetValue(T);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// ShallowCopy
|
||||
// ------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HQueue::ShallowCopy() const
|
||||
{
|
||||
Handle(PCollection_HQueue) TheCopy;
|
||||
Handle(PCollection_QueueNode) TheList;
|
||||
|
||||
TheCopy = new PCollection_HQueue;
|
||||
TheList = TheFront;
|
||||
|
||||
|
||||
for (Standard_Integer I = 1; I <= TheLength; I++){
|
||||
TheCopy->Push(TheList->Value());
|
||||
TheList = TheList->Tail();
|
||||
}
|
||||
|
||||
return TheCopy;
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// ShallowDump
|
||||
// ------------------------------------
|
||||
void PCollection_HQueue::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class Queue "<< endl;
|
||||
S << "Length of Queue : "<< TheLength << endl;
|
||||
TheFront->ShallowDump(cout);
|
||||
S << "end of class Queue." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// Length : numbers of items
|
||||
// -----------------------------
|
||||
Standard_Integer PCollection_HQueue::Length() const {
|
||||
return TheLength;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// FFront : front of the queue
|
||||
// -----------------------------
|
||||
Handle(PCollection_QueueNode) PCollection_HQueue::FFront() const {
|
||||
return TheFront;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// FBack : the back of the queue
|
||||
// -----------------------------
|
||||
Handle(PCollection_QueueNode) PCollection_HQueue::FBack() const {
|
||||
return TheBack;
|
||||
}
|
||||
|
||||
void PCollection_HQueue::Destroy()
|
||||
{
|
||||
#ifdef CSFDB
|
||||
Clear();
|
||||
#endif
|
||||
}
|
422
src/PCollection/PCollection_HSequence.cdl
Executable file
422
src/PCollection/PCollection_HSequence.cdl
Executable file
@@ -0,0 +1,422 @@
|
||||
-- File: PCollection_HSequence.cdl
|
||||
-- Created: Fri Sep 11 17:34:39 1992
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <mip@sdsun3>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class HSequence from PCollection (Item as Storable) inherits Persistent
|
||||
|
||||
---Purpose: Definition of a sequence of elements indexed by
|
||||
-- an Integer in range of 1..n
|
||||
|
||||
raises
|
||||
NoSuchObject from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
|
||||
private class SeqNode inherits PManaged
|
||||
is
|
||||
|
||||
---Purpose: This class provides tools to manipulate a Sequence node.
|
||||
|
||||
Create( TheLast: SeqNode ; TheItem: Item)
|
||||
returns mutable SeqNode from PCollection;
|
||||
|
||||
Create( TheItem: Item ; TheFirst: SeqNode )
|
||||
returns mutable SeqNode from PCollection;
|
||||
|
||||
Create( ThePrevious: SeqNode ; TheNext: SeqNode ; TheItem: Item )
|
||||
returns mutable SeqNode from PCollection;
|
||||
|
||||
Value(me) returns any Item;
|
||||
---Level: Internal
|
||||
---Purpose: Returns MyItem.
|
||||
|
||||
Next(me) returns mutable SeqNode;
|
||||
---Level: Internal
|
||||
---Purpose: Returns MyNext.
|
||||
|
||||
Previous(me) returns mutable SeqNode;
|
||||
---Level: Internal
|
||||
---Purpose: Returns MyPrevious.
|
||||
|
||||
SetValue( me:mutable; AnItem: Item);
|
||||
---Level: Internal
|
||||
---Purpose: Modifies the value of MyItem.
|
||||
|
||||
SetNext( me:mutable; ANode: SeqNode);
|
||||
---Level: Internal
|
||||
---Purpose: Modifies the value of MyNext.
|
||||
|
||||
SetPrevious( me:mutable; ANode: SeqNode);
|
||||
---Level: Internal
|
||||
---Purpose: Modifies the value of MyPrevious.
|
||||
|
||||
fields
|
||||
MyPrevious : SeqNode;
|
||||
MyItem : Item;
|
||||
MyNext : SeqNode;
|
||||
|
||||
friends class HSequence from PCollection,
|
||||
class SeqExplorer from PCollection
|
||||
|
||||
end;
|
||||
|
||||
class SeqExplorer
|
||||
|
||||
---Purpose: To explore a Sequence in an optimized way.
|
||||
|
||||
raises NoSuchObject from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
is
|
||||
Create(S : HSequence from PCollection)
|
||||
returns SeqExplorer from PCollection;
|
||||
---Purpose: Creates an explorer on the sequence S.
|
||||
-- Sets the explorer at the BEGINNING(index 1)
|
||||
-- of the sequence S.
|
||||
|
||||
Value(me : in out ; Index : Integer)
|
||||
returns any Item
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Value of the element indexed by Index in the
|
||||
-- sequence <S>.
|
||||
|
||||
Contains(me : in out ; T : Item) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the sequence <S> contains the element T.
|
||||
|
||||
Location(me : in out ; N : Integer;
|
||||
T : Item; FromIndex : Integer;
|
||||
ToIndex : Integer)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the element T
|
||||
-- in the sequence <S>. The search starts from the index
|
||||
-- FromIndex to the index ToIndex.
|
||||
-- Returns 0 if the element is not present in the sub-sequence.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
|
||||
Location(me : in out ; N : Integer; T : Item)
|
||||
returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the element T
|
||||
-- in the sequence <S>. The search starts from the beginning
|
||||
-- to the end of the sequence.
|
||||
-- Returns 0 if the element is not present in the sub-sequence.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
|
||||
fields
|
||||
CurrentItem : SeqNode;
|
||||
CurrentIndex : Integer;
|
||||
TheSequence : HSequence from PCollection;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create returns mutable HSequence;
|
||||
---Purpose: Creation of an empty sequence.
|
||||
|
||||
|
||||
IsEmpty(me) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the sequence <me> contains no elements.
|
||||
|
||||
Length(me) returns Integer;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of element(s) in the sequence.
|
||||
-- Returns zero if the sequence is empty.
|
||||
|
||||
First(me) returns any Item
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the first element of the sequence <me>.
|
||||
-- Raises an exception if the sequence is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns A
|
||||
|
||||
Last(me) returns any Item
|
||||
raises NoSuchObject from Standard ;
|
||||
---Level: Public
|
||||
---Purpose: Returns the last element of the sequence <me>.
|
||||
-- Raises an exception if the sequence is empty
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns C
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all element(s) of the sequence <me>.
|
||||
-- before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = ()
|
||||
|
||||
Append(me : mutable; T : Item);
|
||||
---Level: Public
|
||||
---Purpose: Pushes an element T at the end of the sequence <me>, thus
|
||||
-- creating a new node.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C T)
|
||||
|
||||
Append(me : mutable; S : HSequence from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushes a sequence S at the end of the sequence <me>.
|
||||
-- There is a concatenation of the two sequences by copying S.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- S = (D E F)
|
||||
-- after
|
||||
-- me = (A B C D E F)
|
||||
-- S = (D E F)
|
||||
|
||||
Prepend(me : mutable; T : Item);
|
||||
---Level: Public
|
||||
---Purpose: Pushes an element T at the beginning of the sequence <me>,
|
||||
-- thus creating a new node.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (T A B C )
|
||||
|
||||
|
||||
Prepend(me : mutable; S : HSequence from PCollection);
|
||||
---Level: Public
|
||||
---Purpose: Pushes a sequence S at the begining of the sequence <me>.
|
||||
-- There is a concatenation of two sequences with a copy of S.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- S = (D E F)
|
||||
-- after
|
||||
-- me = (D E F A B C)
|
||||
-- S = (D E F)
|
||||
|
||||
Reverse(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Reverses the order of the sequence <me>.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (C B A)
|
||||
|
||||
InsertBefore(me : mutable; Index : Integer; T : Item)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushes an element before a specific index in the
|
||||
-- sequence <me>.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B D), Index = 3, T = C
|
||||
-- after
|
||||
-- me = (A B C D )
|
||||
|
||||
InsertBefore(me : mutable ; Index : Integer;
|
||||
S : HSequence from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushes a sequence before a specific index in
|
||||
-- the sequence <me> by copying S.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B F), Index = 3, S = (C D E)
|
||||
-- after
|
||||
-- me = (A B C D E F)
|
||||
-- S = (C D E)
|
||||
|
||||
InsertAfter(me : mutable; Index : Integer; T : Item)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushes an element after a specific index in the
|
||||
-- sequence <me>.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C), Index = 3, T = D
|
||||
-- after
|
||||
-- me = (A B C D )
|
||||
|
||||
InsertAfter(me : mutable ; Index : Integer;
|
||||
S : HSequence from PCollection)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Pushes a sequence after a specific index in
|
||||
-- the sequence <me> by copying S.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C), Index = 3, S = (D E F)
|
||||
-- after
|
||||
-- me = (A B C D E F)
|
||||
-- S = (D E F)
|
||||
|
||||
Exchange(me : mutable; I, J : Integer) raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Swaps elements which are located in positions I and J
|
||||
-- in the sequence <me>.
|
||||
-- Raises an exception if the index I or J is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C), I = 1, J = 3
|
||||
-- after
|
||||
-- me = (C B A)
|
||||
|
||||
SubSequence(me; FromIndex, ToIndex : Integer)
|
||||
returns mutable HSequence
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Creation a sub-sequence with the elements from the
|
||||
-- starting index I to the last index J
|
||||
-- there is a partial copy of the sequence <me>
|
||||
-- Raises an exception if the index is out of bounds or if
|
||||
-- <ToIndex> is less than <FromIndex>.
|
||||
---Example: before
|
||||
-- me = (A B C D E), I = 2, J = 4
|
||||
-- after
|
||||
-- me = (A B C D E)
|
||||
-- returns
|
||||
-- (B C D)
|
||||
|
||||
Split(me : mutable; Index : Integer)
|
||||
returns mutable HSequence
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Split a sequence into two sub-sequences.
|
||||
---Example: before
|
||||
-- me = (A B C D) ,Index = 3
|
||||
-- after
|
||||
-- me = (A B)
|
||||
-- returns
|
||||
-- (C D)
|
||||
|
||||
SetValue(me : mutable; Index : Integer; T : Item)
|
||||
raises OutOfRange;
|
||||
---Level: Public
|
||||
---Purpose: Modification of the element indexed by Index in
|
||||
-- the sequence <me>.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B D), Index = 3, T = C
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
|
||||
Value(me; Index : Integer) returns any Item
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Value of the element indexed by Index in the
|
||||
-- sequence <me>.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C), Index = 1
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- A
|
||||
|
||||
Contains(me; T : Item) returns Boolean;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the sequence <me> contains the element T
|
||||
|
||||
Location(me; N : Integer;
|
||||
T : Item; FromIndex : Integer;
|
||||
ToIndex : Integer) returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the element T
|
||||
-- in the sequence <me>. The search starts from the index FromIndex to
|
||||
-- the index ToIndex.
|
||||
-- Returns 0 if the element is not present in the sub-sequence.
|
||||
-- Raises an exception if the index is out of bounds or if
|
||||
-- <ToIndex> is less than <FromIndex>.
|
||||
---Example: before
|
||||
-- me = (A B C B D E B H), N = 2, T = B, FromIndex = 3
|
||||
-- ToIndex = 8
|
||||
-- after
|
||||
-- me = (A B C B D E B H)
|
||||
-- returns 7
|
||||
|
||||
Location(me; N : Integer; T : Item) returns Integer
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the index of the nth occurence of the element T
|
||||
-- in the sequence <me>. The search starts from the beginning
|
||||
-- to the end of the sequence.
|
||||
-- Returns 0 if the element is not present in the sub-sequence.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C B D E B H), N = 3, T = B
|
||||
-- after
|
||||
-- me = (A B C B D E B H)
|
||||
-- returns 7
|
||||
|
||||
Remove(me : mutable; Index : Integer)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes the element indexed by Index in the
|
||||
-- sequence <me>.
|
||||
-- Raises an exception if the index is out of bounds.
|
||||
---Example: before
|
||||
-- me = (A B C), Index = 3
|
||||
-- after
|
||||
-- me = (A B)
|
||||
|
||||
Remove(me : mutable; FromIndex, ToIndex : Integer)
|
||||
raises OutOfRange from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes the elements from the index FromIndex to the
|
||||
-- index ToIndex in the sequence <me>.
|
||||
-- Raises an exception if the indexes are out of bounds
|
||||
---Example: before
|
||||
-- me = (A B C D E F), FromIndex = 1 ToIndex = 3
|
||||
-- after
|
||||
-- me = (D E F)
|
||||
|
||||
GetFirst(me)
|
||||
---Level: Internal
|
||||
---Purpose: Returns "FirstItem" field.
|
||||
returns SeqNode
|
||||
is private;
|
||||
|
||||
GetLast(me)
|
||||
---Level: Internal
|
||||
---Purpose: Returns "LastItem" field
|
||||
returns SeqNode
|
||||
is private;
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
Destroy(me : mutable);
|
||||
---C++: alias ~
|
||||
|
||||
fields
|
||||
FirstItem : SeqNode;
|
||||
LastItem : SeqNode;
|
||||
Size : Integer;
|
||||
|
||||
friends class SeqExplorer from PCollection
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
499
src/PCollection/PCollection_HSequence.gxx
Executable file
499
src/PCollection/PCollection_HSequence.gxx
Executable file
@@ -0,0 +1,499 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
#include <Standard_OStream.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_HSequence.gxx
|
||||
// Created: Sep, 24 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// -----------
|
||||
// constructor :
|
||||
// -----------
|
||||
PCollection_HSequence::PCollection_HSequence()
|
||||
{
|
||||
Size = 0;
|
||||
FirstItem.Nullify();
|
||||
LastItem.Nullify();
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// Clear : Clear the Current Sequence
|
||||
// ----------------------------------
|
||||
void PCollection_HSequence::Clear()
|
||||
{
|
||||
Handle(PCollection_SeqNode) cell;
|
||||
Handle(PCollection_SeqNode) pnul;
|
||||
pnul.Nullify();
|
||||
if (Size != 0) {
|
||||
while (Size != 1) {
|
||||
cell = FirstItem;
|
||||
FirstItem = FirstItem->Next();
|
||||
FirstItem->SetPrevious(pnul);
|
||||
#ifndef CSFDB
|
||||
cell.Delete();
|
||||
#endif
|
||||
--Size;
|
||||
}
|
||||
FirstItem.Nullify();
|
||||
#ifndef CSFDB
|
||||
LastItem.Delete(); // free memory
|
||||
#endif
|
||||
Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Append : Push an item at the end of the sequence
|
||||
// -------------------------------------------------
|
||||
void PCollection_HSequence::Append(const Item& T)
|
||||
{
|
||||
Handle(PCollection_SeqNode) newcell;
|
||||
#ifndef OBJS
|
||||
newcell = new PCollection_SeqNode(LastItem,T);
|
||||
#else
|
||||
newcell = new (os_segment::of(this)) PCollection_SeqNode(LastItem,T);
|
||||
#endif
|
||||
if (Size == 0) FirstItem = newcell;
|
||||
if (!LastItem.IsNull()) LastItem->SetNext(newcell);
|
||||
LastItem = newcell;
|
||||
++Size;
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Append : Push a sequence at the end of the sequence
|
||||
// ---------------------------------------------------
|
||||
void PCollection_HSequence::Append(const Handle(PCollection_HSequence)& S)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= S->Length(); i++)
|
||||
Append (S->Value(i));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Prepend : Push an element at the begining of the sequence
|
||||
// ---------------------------------------------------------
|
||||
void PCollection_HSequence::Prepend(const Item& T)
|
||||
{
|
||||
Handle(PCollection_SeqNode) newcell;
|
||||
#ifndef OBJS
|
||||
newcell = new PCollection_SeqNode(T,FirstItem);
|
||||
#else
|
||||
newcell = new (os_segment::of(this)) PCollection_SeqNode(T,FirstItem);
|
||||
#endif
|
||||
if (Size == 0) LastItem = newcell;
|
||||
if (!FirstItem.IsNull()) FirstItem->SetPrevious(newcell);
|
||||
FirstItem = newcell;
|
||||
++Size;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Prepend : Push a sequence at the begining of the sequence
|
||||
// ---------------------------------------------------------
|
||||
void PCollection_HSequence::Prepend(const Handle (PCollection_HSequence)& S)
|
||||
{
|
||||
for (Standard_Integer i = S->Length(); i >= 1; i--)
|
||||
Prepend (S->Value(i));
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Reverse : Reverse the order of a given sequence
|
||||
// ---------------------------------------------------------
|
||||
void PCollection_HSequence::Reverse()
|
||||
{
|
||||
if (Size == 0 || Size == 1) return;
|
||||
Handle(PCollection_SeqNode) back,next,temp;
|
||||
temp = LastItem;
|
||||
while (!temp.IsNull())
|
||||
{
|
||||
back = temp->Previous();
|
||||
next = temp->Next();
|
||||
temp->SetNext(back);
|
||||
temp->SetPrevious(next);
|
||||
temp = temp->Next();
|
||||
}
|
||||
temp = FirstItem;
|
||||
FirstItem = LastItem;
|
||||
LastItem = temp;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// InsertBefore : Insert an item before a given index in the sequence
|
||||
// --------------------------------------------------------------------
|
||||
void PCollection_HSequence::InsertBefore(const Standard_Integer Index,
|
||||
const Item& T)
|
||||
{
|
||||
if ( Index <= 0 || Index > Length() ) Standard_OutOfRange::Raise();
|
||||
if ( Index == 1 ) {
|
||||
Prepend (T);
|
||||
return;
|
||||
}
|
||||
|
||||
//Index research
|
||||
Standard_Integer i = 1;
|
||||
Handle(PCollection_SeqNode) cell = FirstItem;
|
||||
while (i != Index) {
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
|
||||
// Insertion before Index
|
||||
Handle(PCollection_SeqNode) previous = cell->Previous();
|
||||
#ifndef OBJS
|
||||
Handle(PCollection_SeqNode) temp = new PCollection_SeqNode(previous,cell,T);
|
||||
#else
|
||||
Handle(PCollection_SeqNode) temp = new (os_segment::of(this)) PCollection_SeqNode(previous,cell,T);
|
||||
#endif
|
||||
previous->SetNext(temp);
|
||||
cell->SetPrevious(temp);
|
||||
++Size;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// InsertBefore : Insert a sequence before a specific index in a sequence
|
||||
// ----------------------------------------------------------------------
|
||||
void PCollection_HSequence::InsertBefore(const Standard_Integer Index ,
|
||||
const Handle(PCollection_HSequence)& S)
|
||||
{
|
||||
if ( Index <= 0 || Index > Size ) Standard_OutOfRange::Raise();
|
||||
for (Standard_Integer i = 1, j = Index ; i <= S->Length(); i++,j++)
|
||||
InsertBefore(j,S->Value(i));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// InsertAfter : Insert an element after a given index in a sequence
|
||||
// -----------------------------------------------------------------
|
||||
void PCollection_HSequence::InsertAfter(const Standard_Integer Index,
|
||||
const Item& T)
|
||||
{
|
||||
if ( Index <= 0 || Index > Length() ) Standard_OutOfRange::Raise();
|
||||
if ( Index == Size )
|
||||
Append (T);
|
||||
else
|
||||
InsertBefore (Index+1,T);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// InsertAfter : Insert a sequence after a given index in the sequence
|
||||
// -------------------------------------------------------------------
|
||||
void PCollection_HSequence::InsertAfter(const Standard_Integer Index,
|
||||
const Handle(PCollection_HSequence)&S)
|
||||
{
|
||||
if ( Index <= 0 || Index > Length() ) Standard_OutOfRange::Raise();
|
||||
for (Standard_Integer i = 1, j = Index ; i <= S->Length(); i++,j++)
|
||||
InsertAfter (j,S->Value(i));
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Exchange : Exchange two elements in the sequence
|
||||
// ----------------------------------------
|
||||
void PCollection_HSequence::Exchange(const Standard_Integer I,
|
||||
const Standard_Integer J)
|
||||
{
|
||||
if ( I <= 0 || J <= 0 || I > Length() || J > Length() )
|
||||
Standard_OutOfRange::Raise();
|
||||
Item T = Value(J);
|
||||
SetValue(J,Value(I));
|
||||
SetValue(I,T);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// SubSequence : Returns a sub-sequence from a sequence
|
||||
// ----------------------------------------------------
|
||||
Handle(PCollection_HSequence) PCollection_HSequence::SubSequence
|
||||
(const Standard_Integer From,const Standard_Integer To) const
|
||||
{
|
||||
if ( From <= 0 || From > Length() ||
|
||||
To <= 0 || To > Length() || To < From ) Standard_OutOfRange::Raise();
|
||||
#ifndef OBJS
|
||||
Handle (PCollection_HSequence) SubSeq = new PCollection_HSequence;
|
||||
#else
|
||||
Handle (PCollection_HSequence) SubSeq = new (os_segment::of(this)) PCollection_HSequence;
|
||||
#endif
|
||||
for(Standard_Integer i = From ; i <= To; i++)
|
||||
SubSeq->Append(Value(i));
|
||||
return SubSeq;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Split : Split a sequence in two sub-sequences
|
||||
// ---------------------------------------------
|
||||
Handle (PCollection_HSequence)
|
||||
PCollection_HSequence::Split(const Standard_Integer Index)
|
||||
{
|
||||
Standard_Integer i ;
|
||||
if ( Index <= 0 || Index > Length() ) Standard_OutOfRange::Raise();
|
||||
|
||||
// construct the new sequence
|
||||
#ifndef OBJS
|
||||
Handle(PCollection_HSequence) Seq = new PCollection_HSequence;
|
||||
#else
|
||||
Handle(PCollection_HSequence) Seq = new (os_segment::of(this)) PCollection_HSequence;
|
||||
#endif
|
||||
for (i = Index ; i<= Size; i++)
|
||||
Seq->Append(Value(i));
|
||||
|
||||
// Update the old sequence
|
||||
if (Index == 1 ) {
|
||||
Clear();
|
||||
return Seq;
|
||||
}
|
||||
// Index research
|
||||
i = 1;
|
||||
Handle(PCollection_SeqNode) cell = FirstItem;
|
||||
while (i != Index-1) {
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
// Re-build the Sequence
|
||||
Handle(PCollection_SeqNode) pnul;
|
||||
pnul.Nullify();
|
||||
LastItem = cell;
|
||||
LastItem->SetNext(pnul);
|
||||
Size = Index - 1 ;
|
||||
return Seq;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// SetValue : Change the element of a given index in a sequence
|
||||
// ----------------------------------------------------------
|
||||
void PCollection_HSequence::SetValue(const Standard_Integer Index,
|
||||
const Item& T)
|
||||
{
|
||||
if (Index <= 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
|
||||
// Index research
|
||||
Standard_Integer i = 1;
|
||||
Handle(PCollection_SeqNode) cell = FirstItem;
|
||||
while (i != Index ) {
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
// Change the value of the node
|
||||
cell->SetValue(T);
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Value : Return the value of a given index
|
||||
// -----------------------------------------
|
||||
Item PCollection_HSequence::Value(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index <= 0 || Index > Length()) Standard_OutOfRange::Raise();
|
||||
// Index research
|
||||
Standard_Integer i = 1;
|
||||
Handle(PCollection_SeqNode) cell = FirstItem;
|
||||
while (i != Index ) {
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
// returns the value of the node
|
||||
return cell->Value();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Contains : Returns True if the sequence contains a given element
|
||||
// ----------------------------------------------------------------
|
||||
//Standard_Boolean PCollection_HSequence::Contains(const Item& T) const
|
||||
Standard_Boolean PCollection_HSequence::Contains(const Item& ) const
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_HSequence::Contains : Obsolete method...");
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Location : returns the index of the nth occurence of an item.
|
||||
// -------------------------------------------------------------
|
||||
//Standard_Integer PCollection_HSequence::Location(const Standard_Integer N,
|
||||
// const Item& T,
|
||||
// const Standard_Integer From,
|
||||
// const Standard_Integer To) const
|
||||
Standard_Integer PCollection_HSequence::Location(const Standard_Integer ,
|
||||
const Item& ,
|
||||
const Standard_Integer ,
|
||||
const Standard_Integer ) const
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_HSequence::Location : Obsolete method...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Location : returns the index of the nth occurence of an item.
|
||||
// -------------------------------------------------------------
|
||||
//Standard_Integer PCollection_HSequence::
|
||||
// Location(const Standard_Integer N,const Item& T) const
|
||||
Standard_Integer PCollection_HSequence::
|
||||
Location(const Standard_Integer ,const Item& ) const
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_HSequence::Location : Obsolete method...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Remove : Remove an item in a sequence
|
||||
// -------------------------------------
|
||||
void PCollection_HSequence::Remove(const Standard_Integer Index)
|
||||
{
|
||||
if (Index <= 0 || Index > Size ) Standard_OutOfRange::Raise();
|
||||
if (Size == 1) {
|
||||
Size = 0;
|
||||
FirstItem.Nullify();
|
||||
#ifndef CSFDB
|
||||
LastItem.Delete(); // free memory
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
Handle(PCollection_SeqNode) pnul,cell,previous,next;
|
||||
pnul.Nullify();
|
||||
if ( Index == 1 ) { // Remove the first Index
|
||||
cell = FirstItem;
|
||||
FirstItem = FirstItem->Next();
|
||||
FirstItem->SetPrevious(pnul);
|
||||
#ifndef CSFDB
|
||||
cell.Delete(); // free memory
|
||||
#endif
|
||||
--Size;
|
||||
} else if ( Index == Size ) { // Remove the last Index
|
||||
cell = LastItem;
|
||||
LastItem = LastItem->Previous();
|
||||
LastItem->SetNext(pnul);
|
||||
#ifndef CSFDB
|
||||
cell.Delete(); // free memory
|
||||
#endif
|
||||
--Size;
|
||||
} else {
|
||||
Standard_Integer i = 1;
|
||||
cell = FirstItem;
|
||||
while (i != Index) {
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
previous = cell->Previous();
|
||||
next = cell->Next();
|
||||
previous->SetNext(next);
|
||||
next->SetPrevious(previous);
|
||||
#ifndef CSFDB
|
||||
cell.Delete(); // free memory
|
||||
#endif
|
||||
--Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// Remove a set of items
|
||||
// ---------------------
|
||||
void PCollection_HSequence::Remove(const Standard_Integer From,const Standard_Integer To)
|
||||
{
|
||||
if (From <= 0 || From > Size || To <= 0 || To > Size || From > To )
|
||||
Standard_OutOfRange::Raise();
|
||||
for (Standard_Integer i = From; i<= To; i++) Remove(From);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// First : Returns the first element of the sequence
|
||||
// Raises an exeption if the sequence is empty
|
||||
// ----------------------------------------------------
|
||||
Item PCollection_HSequence::First() const
|
||||
{
|
||||
if (Size == 0) Standard_NoSuchObject::Raise();
|
||||
return FirstItem->Value();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Last : Returns the last element of the sequence
|
||||
// Raises an exeption if the sequence is empty
|
||||
// ----------------------------------------------------
|
||||
Item PCollection_HSequence::Last() const
|
||||
{
|
||||
if (Size == 0) Standard_NoSuchObject::Raise();
|
||||
return LastItem->Value();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
//
|
||||
// ShallowCopy
|
||||
//
|
||||
// ----------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HSequence::ShallowCopy() const
|
||||
{
|
||||
Handle (PCollection_HSequence) TheCopy ;
|
||||
Handle (PCollection_SeqNode) TheList ;
|
||||
|
||||
#ifndef OBJS
|
||||
TheCopy = new PCollection_HSequence;
|
||||
#else
|
||||
TheCopy = new (os_segment::of(this)) PCollection_HSequence;
|
||||
#endif
|
||||
TheList = FirstItem;
|
||||
for (Standard_Integer I = 1; I <= Size; I++) {
|
||||
TheCopy->Append(TheList->Value());
|
||||
TheList = TheList->Next();
|
||||
}
|
||||
|
||||
return TheCopy;
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
//
|
||||
// ShallowDump
|
||||
// ----------------------------------------------------
|
||||
void PCollection_HSequence::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class Sequence "<< endl;
|
||||
S << "Size : "<< Size << "element(s)." << endl;
|
||||
Standard_Integer i = 1;
|
||||
Handle(PCollection_SeqNode) cell = FirstItem;
|
||||
while ( !cell.IsNull() ) {
|
||||
S << "Index : "<< i << endl;
|
||||
// ::ShallowDump(cell->Value(),S);
|
||||
cell = cell->Next();
|
||||
++i;
|
||||
}
|
||||
S << "end class Sequence" << endl;
|
||||
}
|
||||
|
||||
|
||||
// IsEmpty : Returns Standard_True if the sequence is empty (i.e. Size = 0)
|
||||
Standard_Boolean PCollection_HSequence::IsEmpty() const
|
||||
{
|
||||
return (Size == 0);
|
||||
}
|
||||
|
||||
// Length : Returns the length of the sequence
|
||||
Standard_Integer PCollection_HSequence::Length() const
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
// GetFirst : Returns the field "FirstItem"
|
||||
Handle(PCollection_SeqNode) PCollection_HSequence::GetFirst() const
|
||||
{
|
||||
return FirstItem;
|
||||
}
|
||||
|
||||
// GetLast : Returns the field "LastItem"
|
||||
Handle(PCollection_SeqNode) PCollection_HSequence::GetLast() const
|
||||
{
|
||||
return LastItem;
|
||||
}
|
||||
|
||||
void PCollection_HSequence::Destroy()
|
||||
{
|
||||
#ifdef CSFDB
|
||||
Clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
163
src/PCollection/PCollection_HSet.cdl
Executable file
163
src/PCollection/PCollection_HSet.cdl
Executable file
@@ -0,0 +1,163 @@
|
||||
-- File: PCollection_HSet.cdl
|
||||
-- Created: Mon Sep 2 14:45:39 1991
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <apc@topsn1>
|
||||
---Copyright: Matra Datavision 1991
|
||||
|
||||
|
||||
|
||||
generic class HSet from PCollection (Item as Storable)
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: A set is an unordered collection of items.
|
||||
-- We can not have duplicated items in a given set.
|
||||
|
||||
raises NoSuchObject from Standard
|
||||
|
||||
|
||||
class SetNode instantiates HSingleList from PCollection(Item);
|
||||
|
||||
class SetIterator from PCollection
|
||||
---Purpose: Iterator of the Set class.
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create(S : HSet from PCollection)
|
||||
returns SetIterator from PCollection;
|
||||
---Purpose: Creates an iterator on the set S.
|
||||
-- Set the iterator at the beginning of the set S.
|
||||
|
||||
More(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if there are other items.
|
||||
|
||||
Next(me: in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next item.
|
||||
|
||||
Value(me) returns any Item raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the item value corresponding to
|
||||
-- the current position of the iterator.
|
||||
|
||||
fields
|
||||
TheIterator : SetNode;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
|
||||
Create returns mutable HSet from PCollection;
|
||||
---Purpose: Creation of an empty set.
|
||||
|
||||
Extent(me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Number of items in the set me
|
||||
---Example: if S is the set {a,b,c,d,e}
|
||||
-- Extent returns 5
|
||||
|
||||
Last(me) returns SetNode;
|
||||
---Level: Public
|
||||
---Purpose: Returns the field TheLast .
|
||||
-- (the last item enterred in the set)
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the set me is empty.
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the items of the set me.
|
||||
---Example: before
|
||||
-- me = {a,b,c,d}
|
||||
-- after
|
||||
-- me = {}
|
||||
|
||||
Add(me : mutable; T : Item) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Adds an item T in the set me if it does not already exist.
|
||||
-- Returns False if the item T already exists, True otherwise.
|
||||
---Example: before
|
||||
-- me = {a,b,c,d}, T = y
|
||||
-- after
|
||||
-- me = {a,b,c,d,y}
|
||||
|
||||
Remove(me : mutable; T : Item) raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes the item T in the set me
|
||||
-- Raises an exception if the item is not in the set.
|
||||
---Example: before
|
||||
-- me = {a,b,c,d}, T = a
|
||||
-- after
|
||||
-- me = {b,c,d}
|
||||
-- returns ()
|
||||
|
||||
Union(me; B : HSet from PCollection) returns mutable HSet from PCollection;
|
||||
---Level: Public
|
||||
---Purpose: Creation of a set containing all the items
|
||||
-- of the set me and all the items of the set B which
|
||||
-- are not in me.
|
||||
---Example: before
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- after
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- returns
|
||||
-- {a,b,c,d,f}
|
||||
|
||||
Intersection(me; B : HSet from PCollection) returns mutable HSet from PCollection;
|
||||
---Level: Public
|
||||
---Purpose: Creation of a set containing all the
|
||||
-- items which are both in the set <me> and in the set B.
|
||||
---Example: before
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- after
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- returns
|
||||
-- {a}
|
||||
|
||||
Difference(me; B: HSet from PCollection) returns mutable HSet from PCollection;
|
||||
---Level: Public
|
||||
---Purpose: Creation of a set containing the items
|
||||
-- which are in the set me and not in the set B.
|
||||
---Example: before
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- after
|
||||
-- me = {a,b,c}, B = {d,a,f}
|
||||
-- returns
|
||||
-- {b,c}
|
||||
|
||||
Contains(me; T : Item) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if an item is in the set me.
|
||||
|
||||
IsASubset(me; S : HSet from PCollection) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if a set is contained in the set me.
|
||||
-- The two sets can be identical.
|
||||
|
||||
IsAProperSubset(me; S : HSet from PCollection) returns Boolean from
|
||||
Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if a set is contained in the set me.
|
||||
-- The two sets cannot be identical.
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
|
||||
fields
|
||||
TheExtent : Integer from Standard;
|
||||
TheLast : SetNode;
|
||||
end;
|
389
src/PCollection/PCollection_HSet.gxx
Executable file
389
src/PCollection/PCollection_HSet.gxx
Executable file
@@ -0,0 +1,389 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
|
||||
// ------------
|
||||
// constructor
|
||||
// -----------
|
||||
|
||||
PCollection_HSet::PCollection_HSet()
|
||||
{
|
||||
TheExtent = 0;
|
||||
TheLast = new PCollection_SetNode;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// IsEmpty : is the Set empty ?
|
||||
// -----------------------------
|
||||
Standard_Boolean PCollection_HSet::IsEmpty() const
|
||||
{
|
||||
return TheLast->IsEmpty();
|
||||
}
|
||||
|
||||
// ----------------
|
||||
// Contains an item
|
||||
// ----------------
|
||||
Standard_Boolean PCollection_HSet::Contains(const Item& T) const
|
||||
{
|
||||
Standard_Boolean Ilela;
|
||||
Handle(PCollection_SetNode) TheCurrent;
|
||||
TheCurrent = TheLast;
|
||||
Ilela = Standard_False;
|
||||
while (!Ilela && !TheCurrent->IsEmpty())
|
||||
{
|
||||
if (TheCurrent->Value() == T)
|
||||
Ilela = Standard_True;
|
||||
else
|
||||
TheCurrent = TheCurrent->Tail();
|
||||
};
|
||||
return Ilela;
|
||||
}
|
||||
|
||||
// ---------------------------------
|
||||
// The Set S IsASubset of the set me
|
||||
// ---------------------------------
|
||||
Standard_Boolean PCollection_HSet::IsASubset(const Handle(PCollection_HSet)& S) const
|
||||
{
|
||||
Standard_Boolean Ilela,Ilsonla;
|
||||
Handle(PCollection_SetNode) TheCurrent1,TheCurrent2;
|
||||
TheCurrent1 = TheLast;
|
||||
TheCurrent2 = S->Last();
|
||||
Ilela = Standard_False;
|
||||
Ilsonla = Standard_True;
|
||||
while (Ilsonla && !TheCurrent2->IsEmpty())
|
||||
{
|
||||
while (!Ilela && !TheCurrent1->IsEmpty())
|
||||
{
|
||||
if (TheCurrent1->Value() == TheCurrent2->Value())
|
||||
Ilela = Standard_True;
|
||||
else
|
||||
TheCurrent1 = TheCurrent1->Tail();
|
||||
};
|
||||
if (!Ilela)
|
||||
Ilsonla = Standard_False;
|
||||
else
|
||||
{
|
||||
TheCurrent2 = TheCurrent2->Tail();
|
||||
TheCurrent1 = TheLast;
|
||||
};
|
||||
};
|
||||
return Ilsonla;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
// The Set S IsAProperSubset of the set me
|
||||
// ----------------------------------------
|
||||
Standard_Boolean PCollection_HSet::IsAProperSubset(const Handle(PCollection_HSet)& S) const
|
||||
{
|
||||
Standard_Boolean Ilela,Ilsonla;
|
||||
Handle(PCollection_SetNode) TheCurrent1,TheCurrent2;
|
||||
TheCurrent1 = TheLast;
|
||||
TheCurrent2 = S->Last();
|
||||
Ilela = Standard_False;
|
||||
Ilsonla = Standard_True;
|
||||
if (S->Extent() >= TheExtent) Ilsonla = Standard_False;
|
||||
while (Ilsonla && !TheCurrent2->IsEmpty())
|
||||
{
|
||||
while (!Ilela && !TheCurrent1->IsEmpty())
|
||||
{
|
||||
if (TheCurrent1->Value() == TheCurrent2->Value())
|
||||
Ilela = Standard_True;
|
||||
else
|
||||
TheCurrent1 = TheCurrent1->Tail();
|
||||
};
|
||||
if (!Ilela)
|
||||
Ilsonla = Standard_False;
|
||||
else
|
||||
{
|
||||
TheCurrent2 = TheCurrent2->Tail();
|
||||
TheCurrent1 = TheLast;
|
||||
};
|
||||
};
|
||||
return Ilsonla;
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Clear : remove all items
|
||||
// ------------------------------------
|
||||
void PCollection_HSet::Clear()
|
||||
{
|
||||
Handle(PCollection_SetNode) temp;
|
||||
while (TheExtent != 0) {
|
||||
temp = TheLast;
|
||||
TheLast = TheLast->Tail();
|
||||
#ifndef CSFDB
|
||||
temp.Delete();
|
||||
#endif
|
||||
--TheExtent;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------
|
||||
// Add : insert an item
|
||||
// returns Standard_True if the item has been inserted,
|
||||
// Standard_False otherwise
|
||||
// -------------------------------------------
|
||||
Standard_Boolean PCollection_HSet::Add(const Item& T)
|
||||
{
|
||||
Standard_Boolean Dejala;
|
||||
Handle(PCollection_SetNode) TheCurrent;
|
||||
TheCurrent = TheLast;
|
||||
Dejala = Standard_False;
|
||||
while (!Dejala && !TheCurrent->IsEmpty())
|
||||
{ if (TheCurrent->Value() == T) Dejala = Standard_True;
|
||||
TheCurrent = TheCurrent->Tail();
|
||||
};
|
||||
if (!Dejala)
|
||||
{
|
||||
TheLast = TheLast->Construct(T);
|
||||
TheExtent = TheExtent + 1;
|
||||
};
|
||||
return !Dejala;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Remove : remove an item
|
||||
// from the set me.
|
||||
// Raises Standard_NoSuchObject
|
||||
// ------------------------
|
||||
void PCollection_HSet::Remove(const Item& T)
|
||||
{
|
||||
Standard_Boolean Nepala;
|
||||
Handle(PCollection_SetNode) TheCurrent,ThePrevious;
|
||||
TheCurrent = TheLast;
|
||||
ThePrevious = TheLast;
|
||||
Nepala = Standard_True;
|
||||
while (Nepala && !TheCurrent->IsEmpty()) {
|
||||
if (TheCurrent->Value() == T)
|
||||
Nepala = Standard_False;
|
||||
else {
|
||||
ThePrevious = TheCurrent;
|
||||
TheCurrent = TheCurrent->Tail();
|
||||
}
|
||||
}
|
||||
if (Nepala)
|
||||
Standard_NoSuchObject::Raise();
|
||||
else {
|
||||
if (TheCurrent == ThePrevious)
|
||||
TheLast = TheLast->Tail();
|
||||
else
|
||||
ThePrevious->ChangeForwardPointer(TheCurrent->Tail());
|
||||
TheExtent = TheExtent - 1;
|
||||
#ifndef CSFDB
|
||||
TheCurrent.Delete();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Union with the set S
|
||||
// returns a set containing all the
|
||||
// items of the set me and all the items
|
||||
// of the set B which are not in me
|
||||
// ------------------------------------
|
||||
Handle(PCollection_HSet) PCollection_HSet::Union(const Handle(PCollection_HSet)& S)
|
||||
const
|
||||
{
|
||||
Standard_Boolean Insere;
|
||||
Handle(PCollection_SetNode) TheCurrent;
|
||||
Handle(PCollection_HSet) Lunion;
|
||||
Lunion = new PCollection_HSet;
|
||||
// copier this dans Lunion
|
||||
TheCurrent = TheLast;
|
||||
while (!TheCurrent->IsEmpty())
|
||||
{
|
||||
Insere = Lunion->Add(TheCurrent->Value());
|
||||
TheCurrent = TheCurrent->Tail();
|
||||
};
|
||||
// Inserer dans Lunion les items de S
|
||||
TheCurrent = S->Last();
|
||||
while (!TheCurrent->IsEmpty())
|
||||
{
|
||||
Insere = Lunion->Add(TheCurrent->Value());
|
||||
TheCurrent = TheCurrent->Tail();
|
||||
};
|
||||
return Lunion;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Intersection with the set S
|
||||
// -----------------------------
|
||||
Handle(PCollection_HSet) PCollection_HSet::
|
||||
Intersection(const Handle(PCollection_HSet)& S)
|
||||
const
|
||||
{
|
||||
Item Litem;
|
||||
Standard_Boolean Insere;
|
||||
Handle(PCollection_SetNode) TheCurrent1,TheCurrent2;
|
||||
Handle(PCollection_HSet) Linter;
|
||||
Linter = new PCollection_HSet;
|
||||
TheCurrent1 = TheLast;
|
||||
while (!TheCurrent1->IsEmpty())
|
||||
{
|
||||
Litem = TheCurrent1->Value();
|
||||
TheCurrent2 = S->Last();
|
||||
while (!TheCurrent2->IsEmpty())
|
||||
{
|
||||
if (TheCurrent2->Value() == Litem)
|
||||
Insere = Linter->Add(Litem);
|
||||
TheCurrent2 = TheCurrent2->Tail();
|
||||
};
|
||||
TheCurrent1 = TheCurrent1->Tail();
|
||||
};
|
||||
return Linter;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// Difference with the set S
|
||||
// returns a set containing the
|
||||
// items which are in the set me
|
||||
// and not in the set B
|
||||
// -----------------------------
|
||||
Handle(PCollection_HSet) PCollection_HSet::
|
||||
Difference(const Handle(PCollection_HSet)& S)
|
||||
const
|
||||
{
|
||||
Item Litem;
|
||||
Standard_Boolean Insere,Ilela;
|
||||
Handle(PCollection_SetNode) TheCurrent1,TheCurrent2;
|
||||
Handle(PCollection_HSet) Ladif;
|
||||
Ladif = new PCollection_HSet;
|
||||
TheCurrent1 = TheLast;
|
||||
while (!TheCurrent1->IsEmpty())
|
||||
{
|
||||
Litem = TheCurrent1->Value();
|
||||
TheCurrent2 = S->Last();
|
||||
Ilela = Standard_False;
|
||||
while (!TheCurrent2->IsEmpty() && !Ilela)
|
||||
{
|
||||
if (TheCurrent2->Value() == Litem)
|
||||
Ilela = Standard_True;
|
||||
else
|
||||
TheCurrent2 = TheCurrent2->Tail();
|
||||
};
|
||||
if (!Ilela)
|
||||
Insere = Ladif->Add(Litem);
|
||||
TheCurrent1 = TheCurrent1->Tail();
|
||||
};
|
||||
return Ladif;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ShallowCopy
|
||||
//---------------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HSet::ShallowCopy() const
|
||||
{
|
||||
|
||||
PCollection_HSet* TheCopy = new PCollection_HSet (*this);
|
||||
TheCopy->TheLast =
|
||||
Handle(PCollection_SetNode)::DownCast(::ShallowCopy(TheLast));
|
||||
return TheCopy;
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ShallowDump
|
||||
//---------------------------------------------------------------------
|
||||
void PCollection_HSet::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
|
||||
S << "begin class Set "<<endl;
|
||||
S << "extent of Set : "<< TheExtent << endl;
|
||||
TheLast->ShallowDump(S);
|
||||
S << "end of class Set." << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// Extent : numbers of items
|
||||
// -----------------------------
|
||||
Standard_Integer PCollection_HSet::Extent() const {
|
||||
return TheExtent;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Last : last enterred item
|
||||
// -----------------------------
|
||||
Handle(PCollection_SetNode) PCollection_HSet::Last() const {
|
||||
return TheLast;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
102
src/PCollection/PCollection_HSingleList.cdl
Executable file
102
src/PCollection/PCollection_HSingleList.cdl
Executable file
@@ -0,0 +1,102 @@
|
||||
-- File: PCollection_HSingleList.cdl
|
||||
-- Created: Wed Feb 19 14:24:56 1992
|
||||
-- Author: Jean Pierre TIRAULT
|
||||
-- <jpt@topsn1>
|
||||
generic class HSingleList from PCollection (Item as Storable)
|
||||
inherits PManaged
|
||||
|
||||
raises
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
---Purpose: Definition of a single linked list.
|
||||
|
||||
Create returns mutable HSingleList;
|
||||
---Creation of an empty list.
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the list contains no element.
|
||||
|
||||
|
||||
Construct(me; T : Item) returns mutable
|
||||
HSingleList;
|
||||
---Level: Public
|
||||
---Purpose: add T at the begining of me
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- (T A B C)
|
||||
|
||||
Value(me) returns any Item
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the value of the first node of me.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- A
|
||||
|
||||
Tail(me) returns any HSingleList
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: End of the list me.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- (B C)
|
||||
|
||||
SwapTail(me : mutable; WithList : in out any HSingleList)
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Exchanges the end of <me> with the list WithList.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- WithList = (D E)
|
||||
-- after
|
||||
-- me = (A D E)
|
||||
-- WithList = (B C)
|
||||
|
||||
SetValue(me : mutable; T : Item)
|
||||
raises NoSuchObject from Standard ;
|
||||
---Level: Public
|
||||
---Purpose: Changes the value of the first node of me.
|
||||
-- Raises an exception if me is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (T B C)
|
||||
|
||||
ChangeForwardPointer(me : mutable; ForwardPointer : HSingleList);
|
||||
---Level: Public
|
||||
---Purpose: Modification of the node link.
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
|
||||
fields
|
||||
Data : Item;
|
||||
Next : HSingleList;
|
||||
|
||||
end HSingleList;
|
164
src/PCollection/PCollection_HSingleList.gxx
Executable file
164
src/PCollection/PCollection_HSingleList.gxx
Executable file
@@ -0,0 +1,164 @@
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// HSingleList implementation:
|
||||
//
|
||||
// Last Revision : Feb,10 1992 J.P Tirault
|
||||
// Implementation of ShallowCopy, ShallowDump
|
||||
// methods.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
#include <Standard_OStream.hxx>
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -
|
||||
// Constructor Returns an empty list -
|
||||
// ---------- -
|
||||
// -
|
||||
// -------------------------------------------------------------------------
|
||||
PCollection_HSingleList::PCollection_HSingleList ()
|
||||
{
|
||||
Next.Nullify();
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -
|
||||
// Construct : Add an item at the beginning of the list -
|
||||
// --------- -
|
||||
// -
|
||||
// -------------------------------------------------------------------------
|
||||
Handle(PCollection_HSingleList)
|
||||
PCollection_HSingleList::Construct(const Item& T)const
|
||||
{
|
||||
|
||||
|
||||
Handle(PCollection_HSingleList) me , L ;
|
||||
me = this;
|
||||
#ifndef OBJS
|
||||
L = new PCollection_HSingleList;
|
||||
#else
|
||||
L = new (os_segment::of(this)) PCollection_HSingleList;
|
||||
#endif
|
||||
L->ChangeForwardPointer ( me );
|
||||
L->SetValue ( T );
|
||||
return L;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -
|
||||
// Shallowcopy : Redefinition of the shallowcopy dump -
|
||||
// ----------- -
|
||||
|
||||
// -
|
||||
// -------------------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_HSingleList::ShallowCopy() const
|
||||
{
|
||||
Handle(PCollection_HSingleList) TheList, // Traversal depth of <this>
|
||||
TheCopy, // The list returned
|
||||
Pred, // Backward pointer
|
||||
Succ; // Forward pointer
|
||||
#ifndef OBJS
|
||||
TheCopy = new PCollection_HSingleList; // Initialization of the list
|
||||
#else
|
||||
TheCopy = new (os_segment::of(this)) PCollection_HSingleList; // Initialization of the list
|
||||
#endif
|
||||
// that will be returned
|
||||
Standard_Boolean FirstTime = Standard_True;
|
||||
|
||||
TheList = this; // Start at the beginning
|
||||
Pred = Succ = TheCopy;
|
||||
|
||||
while ( ! TheList->IsEmpty() ) { // Append each item at the
|
||||
Succ = Succ->Construct(TheList->Value()); // end of the list
|
||||
if ( FirstTime ){
|
||||
FirstTime = Standard_False;
|
||||
TheCopy = Succ;
|
||||
}
|
||||
else{
|
||||
Pred->ChangeForwardPointer(Succ); // Make the link between
|
||||
} // Pred and Succ
|
||||
Pred = Succ;
|
||||
Succ = Succ->Tail();
|
||||
TheList = TheList->Tail();
|
||||
}
|
||||
return TheCopy; // Returns the header
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -
|
||||
// ShallowDump Redefinition of the shallowdump method -
|
||||
// ----------- -
|
||||
// -
|
||||
// -------------------------------------------------------------------------
|
||||
void PCollection_HSingleList::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
Handle(PCollection_HSingleList) TheList;
|
||||
TheList = this;
|
||||
S << "begin class HSingleList " << endl;
|
||||
while ( ! TheList->IsEmpty() ) {
|
||||
::ShallowDump(TheList->Value(), S);
|
||||
TheList = TheList->Tail();
|
||||
}
|
||||
S << "end class HSingleList" << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Anciens INLINE */
|
||||
|
||||
Item PCollection_HSingleList::Value() const {
|
||||
Standard_NoSuchObject_Raise_if(IsEmpty(),
|
||||
"Empty Element in HSingleList::Value");
|
||||
return Data;
|
||||
}
|
||||
|
||||
Handle(PCollection_HSingleList) PCollection_HSingleList::Tail() const {
|
||||
Standard_NoSuchObject_Raise_if (IsEmpty(),
|
||||
"Empty Element in HSingleList::Value");
|
||||
return Next;
|
||||
}
|
||||
|
||||
|
||||
Standard_Boolean PCollection_HSingleList::IsEmpty()const
|
||||
{
|
||||
return Next.IsNull();
|
||||
}
|
||||
|
||||
|
||||
void PCollection_HSingleList::SetValue(const Item& T)
|
||||
{
|
||||
Standard_NoSuchObject_Raise_if (IsEmpty(),
|
||||
"Empty Element in HSingleList::SetValue");
|
||||
Data = T;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -
|
||||
// SwapTail : Exchange the tail of the current list with an another list -
|
||||
// -------- -
|
||||
// -
|
||||
// -------------------------------------------------------------------------
|
||||
void PCollection_HSingleList::SwapTail(Handle(PCollection_HSingleList)&
|
||||
WithList)
|
||||
{
|
||||
Standard_NoSuchObject_Raise_if (IsEmpty(),
|
||||
"Empty Element in HSingleList::SwapTail");
|
||||
Handle(PCollection_HSingleList) L = Next;
|
||||
Next = WithList;
|
||||
WithList = L;
|
||||
}
|
||||
|
||||
|
||||
void PCollection_HSingleList::ChangeForwardPointer
|
||||
(const Handle(PCollection_HSingleList)& L)
|
||||
{
|
||||
Next = L;
|
||||
}
|
||||
|
||||
|
142
src/PCollection/PCollection_HStack.cdl
Executable file
142
src/PCollection/PCollection_HStack.cdl
Executable file
@@ -0,0 +1,142 @@
|
||||
-- File: PCollection_HStack.cdl
|
||||
-- Created: Mon Sep 2 14:48:13 1991
|
||||
-- Author: Mireille MERCIEN
|
||||
-- <apc@topsn1>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
generic class HStack from PCollection (Item as Storable)
|
||||
inherits Persistent
|
||||
|
||||
---Purpose: A stack is a list of items in which items are
|
||||
-- added and removed from the same end, called the
|
||||
-- top of the stack.
|
||||
|
||||
raises NoSuchObject from Standard
|
||||
|
||||
|
||||
class StackNode instantiates HSingleList from PCollection(Item);
|
||||
|
||||
class StackIterator from PCollection
|
||||
|
||||
---Purpose: Iterator of the Stack class.
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
is
|
||||
|
||||
Create(S : HStack from PCollection)
|
||||
returns StackIterator from PCollection;
|
||||
---Purpose: Creates an iterator on the stack S.
|
||||
-- Set the iterator at the beginning of the stack S.
|
||||
|
||||
More(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if there are other items.
|
||||
|
||||
Next(me: in out) raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Sets the iterator to the next item.
|
||||
|
||||
Value(me) returns any Item raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the item value corresponding to
|
||||
-- the current position of the iterator.
|
||||
|
||||
fields
|
||||
TheIterator : StackNode;
|
||||
end;
|
||||
|
||||
|
||||
is
|
||||
Create returns mutable HStack from PCollection;
|
||||
---Purpose: Creates an empty stack.
|
||||
|
||||
Depth(me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns the number of items in the stack.
|
||||
---Example: if me = (A B C)
|
||||
-- returns 3
|
||||
|
||||
IsEmpty(me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Returns True if the stack contains no item.
|
||||
|
||||
Top(me) returns any Item
|
||||
---Level: Public
|
||||
---Purpose: Returns the item on the top of the stack.
|
||||
-- Raises an exception if the stack is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
-- returns
|
||||
-- C
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
FTop(me) returns StackNode;
|
||||
---Level: Public
|
||||
---Purpose: Returns the field TheTop (the top of the stack).
|
||||
|
||||
Push(me : mutable; T : Item);
|
||||
---Level: Public
|
||||
---Purpose: Inserts an item on the top of the stack.
|
||||
---Example: before
|
||||
-- me = (A B) , T = C
|
||||
-- after
|
||||
-- me = (A B C)
|
||||
|
||||
Pop(me : mutable) raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Removes an item from the top of the stack.
|
||||
-- Raises an exception if the stack is empty.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = (A B)
|
||||
-- returns
|
||||
-- C
|
||||
|
||||
Clear(me : mutable);
|
||||
---Level: Public
|
||||
---Purpose: Removes all the items from the stack.
|
||||
---Example: before
|
||||
-- me = (A B C)
|
||||
-- after
|
||||
-- me = ()
|
||||
|
||||
ChangeTop(me:mutable; T : Item) raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
---Purpose: Replaces the top of the stack with T.
|
||||
-- Raises an exception if the stack is empty.
|
||||
---Example: before
|
||||
-- me = (A B C) , T = D
|
||||
-- after
|
||||
-- me = (A B D)
|
||||
|
||||
|
||||
ShallowCopy(me)
|
||||
returns mutable like me
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
ShallowDump (me; s: in out OStream)
|
||||
is redefined;
|
||||
---Level: Advanced
|
||||
---C++: function call
|
||||
|
||||
|
||||
|
||||
fields
|
||||
TheTop : StackNode;
|
||||
TheDepth : Integer from Standard;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
164
src/PCollection/PCollection_HStack.gxx
Executable file
164
src/PCollection/PCollection_HStack.gxx
Executable file
@@ -0,0 +1,164 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ------------
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
30
src/PCollection/PCollection_Hash.cdl
Executable file
30
src/PCollection/PCollection_Hash.cdl
Executable file
@@ -0,0 +1,30 @@
|
||||
-- File: PCollection_Hash.cdl
|
||||
-- Created: Mon Apr 22 16:26:20 1991
|
||||
-- Author: jean pierre TIRAULT
|
||||
-- <jpt@topsn1>
|
||||
---Copyright: Matra Datavision 1991
|
||||
|
||||
|
||||
generic class Hash from PCollection (key as Storable) inherits Storable
|
||||
is
|
||||
|
||||
|
||||
|
||||
Create returns Hash;
|
||||
---Purpose : Empty constructor.
|
||||
|
||||
|
||||
|
||||
HashCode (me; MyKey : key ; Upper : Integer)
|
||||
returns Integer is virtual;
|
||||
---Level: Public
|
||||
---Purpose: Returns a hashcod value of key bounded by Upper.
|
||||
|
||||
|
||||
|
||||
Compare (me; One , Two : key) returns Boolean is virtual;
|
||||
---Level: Public
|
||||
---Purpose : Compare two keys and returns a boolean value
|
||||
|
||||
end;
|
||||
|
48
src/PCollection/PCollection_Hash.gxx
Executable file
48
src/PCollection/PCollection_Hash.gxx
Executable file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Hash.gxx doesn't contains methods. All methods are inline methods.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// methods for hash class from PCollection.
|
||||
// Written by JPT FEB,24 1992
|
||||
// Copyright matra datavision 1992
|
||||
//
|
||||
// -----------------
|
||||
// Empty constructor
|
||||
// -----------------
|
||||
PCollection_Hash::PCollection_Hash(){}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// To remove the ambigous compilation warning between Hash::HashCode
|
||||
// and Storable::Hashcode
|
||||
// -----------------------------------------------------------------
|
||||
//Standard_Integer PCollection_Hash::HashCode
|
||||
// (const Standard_Integer Upper) const {
|
||||
|
||||
// return this % Upper;
|
||||
//}
|
||||
|
||||
// ------------------------------
|
||||
// The PCollection::Hascode method
|
||||
// ------------------------------
|
||||
Standard_Integer PCollection_Hash::HashCode(const key& K,
|
||||
const Standard_Integer Upper)
|
||||
const {
|
||||
|
||||
return ::HashCode(K,Upper);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// A method to compare two items
|
||||
// ------------------------------
|
||||
Standard_Boolean PCollection_Hash::Compare (const key& one,
|
||||
const key& two) const {
|
||||
|
||||
return(one == two);
|
||||
}
|
||||
|
||||
|
||||
|
158
src/PCollection/PCollection_IndexedDataMapNode.gxx
Executable file
158
src/PCollection/PCollection_IndexedDataMapNode.gxx
Executable file
@@ -0,0 +1,158 @@
|
||||
//-Copyright: Matra Datavision 1992
|
||||
//-Version:
|
||||
|
||||
//-History:
|
||||
// Version Date Purpose
|
||||
// 14/12/92 Creation
|
||||
|
||||
//-Language C++2.0
|
||||
|
||||
//=======================================================================
|
||||
// Function : PCollection_IndexedDataMapNode
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
PCollection_IndexedDataMapNode::PCollection_IndexedDataMapNode
|
||||
(
|
||||
const Key& aKey,
|
||||
const Standard_Integer Index,
|
||||
const Item& anItem,
|
||||
const Handle(PCollection_IndexedDataMapNode)& NextKey,
|
||||
const Handle(PCollection_IndexedDataMapNode)& NextIndex) :
|
||||
|
||||
myKey(aKey), myIndex(Index), myItem(anItem),
|
||||
myNextKey(NextKey), myNextIndex(NextIndex)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : Set
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::Set
|
||||
(
|
||||
const Key& aKey,
|
||||
const Standard_Integer Index,
|
||||
const Item& anItem,
|
||||
const Handle(PCollection_IndexedDataMapNode)& NextK,
|
||||
const Handle(PCollection_IndexedDataMapNode)& NextI)
|
||||
|
||||
{
|
||||
myKey = aKey;
|
||||
myIndex = Index;
|
||||
myItem = anItem;
|
||||
myNextKey = NextK;
|
||||
myNextIndex = NextI;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : GetKey
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Key PCollection_IndexedDataMapNode::GetKey() const
|
||||
{
|
||||
return myKey;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Function : Index
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer PCollection_IndexedDataMapNode::Index() const
|
||||
{
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Function : GetItem
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Item PCollection_IndexedDataMapNode::GetItem() const
|
||||
{
|
||||
return myItem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : KeyAndItem
|
||||
// Purpose : get two fields
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::KeyAndItem(Key& theKey, Item& theItem) const
|
||||
{
|
||||
theKey = myKey;
|
||||
theItem = myItem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : IndexAndItem
|
||||
// Purpose : get two fields
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::IndexAndItem(Standard_Integer& Index,
|
||||
Item& theItem) const
|
||||
{
|
||||
Index = myIndex;
|
||||
theItem = myItem;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Function : NextKey
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_IndexedDataMapNode)
|
||||
PCollection_IndexedDataMapNode::NextKey() const
|
||||
{
|
||||
return myNextKey;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : NextIndex
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(PCollection_IndexedDataMapNode)
|
||||
PCollection_IndexedDataMapNode::NextIndex() const
|
||||
{
|
||||
return myNextIndex;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetItem
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::SetItem(const Item& anItem)
|
||||
{
|
||||
myItem = anItem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetNextKey
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::
|
||||
SetNextKey(const Handle(PCollection_IndexedDataMapNode)& aNode)
|
||||
{
|
||||
myNextKey = aNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Function : SetNextIndex
|
||||
// Purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCollection_IndexedDataMapNode::
|
||||
SetNextIndex(const Handle(PCollection_IndexedDataMapNode)& aNode)
|
||||
{
|
||||
myNextIndex = aNode;
|
||||
}
|
||||
|
3
src/PCollection/PCollection_LDSHR.edl
Executable file
3
src/PCollection/PCollection_LDSHR.edl
Executable file
@@ -0,0 +1,3 @@
|
||||
@if ( ( %Station == "ao1" ) && ( %DBMS == "OBJS" ) ) then
|
||||
@string %LDSHR_DBMSOpt += " -taso ";
|
||||
@endif;
|
70
src/PCollection/PCollection_LeavesIterator.gxx
Executable file
70
src/PCollection/PCollection_LeavesIterator.gxx
Executable file
@@ -0,0 +1,70 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_LeavesIterator.gxx
|
||||
// Created: Wed May 29 17:43:32 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_LeavesIterator::PCollection_LeavesIterator
|
||||
(const Handle(PCollection_HDirectedGraph)& G):MyVertexIterator(G->GetVertices())
|
||||
{
|
||||
HasMore = False;
|
||||
while ((MyVertexIterator.More()) && (!HasMore)) {
|
||||
if (MyVertexIterator.Value()->IsLeaf())
|
||||
HasMore = True;
|
||||
else
|
||||
MyVertexIterator.Next();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_LeavesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_LeavesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
HasMore = False;
|
||||
MyVertexIterator.Next();
|
||||
while (MyVertexIterator.More() && !HasMore) {
|
||||
if (MyVertexIterator.Value()->IsLeaf())
|
||||
HasMore = True;
|
||||
else
|
||||
MyVertexIterator.Next();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_LeavesIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return MyVertexIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_LeavesIterator::Clear ()
|
||||
{
|
||||
// Nullify sur les champs
|
||||
HasMore = False;
|
||||
}
|
||||
|
90
src/PCollection/PCollection_MapIterator.gxx
Executable file
90
src/PCollection/PCollection_MapIterator.gxx
Executable file
@@ -0,0 +1,90 @@
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_MapIterator.gxx
|
||||
// Created: Oct, 9 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Create
|
||||
//----------------------------------------------------------------
|
||||
PCollection_MapIterator::PCollection_MapIterator
|
||||
(const Handle(PCollection_HDataMap)& AMap)
|
||||
{
|
||||
if (AMap->IsEmpty()) {
|
||||
Index = 0;
|
||||
Node.Nullify();
|
||||
Buckets.Nullify();
|
||||
HasMore = False;
|
||||
}
|
||||
else {
|
||||
// stop at the first element of the first "no empty" bucket entry
|
||||
HasMore = True;
|
||||
Buckets = AMap->GetArray();
|
||||
NbBuck = AMap->NbBuckets();
|
||||
Boolean Found = False;
|
||||
Index = 1 ;
|
||||
while ( Index <= NbBuck && !Found ) {
|
||||
Node = Buckets->Value(Index);
|
||||
if (Node.IsNull())
|
||||
Index++;
|
||||
else
|
||||
Found = True;
|
||||
}
|
||||
if (!Found) HasMore = False;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// More
|
||||
//----------------------------------------------------------------
|
||||
Standard_Boolean PCollection_MapIterator::More() const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Value
|
||||
//----------------------------------------------------------------
|
||||
Item PCollection_MapIterator::Value() const
|
||||
{
|
||||
if (Node.IsNull()) Standard_NoSuchObject::Raise();
|
||||
return (Node->Value());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// GetKey
|
||||
//----------------------------------------------------------------
|
||||
Key PCollection_MapIterator::GetKey() const
|
||||
{
|
||||
if (Node.IsNull()) Standard_NoSuchObject::Raise();
|
||||
return (Node->GetKey());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Next
|
||||
//----------------------------------------------------------------
|
||||
void PCollection_MapIterator::Next()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
Node = Node->Next();
|
||||
if (Node.IsNull()) {
|
||||
Boolean Found = False;
|
||||
Index++;
|
||||
while ( Index <= NbBuck && !Found ) {
|
||||
Node = Buckets->Value(Index);
|
||||
if (Node.IsNull())
|
||||
Index++;
|
||||
else
|
||||
Found = True;
|
||||
}
|
||||
if (!Found) HasMore = False;
|
||||
}
|
||||
}
|
||||
|
||||
|
98
src/PCollection/PCollection_MapNode.gxx
Executable file
98
src/PCollection/PCollection_MapNode.gxx
Executable file
@@ -0,0 +1,98 @@
|
||||
// Copyright: Matra-Datavision 1993
|
||||
// File: PCollection_MapNode.gxx
|
||||
// Created: Mon Jan 11 10:38:53 1993
|
||||
// Author: Mireille MERCIEN
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------
|
||||
PCollection_MapNode::PCollection_MapNode(const Key& aKey,
|
||||
const Item& anItem,
|
||||
const Handle(PCollection_MapNode)& aNext)
|
||||
{
|
||||
myKey = aKey;
|
||||
myItem = anItem;
|
||||
myNext = aNext;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// GetKey
|
||||
//-----------------------------------------------------------------
|
||||
Key PCollection_MapNode::GetKey() const
|
||||
{
|
||||
return myKey;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Value
|
||||
//-----------------------------------------------------------------
|
||||
Item PCollection_MapNode::Value() const
|
||||
{
|
||||
return myItem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// Next
|
||||
//-----------------------------------------------------------------
|
||||
Handle(PCollection_MapNode) PCollection_MapNode::Next() const
|
||||
{
|
||||
return myNext;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// SetKey
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_MapNode::SetKey(const Key& aKey)
|
||||
{
|
||||
myKey = aKey;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// SetValue
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_MapNode::SetValue(const Item& anItem)
|
||||
{
|
||||
myItem = anItem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// SetNext
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_MapNode::SetNext
|
||||
(const Handle(PCollection_MapNode)& aNext)
|
||||
{
|
||||
myNext = aNext;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// ShallowCopy : ShallowCopy redefinition
|
||||
//-----------------------------------------------------------------
|
||||
Handle(Standard_Persistent) PCollection_MapNode::ShallowCopy() const
|
||||
{
|
||||
Handle(PCollection_MapNode) TheCopy;
|
||||
TheCopy = new PCollection_MapNode(myKey,myItem,myNext);
|
||||
return TheCopy;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// ShallowDump : ShallowDump redefinition
|
||||
//-----------------------------------------------------------------
|
||||
void PCollection_MapNode::ShallowDump(Standard_OStream& S) const
|
||||
{
|
||||
S << "begin class MapNode "<< endl;
|
||||
Handle(PCollection_MapNode) anode;
|
||||
anode = this;
|
||||
::ShallowDump(anode->GetKey(),S);
|
||||
::ShallowDump(anode->Value(),S);
|
||||
if (!myNext.IsNull()) myNext->ShallowDump(S);
|
||||
S << "end of class MapNode." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
73
src/PCollection/PCollection_QueueIterator.gxx
Executable file
73
src/PCollection/PCollection_QueueIterator.gxx
Executable file
@@ -0,0 +1,73 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// --------------------------------
|
||||
// constructor of QueueIterator
|
||||
// --------------------------------
|
||||
|
||||
PCollection_QueueIterator::PCollection_QueueIterator
|
||||
(const Handle(PCollection_HQueue)& S)
|
||||
{
|
||||
TheIterator = S->FFront();
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// More : returns Standard_True if there
|
||||
// are other items
|
||||
// -----------------------------------
|
||||
Standard_Boolean PCollection_QueueIterator::More() const
|
||||
{
|
||||
return ( ! TheIterator->IsEmpty() );
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Next : set the iterator to the next item
|
||||
// -----------------------------------------
|
||||
void PCollection_QueueIterator::Next()
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoMoreObject::Raise();
|
||||
TheIterator = TheIterator->Tail();
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
// Value : returns the current item value
|
||||
// of the iterator
|
||||
// ---------------------------------------
|
||||
Item PCollection_QueueIterator::Value() const
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
return TheIterator->Value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
72
src/PCollection/PCollection_RootsIterator.gxx
Executable file
72
src/PCollection/PCollection_RootsIterator.gxx
Executable file
@@ -0,0 +1,72 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_RootsIterator.gxx
|
||||
// Created: Wed May 29 17:43:32 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_RootsIterator::PCollection_RootsIterator
|
||||
(const Handle(PCollection_HDirectedGraph)& G):MyVertexIterator(G->GetVertices())
|
||||
{
|
||||
HasMore = False;
|
||||
while ((MyVertexIterator.More()) && (!HasMore)) {
|
||||
if (MyVertexIterator.Value()->IsRoot())
|
||||
HasMore = True;
|
||||
else
|
||||
MyVertexIterator.Next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_RootsIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_RootsIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
HasMore = False;
|
||||
MyVertexIterator.Next();
|
||||
while ((MyVertexIterator.More()) && (!HasMore)) {
|
||||
if (MyVertexIterator.Value()->IsRoot())
|
||||
HasMore = True;
|
||||
else
|
||||
MyVertexIterator.Next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_RootsIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return MyVertexIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_RootsIterator::Clear ()
|
||||
{
|
||||
// Nullify sur les champs
|
||||
HasMore = False;
|
||||
}
|
||||
|
88
src/PCollection/PCollection_SeqExplorer.gxx
Executable file
88
src/PCollection/PCollection_SeqExplorer.gxx
Executable file
@@ -0,0 +1,88 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_SeqExplorer.gxx
|
||||
// Created: Sep, 28 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// -----------
|
||||
// constructor :
|
||||
// -----------
|
||||
PCollection_SeqExplorer::PCollection_SeqExplorer
|
||||
(const Handle(PCollection_HSequence)& S )
|
||||
{
|
||||
if (S->Length() != 0) {
|
||||
CurrentItem = S->GetFirst();
|
||||
CurrentIndex = 1;
|
||||
TheSequence = S;
|
||||
}
|
||||
else {
|
||||
CurrentItem.Nullify();
|
||||
CurrentIndex = 0;
|
||||
TheSequence.Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Value :
|
||||
// -----------
|
||||
Item PCollection_SeqExplorer::Value(const Standard_Integer Index)
|
||||
{
|
||||
if (Index <= 0 || Index > TheSequence->Length())
|
||||
Standard_NoSuchObject::Raise();
|
||||
if (Index < CurrentIndex) {
|
||||
CurrentIndex = 1;
|
||||
CurrentItem = TheSequence->GetFirst();
|
||||
}
|
||||
while ( CurrentIndex != Index ) {
|
||||
++CurrentIndex;
|
||||
CurrentItem = CurrentItem->Next();
|
||||
}
|
||||
// Return the value of the item pointed by CurrentItem
|
||||
return CurrentItem->Value();
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Contains :
|
||||
// -----------
|
||||
//Standard_Boolean PCollection_SeqExplorer::Contains(const Item& T)
|
||||
Standard_Boolean PCollection_SeqExplorer::Contains(const Item& )
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_SeqExplorer::Contains : Obsolete method...");
|
||||
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Location :
|
||||
// -----------
|
||||
//Standard_Integer PCollection_SeqExplorer::Location ( const Standard_Integer N ,
|
||||
// const Item& T ,
|
||||
// const Standard_Integer From ,
|
||||
// const Standard_Integer To)
|
||||
Standard_Integer PCollection_SeqExplorer::Location ( const Standard_Integer ,
|
||||
const Item& ,
|
||||
const Standard_Integer ,
|
||||
const Standard_Integer )
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_SeqExplorer::Location : Obsolete method...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Location :
|
||||
// -----------
|
||||
//Standard_Integer PCollection_SeqExplorer::Location(const Standard_Integer N , const Item& T )
|
||||
Standard_Integer PCollection_SeqExplorer::Location(const Standard_Integer , const Item& )
|
||||
{
|
||||
Standard_ProgramError::Raise("PCollection_SeqExplorer::Location : Obsolete method...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
95
src/PCollection/PCollection_SeqNode.gxx
Executable file
95
src/PCollection/PCollection_SeqNode.gxx
Executable file
@@ -0,0 +1,95 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: PCollection_SeqNode.gxx
|
||||
// Created: Sep, 24 1992
|
||||
// Author: Mireille MERCIEN
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// -----------
|
||||
// constructor :
|
||||
// -----------
|
||||
PCollection_SeqNode::PCollection_SeqNode
|
||||
(const Handle(PCollection_SeqNode)& TheLast , const Item& TheItem )
|
||||
{
|
||||
MyItem = TheItem;
|
||||
MyPrevious = TheLast;
|
||||
MyNext.Nullify();
|
||||
}
|
||||
|
||||
PCollection_SeqNode::PCollection_SeqNode
|
||||
(const Item& TheItem , const Handle(PCollection_SeqNode)& TheFirst)
|
||||
{
|
||||
MyItem = TheItem;
|
||||
MyNext = TheFirst;
|
||||
MyPrevious.Nullify();
|
||||
|
||||
}
|
||||
|
||||
PCollection_SeqNode::PCollection_SeqNode
|
||||
(const Handle(PCollection_SeqNode)& ThePrevious ,
|
||||
const Handle(PCollection_SeqNode)& TheNext ,
|
||||
const Item& TheItem)
|
||||
{
|
||||
MyItem = TheItem;
|
||||
MyNext = TheNext;
|
||||
MyPrevious = ThePrevious;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Value
|
||||
// -----------
|
||||
Item PCollection_SeqNode::Value() const
|
||||
{
|
||||
return MyItem;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Next
|
||||
// -----------
|
||||
Handle(PCollection_SeqNode) PCollection_SeqNode::Next() const
|
||||
{
|
||||
return MyNext;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// Previous
|
||||
// -----------
|
||||
Handle(PCollection_SeqNode) PCollection_SeqNode::Previous() const
|
||||
{
|
||||
return MyPrevious;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// SetValue
|
||||
// -----------
|
||||
void PCollection_SeqNode::SetValue(const Item& TheItem)
|
||||
{
|
||||
MyItem = TheItem;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// SetNext
|
||||
// -----------
|
||||
void PCollection_SeqNode::SetNext(const Handle(PCollection_SeqNode)& TheNext)
|
||||
{
|
||||
MyNext = TheNext;
|
||||
}
|
||||
|
||||
// -----------
|
||||
// SetPrevious
|
||||
// -----------
|
||||
void PCollection_SeqNode::
|
||||
SetPrevious(const Handle(PCollection_SeqNode)& ThePrevious)
|
||||
{
|
||||
MyPrevious = ThePrevious;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
39
src/PCollection/PCollection_SetIterator.gxx
Executable file
39
src/PCollection/PCollection_SetIterator.gxx
Executable file
@@ -0,0 +1,39 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// --------------------------------
|
||||
// constructor of SetIterator
|
||||
// --------------------------------
|
||||
PCollection_SetIterator::PCollection_SetIterator
|
||||
(const Handle(PCollection_HSet)& S)
|
||||
{
|
||||
TheIterator = S->Last();
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// More : returns Standard_True if there
|
||||
// are other items
|
||||
// -----------------------------------
|
||||
Standard_Boolean PCollection_SetIterator::More() const
|
||||
{
|
||||
return ! ( TheIterator->IsEmpty() ) ;
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Next : set the iterator to the next item
|
||||
// -----------------------------------------
|
||||
void PCollection_SetIterator::Next()
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoMoreObject::Raise();
|
||||
TheIterator = TheIterator->Tail();
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
// Value : returns the current item value
|
||||
// of the iterator
|
||||
// ---------------------------------------
|
||||
Item PCollection_SetIterator::Value() const
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
return TheIterator->Value();
|
||||
}
|
73
src/PCollection/PCollection_StackIterator.gxx
Executable file
73
src/PCollection/PCollection_StackIterator.gxx
Executable file
@@ -0,0 +1,73 @@
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
// --------------------------------
|
||||
// constructor of StackIterator
|
||||
// --------------------------------
|
||||
|
||||
PCollection_StackIterator::PCollection_StackIterator
|
||||
(const Handle(PCollection_HStack)& S)
|
||||
{
|
||||
TheIterator = S->FTop();
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// More : returns Standard_True if there
|
||||
// are other items
|
||||
// -----------------------------------
|
||||
Standard_Boolean PCollection_StackIterator::More() const
|
||||
{
|
||||
return (! TheIterator->IsEmpty());
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// Next : Set the iterator to the next item
|
||||
// -----------------------------------------
|
||||
void PCollection_StackIterator::Next()
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoMoreObject::Raise();
|
||||
TheIterator = TheIterator->Tail();
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
// Value : returns the current item value
|
||||
// of the iterator
|
||||
// ---------------------------------------
|
||||
Item PCollection_StackIterator::Value() const
|
||||
{
|
||||
if (TheIterator->IsEmpty()) Standard_NoSuchObject::Raise();
|
||||
return TheIterator->Value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
181
src/PCollection/PCollection_Vertex.gxx
Executable file
181
src/PCollection/PCollection_Vertex.gxx
Executable file
@@ -0,0 +1,181 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_Vertex.gxx
|
||||
// Created: Wed May 29 17:04:56 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_Vertex::
|
||||
PCollection_Vertex (const Item& Value,
|
||||
const Handle(PCollection_HDirectedGraph)& InGraph)
|
||||
{
|
||||
MyItem = Value;
|
||||
MyGraph = InGraph;
|
||||
MyFrontEdges = new PCollection_SetOfEdge;
|
||||
MyBackEdges = new PCollection_SetOfEdge;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetItem
|
||||
//---------------------------------------------------------------------------
|
||||
Item PCollection_Vertex::GetItem () const
|
||||
{
|
||||
return MyItem;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SetItem
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Vertex::SetItem (const Item& Value)
|
||||
{
|
||||
MyItem = Value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetGraph
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_HDirectedGraph) PCollection_Vertex::GetGraph () const
|
||||
{
|
||||
return MyGraph;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// AddFrontEdge
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::AddFrontEdge (const Handle(PCollection_Edge)& E)
|
||||
{
|
||||
if (MyFrontEdges->Contains(E)) {
|
||||
return False;
|
||||
}
|
||||
else {
|
||||
MyFrontEdges->Add(E);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// RemoveFrontEdge
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Vertex::RemoveFrontEdge (const Handle(PCollection_Edge)& E)
|
||||
{
|
||||
if (MyFrontEdges->Contains(E)) {
|
||||
MyFrontEdges->Remove(E);
|
||||
}
|
||||
else {
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// NbFrontEdges
|
||||
//---------------------------------------------------------------------------
|
||||
Integer PCollection_Vertex::NbFrontEdges () const
|
||||
{
|
||||
return MyFrontEdges->Extent();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetFrontEdges
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_SetOfEdge) PCollection_Vertex::GetFrontEdges () const
|
||||
{
|
||||
return MyFrontEdges;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// AddBackEdge
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::AddBackEdge (const Handle(PCollection_Edge)& E)
|
||||
{
|
||||
if (MyBackEdges->Contains(E)) {
|
||||
return False;
|
||||
}
|
||||
else {
|
||||
MyBackEdges->Add(E);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// RemoveBackEdge
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_Vertex::RemoveBackEdge (const Handle(PCollection_Edge)& E)
|
||||
{
|
||||
if (MyBackEdges->Contains(E)) {
|
||||
MyBackEdges->Remove(E);
|
||||
}
|
||||
else {
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// NbBackEdges
|
||||
//---------------------------------------------------------------------------
|
||||
Integer PCollection_Vertex::NbBackEdges () const
|
||||
{
|
||||
return MyBackEdges->Extent();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GetBackEdges
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_SetOfEdge) PCollection_Vertex::GetBackEdges () const
|
||||
{
|
||||
return MyBackEdges;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// IsRoot
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::IsRoot () const
|
||||
{
|
||||
return (NbBackEdges() == 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// IsLeaf
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::IsLeaf () const
|
||||
{
|
||||
return (NbFrontEdges() == 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// IsDestination
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::
|
||||
IsDestination (const Handle(PCollection_Vertex)& V) const
|
||||
{
|
||||
PCollection_SetIteratorOfSetOfEdge It(MyBackEdges);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Edge) E = It.Value();
|
||||
if (E->Source() == V) return True;
|
||||
It.Next();
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// IsSource
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_Vertex::
|
||||
IsSource (const Handle(PCollection_Vertex)& V) const
|
||||
{
|
||||
PCollection_SetIteratorOfSetOfEdge It(MyFrontEdges);
|
||||
while (It.More()) {
|
||||
Handle(PCollection_Edge) E = It.Value();
|
||||
if ( E->Destination() == V) return True;
|
||||
It.Next();
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
67
src/PCollection/PCollection_VerticesIterator.gxx
Executable file
67
src/PCollection/PCollection_VerticesIterator.gxx
Executable file
@@ -0,0 +1,67 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: PCollection_VerticesIterator.gxx
|
||||
// Created: Wed May 29 17:43:20 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
// Revised by: Mireille MERCIEN
|
||||
// Sep,7 1992
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//---------------------------------------------------------------------------
|
||||
PCollection_VerticesIterator::PCollection_VerticesIterator
|
||||
(const Handle(PCollection_HDirectedGraph)& G):MyVertexIterator(G->GetVertices())
|
||||
{
|
||||
HasMore = MyVertexIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// More
|
||||
//---------------------------------------------------------------------------
|
||||
Boolean PCollection_VerticesIterator::More () const
|
||||
{
|
||||
return HasMore;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Next
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_VerticesIterator::Next ()
|
||||
{
|
||||
if (!HasMore) Standard_NoMoreObject::Raise();
|
||||
MyVertexIterator.Next();
|
||||
HasMore = MyVertexIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Value
|
||||
//---------------------------------------------------------------------------
|
||||
Handle(PCollection_Vertex) PCollection_VerticesIterator::Value () const
|
||||
{
|
||||
if (!HasMore) Standard_NoSuchObject::Raise();
|
||||
return MyVertexIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Clear
|
||||
//---------------------------------------------------------------------------
|
||||
void PCollection_VerticesIterator::Clear ()
|
||||
{
|
||||
HasMore = False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
17
src/PCollection/PCollection_WOKSteps.edl
Executable file
17
src/PCollection/PCollection_WOKSteps.edl
Executable file
@@ -0,0 +1,17 @@
|
||||
|
||||
--
|
||||
-- File: PCollection_WOKSteps.edl
|
||||
-- Author: Stephane Callegari
|
||||
-- History: 30-04-98 : CAL : Creation
|
||||
-- Copyright: Matra Datavision 1998
|
||||
--
|
||||
|
||||
@ifnotdefined ( %PCollection_WOKSteps_EDL) then
|
||||
|
||||
@set %PCollection_WOKSteps_EDL = "";
|
||||
|
||||
@string %WOKSteps_XcppGroup = " xcpp.fill xcpp.src xcpp.header xcpp.template obj.cgen obj.inc ";
|
||||
--@set %WOKSteps_xcpp_repl = "*PCollection_Replace(xcpp.header)";
|
||||
|
||||
@endif;
|
||||
|
Reference in New Issue
Block a user