src/work/marci/leda/leda_graph_wrapper.h
changeset 737 2d867176d10e
parent 646 bd7a69231cf8
child 921 818510fa3d99
equal deleted inserted replaced
7:5abb0cc4b545 8:0cfe5d89ad08
    31   protected:
    31   protected:
    32     Graph* l_graph;
    32     Graph* l_graph;
    33     LedaGraphWrapper() : l_graph(0) { }
    33     LedaGraphWrapper() : l_graph(0) { }
    34     void setGraph(Graph& _l_graph) { l_graph=&_l_graph; }
    34     void setGraph(Graph& _l_graph) { l_graph=&_l_graph; }
    35   public:
    35   public:
    36    
    36 
    37         //LedaGraphWrapper() { }
    37     /// Constructor for wrapping LEDA graphs.
    38     LedaGraphWrapper(Graph& _l_graph) : l_graph(&_l_graph) { }
    38     LedaGraphWrapper(Graph& _l_graph) : l_graph(&_l_graph) { }
    39     LedaGraphWrapper(const LedaGraphWrapper &G) : l_graph(G.l_graph) { }
    39     /// Copy constructor
       
    40     LedaGraphWrapper(const LedaGraphWrapper &g) : l_graph(g.l_graph) { }
    40 
    41 
    41     template <typename T> class NodeMap;
    42     template <typename T> class NodeMap;
    42     template <typename T> class EdgeMap;
    43     template <typename T> class EdgeMap;
    43     template <typename T> class NodeMapWrapper;
    44     template <typename T> class NodeMapWrapper;
    44     template <typename T> class EdgeMapWrapper;
    45     template <typename T> class EdgeMapWrapper;
    48     class Edge;
    49     class Edge;
    49     class EdgeIt;
    50     class EdgeIt;
    50     class OutEdgeIt;
    51     class OutEdgeIt;
    51     class InEdgeIt;
    52     class InEdgeIt;
    52 
    53 
    53     /// The base type of the node iterators.
    54     /// Trivial node-iterator
    54     class Node {
    55     class Node {
    55       friend class LedaGraphWrapper<Graph>;
    56       friend class LedaGraphWrapper<Graph>;
    56       //friend class Edge;
    57       //friend class Edge;
    57       friend class EdgeIt;
    58       friend class EdgeIt;
    58       friend class InEdgeIt;
    59       friend class InEdgeIt;
    63     public: //FIXME
    64     public: //FIXME
    64       Node(leda_node _l_n) : l_n(_l_n) { } 
    65       Node(leda_node _l_n) : l_n(_l_n) { } 
    65     public:
    66     public:
    66       /// @warning The default constructor sets the iterator
    67       /// @warning The default constructor sets the iterator
    67       /// to an undefined value.
    68       /// to an undefined value.
    68       Node() {}   //FIXME
    69       Node() { }   //FIXME
    69       /// Initialize the iterator to be invalid
    70       /// Initialize the iterator to be invalid
    70       Node(Invalid) : l_n(0) { }
    71       Node(Invalid) : l_n(0) { }
    71       //Node(const Node &) {} 
    72       //Node(const Node &) {} 
    72       bool operator==(Node n) const { return l_n==n.l_n; } //FIXME
    73       bool operator==(Node n) const { return l_n==n.l_n; } //FIXME
    73       bool operator!=(Node n) const { return l_n!=n.l_n; } //FIXME
    74       bool operator!=(Node n) const { return l_n!=n.l_n; } //FIXME
    77     /// This iterator goes through each node.
    78     /// This iterator goes through each node.
    78     class NodeIt : public Node {
    79     class NodeIt : public Node {
    79     public:
    80     public:
    80       /// @warning The default constructor sets the iterator
    81       /// @warning The default constructor sets the iterator
    81       /// to an undefined value.
    82       /// to an undefined value.
    82       NodeIt() {} //FIXME
    83       NodeIt() { } //FIXME
    83       /// Initialize the iterator to be invalid
    84       /// Initialize the iterator to be invalid
    84       NodeIt(Invalid i) : Node(i) {}
    85       NodeIt(Invalid i) : Node(i) { }
    85       /// Sets the iterator to the first node of \c G.
    86       /// Sets the iterator to the first node of \c G.
    86       NodeIt(const LedaGraphWrapper &G) : Node(G.l_graph->first_node()) { }
    87       NodeIt(const LedaGraphWrapper &G) : Node(G.l_graph->first_node()) { }
    87       //NodeIt(const NodeIt &) {} //FIXME
    88       //NodeIt(const NodeIt &) {} //FIXME
    88     };
    89     };
    89     
    90     
    90     /// The base type of the edge iterators.
    91     /// Trivial edge-iterator.
    91     class Edge {
    92     class Edge {
    92       friend class LedaGraphWrapper;
    93       friend class LedaGraphWrapper;
    93     protected:
    94     protected:
    94       template <typename T> friend class EdgeMap;
    95       template <typename T> friend class EdgeMap;
    95       leda_edge l_e;
    96       leda_edge l_e;
    96     public: //FIXME
    97     public: //FIXME
    97       Edge(leda_edge _l_e) : l_e(_l_e) { } 
    98       Edge(leda_edge _l_e) : l_e(_l_e) { } 
    98     public:
    99     public:
    99       /// @warning The default constructor sets the iterator
   100       /// @warning The default constructor sets the iterator
   100       /// to an undefined value.
   101       /// to an undefined value.
   101       Edge() {}   //FIXME
   102       Edge() { }   //FIXME
   102       /// Initialize the iterator to be invalid
   103       /// Initialize the iterator to be invalid
   103       Edge(Invalid) : l_e(0) {}
   104       Edge(Invalid) : l_e(0) { }
   104       //Edge(const Edge &) {} 
   105       //Edge(const Edge &) {} 
   105       bool operator==(Edge e) const { return l_e==e.l_e; } //FIXME
   106       bool operator==(Edge e) const { return l_e==e.l_e; } //FIXME
   106       bool operator!=(Edge e) const { return l_e!=e.l_e; } //FIXME 
   107       bool operator!=(Edge e) const { return l_e!=e.l_e; } //FIXME 
   107       operator leda_edge () { return l_e; }
   108       operator leda_edge () { return l_e; }
   108     };
   109     };
   109     
   110     
   110     /// This iterator goes trought the outgoing edges of a certain graph.
   111     /// This iterator goes trought the outgoing edges of a certain node.
   111     
       
   112     class OutEdgeIt : public Edge {
   112     class OutEdgeIt : public Edge {
   113     public:
   113     public:
   114       /// @warning The default constructor sets the iterator
   114       /// @warning The default constructor sets the iterator
   115       /// to an undefined value.
   115       /// to an undefined value.
   116       OutEdgeIt() {}
   116       OutEdgeIt() { }
   117       /// Initialize the iterator to be invalid
   117       /// Initialize the iterator to be invalid
   118       OutEdgeIt(Invalid i) : Edge(i) {}
   118       OutEdgeIt(Invalid i) : Edge(i) { }
   119       /// This constructor sets the iterator to first outgoing edge.
   119       /// This constructor sets the iterator to first outgoing edge.
   120     
   120     
   121       /// This constructor set the iterator to the first outgoing edge of
   121       /// This constructor set the iterator to the first outgoing edge of
   122       /// node
   122       /// node
   123       ///@param n the node
   123       ///@param n the node
   124       ///@param G the graph
   124       ///@param G the graph
   125       OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_adj_edge(n.l_n)) { }
   125       OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_adj_edge(n.l_n)) { }
   126     };
   126     };
   127 
   127 
       
   128     /// This iterator goes trought the incoming edges of a certain node.
   128     class InEdgeIt : public Edge {
   129     class InEdgeIt : public Edge {
   129     public:
   130     public:
   130       /// @warning The default constructor sets the iterator
   131       /// @warning The default constructor sets the iterator
   131       /// to an undefined value.
   132       /// to an undefined value.
   132       InEdgeIt() {}
   133       InEdgeIt() { }
   133       /// Initialize the iterator to be invalid
   134       /// Initialize the iterator to be invalid
   134       InEdgeIt(Invalid i) : Edge(i) {}
   135       InEdgeIt(Invalid i) : Edge(i) { }
   135       InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_in_edge(n.l_n)) { }
   136       InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_in_edge(n.l_n)) { }
   136     };
   137     };
   137 
   138 
   138     //  class SymEdgeIt : public Edge {};
   139     //  class SymEdgeIt : public Edge {};
       
   140     
       
   141     /// This iterator goes trought the edges of the graph.
   139     class EdgeIt : public Edge {
   142     class EdgeIt : public Edge {
   140     public:
   143     public:
   141       /// @warning The default constructor sets the iterator
   144       /// @warning The default constructor sets the iterator
   142       /// to an undefined value.
   145       /// to an undefined value.
   143       EdgeIt() {}
   146       EdgeIt() { }
   144       /// Initialize the iterator to be invalid
   147       /// Initialize the iterator to be invalid
   145       EdgeIt(Invalid i) : Edge(i) {}
   148       EdgeIt(Invalid i) : Edge(i) { }
   146       EdgeIt(const LedaGraphWrapper & G) : Edge(G.l_graph->first_edge()) { }
   149       EdgeIt(const LedaGraphWrapper & G) : Edge(G.l_graph->first_edge()) { }
   147     };
   150     };
   148 
   151 
   149     /// First node of the graph.
   152     /// First node of the graph.
   150 
   153     ///
   151     /// \post \c i and the return value will be the first node.
   154     /// \post \c i and the return value will be the first node.
   152     ///
   155     ///
   153     NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; }
   156     NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; }
   154 
   157 
   155     /// The first outgoing edge.
   158     /// The first outgoing edge.
   161     OutEdgeIt &first(OutEdgeIt &i, Node n) const { 
   164     OutEdgeIt &first(OutEdgeIt &i, Node n) const { 
   162       i=OutEdgeIt(*this, n); 
   165       i=OutEdgeIt(*this, n); 
   163       return i;
   166       return i;
   164     }
   167     }
   165     //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
   168     //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
   166     /// The first edge of the Graph.
   169     /// The first edge of the graph.
   167     EdgeIt &first(EdgeIt &i) const {      
   170     EdgeIt &first(EdgeIt &i) const {      
   168       i=EdgeIt(*this); 
   171       i=EdgeIt(*this); 
   169       return i; }
   172       return i; }
   170 
   173 
   171 //     Node getNext(Node) const {}
   174 //     Node getNext(Node) const {}
   251     void clear() const { l_graph->clear(); }
   254     void clear() const { l_graph->clear(); }
   252 
   255 
   253     int nodeNum() const { return l_graph->number_of_nodes(); }
   256     int nodeNum() const { return l_graph->number_of_nodes(); }
   254     int edgeNum() const { return l_graph->number_of_edges(); }
   257     int edgeNum() const { return l_graph->number_of_edges(); }
   255 
   258 
   256     ///Read/write map from the nodes to type \c T.
   259     /// Read/write map from the nodes to type \c T.
   257     template<typename T> class NodeMap
   260     template<typename T> class NodeMap
   258     {
   261     {
   259       leda_node_map<T> leda_stuff;
   262       leda_node_map<T> leda_stuff;
   260     public:
   263     public:
   261       typedef T ValueType;
   264       typedef T ValueType;
   271 
   274 
   272       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   275       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   273       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   276       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   274     };
   277     };
   275 
   278 
   276     ///Read/write map from the edges to type \c T.
   279     /// Read/write map from the edges to type \c T.
   277     template<typename T> class EdgeMap
   280     template<typename T> class EdgeMap
   278     {
   281     {
   279       leda_edge_map<T> leda_stuff;
   282       leda_edge_map<T> leda_stuff;
   280     public:
   283     public:
   281       typedef T ValueType;
   284       typedef T ValueType;
   292       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   295       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   293       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   296       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   294     };
   297     };
   295 
   298 
   296 
   299 
   297     ///Read/write map from the nodes to type \c T.
   300     /// This class is to wrap existing 
       
   301     /// LEDA node-maps to HUGO ones.
   298     template<typename T> class NodeMapWrapper
   302     template<typename T> class NodeMapWrapper
   299     {
   303     {
   300       leda_node_map<T>* leda_stuff;
   304       leda_node_array<T>* leda_stuff;
   301     public:
   305     public:
   302       typedef T ValueType;
   306       typedef T ValueType;
   303       typedef Node KeyType;
   307       typedef Node KeyType;
   304 
   308 
   305       NodeMapWrapper(leda_node_map<T>& _leda_stuff) : 
   309       NodeMapWrapper(leda_node_array<T>& _leda_stuff) : 
   306 	leda_stuff(&_leda_stuff) { }
   310 	leda_stuff(&_leda_stuff) { }
   307       //NodeMap(leda_node_map& &G, T t) : leda_stuff(*(G.l_graph), t) {}
   311       //NodeMap(leda_node_map& &G, T t) : leda_stuff(*(G.l_graph), t) {}
   308 
   312 
   309       void set(Node i, T t) { (*leda_stuff)[i.l_n]=t; }
   313       void set(Node i, T t) { (*leda_stuff)[i.l_n]=t; }
   310       T get(Node i) const { return (*leda_stuff)[i.l_n]; }  //FIXME: Is it necessary
   314       //T get(Node i) const { return (*leda_stuff)[i.l_n]; }  //FIXME: Is it necessary
   311       T &operator[](Node i) { return (*leda_stuff)[i.l_n]; }
   315       T &operator[](Node i) { return (*leda_stuff)[i.l_n]; }
   312       const T &operator[](Node i) const { return (*leda_stuff)[i.l_n]; }
   316       const T &operator[](Node i) const { return (*leda_stuff)[i.l_n]; }
   313 
   317 
   314       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   318       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   315       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   319       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   316     };
   320     };
   317 
   321 
   318     ///Read/write map from the edges to type \c T.
   322     /// This class is to wrap existing 
       
   323     /// LEDA edge-maps to HUGO ones.
   319     template<typename T> class EdgeMapWrapper
   324     template<typename T> class EdgeMapWrapper
   320     {
   325     {
   321       leda_edge_map<T>* leda_stuff;
   326       leda_edge_array<T>* leda_stuff;
   322     public:
   327     public:
   323       typedef T ValueType;
   328       typedef T ValueType;
   324       typedef Edge KeyType;
   329       typedef Edge KeyType;
   325 
   330 
   326       EdgeMapWrapper(leda_edge_map<T>& _leda_stuff) : 
   331       EdgeMapWrapper(leda_edge_array<T>& _leda_stuff) : 
   327 	leda_stuff(_leda_stuff) { }
   332 	leda_stuff(_leda_stuff) { }
   328       //EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G.l_graph), t) {}
   333       //EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G.l_graph), t) {}
   329 
   334 
   330       void set(Edge i, T t) { (*leda_stuff)[i.l_e]=t; }
   335       void set(Edge i, T t) { (*leda_stuff)[i.l_e]=t; }
   331       T get(Edge i) const { return (*leda_stuff)[i.l_e]; }  //FIXME: Is it necessary
   336       //T get(Edge i) const { return (*leda_stuff)[i.l_e]; }  //FIXME: Is it necessary
   332       T &operator[](Edge i) { return (*leda_stuff)[i.l_e]; }
   337       T &operator[](Edge i) { return (*leda_stuff)[i.l_e]; }
   333       const T &operator[](Edge i) const { return (*leda_stuff)[i.l_e]; }
   338       const T &operator[](Edge i) const { return (*leda_stuff)[i.l_e]; }
   334 
   339 
   335       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   340       void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ }
   336       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
   341       //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); }   //FIXME: Is it necessary
       
   342     };
       
   343 
       
   344     /// This class is used for access node-data of 
       
   345     /// LEDA parametrized graphs.
       
   346     template<typename T> 
       
   347     class NodeDataMap : public NodeMapWrapper<T>
       
   348     {
       
   349     public:
       
   350       NodeDataMap(LedaGraphWrapper<Graph>& LGW) : 
       
   351 	NodeMapWrapper<T>(*(LGW._g_graph).node_data()) { }
       
   352     };
       
   353 
       
   354     /// This class is used for access edge-data of 
       
   355     /// LEDA parametrized graphs.
       
   356     template<typename T> 
       
   357     class EdgeDataMap : public EdgeMapWrapper<T>
       
   358     {
       
   359     public:
       
   360       EdgeDataMap(LedaGraphWrapper<Graph>& LGW) : 
       
   361 	EdgeMapWrapper<T>(*(LGW._g_graph).edge_data()) { }
   337     };
   362     };
   338 
   363 
   339   };
   364   };
   340 
   365 
   341 
   366