TAPs 0.7.7.3
TAPsDirectedGraph.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsDirectedGraph.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (09/12/2005)
00009 UPDATE          (09/09/2010)
00010 ******************************************************************************/
00011 #ifndef TAPs_DIRECTED_GRAPH_HPP
00012 #define TAPs_DIRECTED_GRAPH_HPP
00013 
00014 #include "TAPsGraphNode.hpp"
00015 #include <vector>
00016 
00017 BEGIN_NAMESPACE_TAPs__DS
00018 //=============================================================================
00019 template <typename T>
00020 class DirectedGraph {
00021 //=============================================================================
00022 // Data Members
00023 protected:
00024     std::vector< GraphNode<T> > m_vNodes;   // a vector of vertices
00025 //=============================================================================
00026 // Member Functions
00027 public:
00028     typedef T value_type;
00029     typedef typename GraphNode<T> node;
00030     typedef typename std::vector<node>::iterator iterator;
00031     typedef typename std::vector<node>::const_iterator const_iterator;
00032     //-------------------------------------------------------------------------
00034     friend std::ostream & operator<< ( std::ostream &output, DirectedGraph<T> const &obj )
00035     {
00036         output  << "DirectedGraph<" << typeid(T).name()
00037             << "> with " << static_cast<int>(obj.m_vNodes.size()) << " nodes:"
00038             << "\n";
00039         //output << "Connections:\n";
00040         //for ( unsigned int i = 0; i < obj.m_vNodes.size(); ++i ) {
00041         //  output << "  Node#" << i << " with ID " << obj.m_vNodes[i].GetID() << " connects to nodes with IDs ";
00042         //  for ( unsigned int l = 0; l < obj.m_vNodes[i].GetNumOfLinks(); ++l ) {
00043         //      output << " " << obj.m_vNodes[i].GetNodeIdOfLinkNumber( l );
00044         //  }
00045         //  output << "\n";
00046         //}
00047         output << "List of Nodes:\n";
00048         for ( int i = 0; i < static_cast<int>(obj.m_vNodes.size()); ++i ) {
00049             output << "  Node#" << i << ": " << obj.m_vNodes[i];
00050         }
00051         return output;
00052     }
00053     //-------------------------------------------------------------------------
00054     // Constructors and Destructor
00055     DirectedGraph ();
00056     virtual ~DirectedGraph ();
00057     //-------------------------------------------------------------------------
00058     // Graph Operations
00059     void NewGraphNode ( T & t );            // create a graph node
00060 
00061     // using int instead of addresses of nodes because std::vector will move 
00062     // nodes to new addresses when its size gets expanded.
00063 
00065     inline void SetDirection ( unsigned int n1, unsigned int n2 );      // direct node 1 to node 2
00066 
00068     inline void SetBidirection ( unsigned int n1, unsigned int n2 );    // bidirect node 1 and node 2
00069 
00070     //iterator begin () const;
00071     //iterator end () const;
00072     //-------------------------------------------------------------------------
00073     
00075     inline unsigned int GetNumOfNodes () const  { return m_vNodes.size(); }
00076 
00078     inline node const & RefNodeNumber ( unsigned int number ) const;
00080     inline node & RefNodeNumber ( unsigned int number );
00081 
00083     inline value_type const &   RefDataInNodeNumber ( unsigned int number ) const;
00085     inline value_type &         RefDataInNodeNumber ( unsigned int number );
00086 
00087     //-------------------------------------------------------------------------
00088 #if defined(__gl_h_) || defined(__GL_H__)
00089 public:
00091     virtual void Draw () const;
00092 protected:
00093     std::vector< Vector3<float> >   m_ListOfNodePos;    
00094 #endif
00095     //-------------------------------------------------------------------------
00096 }; // END CLASS DirectedGraph
00097 //=============================================================================
00098 END_NAMESPACE_TAPs__DS
00099 //-----------------------------------------------------------------------------
00100 // Include definition if TAPs_USE_EXPORT is not defined
00101 //#if !defined( TAPs_USE_EXPORT )
00102     #include "TAPsDirectedGraph.cpp"
00103 //#endif
00104 //-----------------------------------------------------------------------------
00105 #endif
00106 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00107 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines