00001 // Copyright (C) 2005 Alexander Ushakov 00002 // Contents: Definition of class GraphRep 00003 // 00004 // Principal Authors: Alexander Ushakov 00005 // 00006 // Revision History: 00007 // 00008 00009 #ifndef _GraphRep_H_ 00010 #define _GraphRep_H_ 00011 00012 #include "RefCounter.h" 00013 00014 #include "set" 00015 #include "map" 00016 using namespace std; 00017 00018 00019 00020 00021 //---------------------------------------------------------------------------// 00022 //-------------------------------- FSAEdge ----------------------------------// 00023 //---------------------------------------------------------------------------// 00024 00025 00026 struct GraphEdge 00027 { 00028 00029 GraphEdge( ) : target(-1) { } 00030 // dummy constructor, not to be used, required for STL::map 00031 00032 GraphEdge( int t ) : target(t) { } 00033 00034 bool operator < ( const GraphEdge& e ) const { return target< e.target; } 00035 bool operator ==( const GraphEdge& e ) const { return target==e.target; } 00036 00037 int target; 00038 }; 00039 00040 00041 //---------------------------------------------------------------------------// 00042 //------------------------------- FSAState ----------------------------------// 00043 //---------------------------------------------------------------------------// 00044 00045 00046 struct GraphState 00047 { 00048 typedef GraphEdge edge_type; 00049 00050 GraphState( int s ) : theState(s) { } 00051 GraphState( ) : theState(0) { } 00052 // doomy constructor for class map 00053 00054 bool operator== ( const GraphState& s ) const { 00055 return theState==s.theState; 00056 } 00057 bool operator< ( const GraphState& s ) const { 00058 return theState<s.theState; 00059 } 00060 00061 set< edge_type > in; 00062 set< edge_type > out; 00063 int theState; 00064 }; 00065 00066 00067 //---------------------------------------------------------------------------// 00068 //-------------------------------- GraphRep ---------------------------------// 00069 //---------------------------------------------------------------------------// 00070 00071 00072 class GraphRep : public RefCounter 00073 { 00074 00075 public: 00076 typedef GraphEdge edge_type; 00077 typedef GraphState state_type; 00078 00079 friend class Graph; 00080 00081 00083 // // 00084 // Constructors // 00085 // // 00087 private: 00088 00089 GraphRep( ) : maxState( 0 ) { } 00090 00092 // // 00093 // Operators // 00094 // // 00096 private: 00097 00098 00099 00101 // // 00102 // Accessors // 00103 // // 00105 00106 public: 00107 GraphRep* clone( ) const { return new GraphRep( *this ); } 00108 00109 private: 00110 00111 int newState( ); 00112 void newEdge( int v1 , int v2 ); 00113 void clear( ); 00114 00115 const map< int, state_type >& getStates( ) const { return theStates; } 00116 00118 // // 00119 // Internal functions // 00120 // // 00122 private: 00123 00125 // // 00126 // Data members // 00127 // // 00129 private: 00130 00131 map< int, state_type > theStates; 00132 // the set of vertices in the graph 00133 00134 int maxState; 00135 // the maximal unused number of a vertex (used in addNewVertex) 00136 }; 00137 00138 00139 00140 #endif