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 public:
00038
00039
00040
00041
00042
00043
00044
00045 class const_iterator {
00046 friend class Graph;
00047 public:
00048 const_iterator() : m_it() { }
00049
00050
00051 const_iterator( const const_iterator& o ) : m_it(o.m_it) { }
00052 const_iterator& operator=( const const_iterator& o ) {
00053 m_it = o.m_it;
00054 return *this;
00055 }
00056
00057 friend bool operator == ( const const_iterator& p , const const_iterator& q ) {
00058 return p.m_it == q.m_it;
00059 }
00060 friend bool operator != ( const const_iterator& p , const const_iterator& q ) {
00061 return p.m_it != q.m_it;
00062 }
00063
00064 const_iterator operator++(int)
00065 { const_iterator q = (*this); ++m_it; return q; }
00066 const_iterator operator++() { ++m_it; return *this; }
00067 const_iterator operator--(int)
00068 { const_iterator q = (*this); --m_it; return q; }
00069 const_iterator operator--() { --m_it; return *this; }
00070
00071 const value_type& operator*() { return *m_it ; }
00072 const value_type* operator->() { return &(*m_it); }
00073 private:
00074 Rep::const_iterator m_it;
00075 };
00076
00077 Graph() : m_DICC() { }
00078 Graph(const Graph& G) : m_DICC() { *this = G; }
00079 ~Graph() { }
00080
00081 bool empty() const { return m_DICC.empty(); }
00082
00083 Graph& operator=(const Graph& G) {
00084 m_DICC = G.m_DICC; return *this; }
00085 void swap(Graph& M) { m_DICC.swap(M.m_DICC); }
00086
00087
00088 const_iterator begin() const { const_iterator p; p.m_it = m_DICC.begin(); return p; }
00089
00090 const_iterator end () const { const_iterator p; p.m_it = m_DICC.end(); return p; }
00091
00092 friend std::ostream& operator<< (std::ostream &COUT, const Graph& G);
00093 friend void dump( std::ostream &COUT, const Graph& G );
00094
00095 friend bool check_ok( const Graph & DDD );
00096 friend class test_Graph;
00097
00098 public:
00099 bool isVertex( const std::string & vtx ) const;
00100 bool isArc( const std::string & src , const std::string & dst , int & val ) const;
00101 void set( const std::string & vtx );
00102 void set( const std::string & src , const std::string & dst , int val );
00103 bool connected( const std::string & src , const std::string & dst , std::list< std::string > & C );
00104 private:
00105 Rep m_DICC;
00106 };
00107
00108 }
00109
00110 #endif // ADH_Graph_h
00111
00112