#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Container/Branch/BGraph.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_BGRAPH_HEADER #define RAVL_BGRAPH_HEADER 1 /////////////////////////////////////////////////////////////// //! file="Ravl/Core/Container/Branch/BGraph.hh" //! lib=RavlCore //! userlevel=Normal //! author="Charles Galambos" //! date="19/2/1997" //! docentry="Ravl.Core.Branch" //! rcsid="$Id: BGraph.hh,v 1.1 2002/04/05 12:59:07 craftit Exp $" #include "Ravl/BGraphBase.hh" namespace RavlN { template class BGraphEdgeC; template class BGraphNodeC; template class BGraphNodeHC; template class BGraphLinearIterC; //: Branching graph. template class BGraphC : public BGraphTypesC { public: inline BGraphC() : Base(*new BGraphBaseC()) {} //: Default constructor. NodeHandleT InsNode(const NT &Data); // Add a node BGraphEdgeC &InsEdge(NodeHandleT From,NodeHandleT To,const ET &Data); // Add an edge inline BGraphEdgeC &InsEdge(BGraphNodeHC From,BGraphNodeHC To,const ET &Data) { return InsEdge(From.ID(),To.ID(),Data); } // Add an edge inline BGraphNodeC &NodeObj(NodeHandleT H) { return *(static_cast *> (&Base->Node(H))); } // Convert a NodeHandle to a node. inline BGraphNodeHC NodeObjH(NodeHandleT H); // Convert a NodeHandle to a node. inline NT & NodeData(NodeHandleT H); // Access node data. inline IntT NoNodes() const { return Base->NoNodes(); } // Get number of nodes. inline BGraphBaseC &BaseGraph() { return *Base; } // Access base graph. inline bool IsValid(NodeHandleT H) const { return Base->IsValid(H); } // Check a node handle is valid. (For debuging.) inline bool IsValid() const { return Base.IsValid(); } // Check its valid handle. inline void SetConst(void) { if(Base.IsValid()) Base->SetConst(); } //: Lock-out changes. protected: inline BGraphC(BGraphBaseC &BG); // Constructor. inline void DupNode(NodeHandleT ID); // Duplicate node. private: SmartPtrC Base; friend class BGraphLinearIterC; }; } #include "Ravl/BGraphNode.hh" #include "Ravl/BGraphEdge.hh" namespace RavlN { ////////////////////////////////////////////////// template inline BGraphNodeHC BGraphC::NodeObjH(BGraphTypesC::NodeHandleT H) { return BGraphNodeHC(NodeObj(H)); } /////////////////////////////////////////////////////// template inline NT & BGraphC::NodeData(BGraphTypesC::NodeHandleT H) { return NodeObj(H).Data(); } /////////////////////////////////////////////////////// template BGraphTypesC::NodeHandleT BGraphC::InsNode(const NT &Data) { Base = *new BGraphBaseC(*Base,1); BGraphNodeC *tmp = new BGraphNodeC(Data); Base->Insert(*tmp); //printf("Insert node %d \n",Tmp->ID().V()); return tmp->ID(); } /////////////////////////////////////////////////////// template inline void BGraphC::DupNode(BGraphTypesC::NodeHandleT ID) { RavlAssert(IsValid(ID)); Base->Dup(*new BGraphNodeC(NodeObj(ID))); } /////////////////////////////////////////////////////// template BGraphEdgeC &BGraphC::InsEdge(BGraphTypesC::NodeHandleT From, BGraphTypesC::NodeHandleT To, const ET &data) { Base = *new BGraphBaseC(*Base); DupNode(From); DupNode(To); BGraphEdgeC *Tmp = new BGraphEdgeC(From, To, data); Base->Insert(*Tmp); return *Tmp; } } #endif