00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ADH_Graph_h
00011 #define ADH_Graph_h "Versión 1"
00012
00013 #include <map>
00014 #include <set>
00015 #include <list>
00016 #include <string>
00017 #include <iostream>
00018
00019
00020 namespace ADH {}
00021
00022 namespace ADH {
00023
00024
00025
00026 class Graph {
00027 public:
00028 typedef std::string key_type;
00029 typedef std::map< std::string, int > mapped_type;
00030 private:
00031
00032 typedef std::map< key_type, mapped_type > Rep;
00033 public:
00034 typedef Rep::value_type value_type;
00035 typedef value_type& reference;
00036 typedef const value_type& const_reference;
00037 private:
00038
00039
00040
00041
00042
00043
00044
00045
00046 class Rep_const_iterator {
00047 friend class Graph;
00048 public:
00049 Rep_const_iterator() : m_it() { }
00050
00051
00052 Rep_const_iterator( const Rep_const_iterator& o ) : m_it(o.m_it) { }
00053 Rep_const_iterator& operator=( const Rep_const_iterator& o ) {
00054 m_it = o.m_it;
00055 return *this;
00056 }
00057
00058 friend bool operator == ( const Rep_const_iterator& p , const Rep_const_iterator& q ) {
00059 return p.m_it == q.m_it;
00060 }
00061 friend bool operator != ( const Rep_const_iterator& p , const Rep_const_iterator& q ) {
00062 return p.m_it != q.m_it;
00063 }
00064
00065 Rep_const_iterator operator++(int)
00066 { Rep_const_iterator q = (*this); ++m_it; return q; }
00067 Rep_const_iterator operator++() { ++m_it; return *this; }
00068 Rep_const_iterator operator--(int)
00069 { Rep_const_iterator q = (*this); --m_it; return q; }
00070 Rep_const_iterator operator--() { --m_it; return *this; }
00071
00072 const value_type& operator*() { return *m_it ; }
00073 const value_type* operator->() { return &(*m_it); }
00074 private:
00075 Rep::const_iterator m_it;
00076 };
00077 public:
00078
00079
00080
00081
00082
00083
00084
00085 class const_iterator {
00086 friend class Graph;
00087 public:
00088 const_iterator() : m_it() { }
00089
00090
00091 const_iterator( const const_iterator& o ) : m_it(o.m_it) { }
00092 const_iterator& operator=( const const_iterator& o ) {
00093 m_it = o.m_it;
00094 return *this;
00095 }
00096
00097 friend bool operator == ( const const_iterator& p , const const_iterator& q ) {
00098 return p.m_it == q.m_it;
00099 }
00100 friend bool operator != ( const const_iterator& p , const const_iterator& q ) {
00101 return p.m_it != q.m_it;
00102 }
00103
00104 const_iterator operator++(int)
00105 { const_iterator q = (*this); ++m_it; return q; }
00106 const_iterator operator++() { ++m_it; return *this; }
00107 const_iterator operator--(int)
00108 { const_iterator q = (*this); --m_it; return q; }
00109 const_iterator operator--() { --m_it; return *this; }
00110
00111 const key_type& operator*() { return m_it->first; }
00112 const key_type* operator->() { return &(m_it->first); }
00113 private:
00114 Rep::const_iterator m_it;
00115 };
00116 Graph() : m_DICC() { }
00117 Graph(const Graph& G) : m_DICC() { *this = G; }
00118 ~Graph() { }
00119
00120 bool empty() const { return m_DICC.empty(); }
00121
00122 Graph& operator=(const Graph& G) {
00123 m_DICC = G.m_DICC; return *this; }
00124 void swap(Graph& M) { m_DICC.swap(M.m_DICC); }
00125 void clear() { m_DICC.clear(); }
00126 private:
00127
00128 Rep_const_iterator begin_Rep() const { Rep_const_iterator p; p.m_it = m_DICC.begin(); return p; }
00129
00130 Rep_const_iterator end_Rep () const { Rep_const_iterator p; p.m_it = m_DICC.end(); return p; }
00131 public:
00132
00133 const_iterator begin() const { const_iterator p; p.m_it = m_DICC.begin(); return p; }
00134
00135 const_iterator end () const { const_iterator p; p.m_it = m_DICC.end(); return p; }
00136
00137 friend std::ostream& operator<< (std::ostream &COUT, const Graph& G);
00138 friend void dump( std::ostream &COUT, const Graph& G );
00139
00140 friend bool check_ok( const Graph & DDD );
00141 friend class test_Graph;
00142
00143 public:
00144 bool isVertex( const std::string & vtx ) const;
00145 bool isArc( const std::string & src , const std::string & dst , int & val ) const;
00146 void set( const std::string & vtx );
00147 void set( const std::string & src , const std::string & dst , int val );
00148 void vertexList( std::list< std::string> & L ) const;
00149 void vertexList( std::string vtx , std::list< std::string> & L ) const;
00150 private:
00151 Rep m_DICC;
00152 };
00153
00154 }
00155
00156 #endif // ADH_Graph_h
00157
00158