![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsGraphNode.hpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (09/12/2005) 00009 UPDATE (08/15/2010) 00010 ******************************************************************************/ 00011 #ifndef TAPs_GRAPH_NODE_HPP 00012 #define TAPs_GRAPH_NODE_HPP 00013 00014 #include "../Core/TAPsLib.hpp" 00015 #include <set> 00016 00017 BEGIN_NAMESPACE_TAPs__DS 00018 //============================================================================= 00019 00020 // Class forward 00021 //template <typename T> class DirectedGraph; 00022 00023 template <typename T> 00024 class GraphNode { 00025 //============================================================================= 00026 00027 //friend class DirectedGraph<T>; 00028 00029 public: 00034 class Edge { 00035 public: 00037 Edge ( int destNodeID, float weight = 1.0f ) : DestNodeID( destNodeID ), Weight( weight ) {} 00038 00039 int DestNodeID; 00040 float Weight; 00041 00043 //int CompareWeight ( Edge const & edge ) 00044 //{ return Weight - edge.Weight; } 00045 00047 std::string StrInfo () const 00048 { 00049 std::stringstream ss; 00050 ss << "(NodeID: " << DestNodeID << ", weight: " << Weight << ")"; 00051 return ss.str(); 00052 } 00053 }; 00054 00055 // Data Members 00056 protected: 00057 int m_iID; 00058 bool m_bMark; 00059 T * m_ptValue; 00060 //---------------------------------------------------------------- 00061 // Pointers to Neighbors 00062 // --------------------- 00063 // using int instead of addresses of nodes because std::vector will move 00064 // nodes to new addresses when its size gets expanded. 00065 typedef std::vector< Edge > EdgeList; 00066 EdgeList m_vEdges_IN; 00067 EdgeList m_vEdges_OUT; 00068 //---------------------------------------------------------------- 00069 //============================================================================= 00070 // Member Functions 00071 public: 00072 00073 //------------------------------------------------------------------------- 00075 friend std::ostream & operator<< ( std::ostream &output, GraphNode<T> const &node ) 00076 { 00077 output << node.StrInfo(); 00078 return output; 00079 } 00080 //------------------------------------------------------------------------- 00082 GraphNode ( T & value = T(), int id = -1 ); 00084 virtual ~GraphNode (); 00085 //------------------------------------------------------------------------- 00087 virtual std::string StrInfo () const; 00088 //------------------------------------------------------------------------- 00089 // Get/Set Fn(s) 00090 00092 inline int GetID () const { return m_iID; } 00093 00095 inline bool GetStatusMark () const { return m_bMark; } 00097 inline void SetStatusMark ( bool b ) { m_bMark = b; } 00098 00100 inline void Mark () { m_bMark = true; } 00102 inline void Unmark () { m_bMark = false; } 00103 00105 inline unsigned int GetNumOfInPaths () const { return m_vEdges_IN.size(); } 00107 inline unsigned int GetNumOfOutPaths () const { return m_vEdges_OUT.size(); } 00109 inline int GetNodeIdOfInPathsNumber ( unsigned int i ) const; 00111 inline int GetNodeIdOfOutPathsNumber ( unsigned int i ) const; 00112 00114 inline EdgeList const & RefToListOfInPaths () const { return m_vEdges_IN; } 00116 inline EdgeList & RefToListOfInPaths () { return m_vEdges_IN; } 00118 inline EdgeList const & RefToListOfOutPaths () const { return m_vEdges_OUT; } 00120 inline EdgeList & RefToListOfOutPaths () { return m_vEdges_OUT; } 00121 00123 inline T const & RefValue () const { return *m_ptValue; } 00125 inline T & RefValue () { return *m_ptValue; } 00126 00127 //------------------------------------------------------------------------- 00128 #if defined(__gl_h_) || defined(__GL_H__) 00129 public: 00131 virtual void Draw () const; 00132 #endif 00133 //------------------------------------------------------------------------- 00134 }; // END CLASS GraphNode 00135 //============================================================================= 00136 END_NAMESPACE_TAPs__DS 00137 //----------------------------------------------------------------------------- 00138 // Include definition if TAPs_USE_EXPORT is not defined 00139 //#if !defined( TAPs_USE_EXPORT ) 00140 #include "TAPsGraphNode.cpp" 00141 //#endif 00142 //----------------------------------------------------------------------------- 00143 #endif 00144 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00145 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8