src/work/sage_graph.h
changeset 905 5be029d19c98
parent 642 e812963087f0
child 921 818510fa3d99
equal deleted inserted replaced
0:5c88e4897975 1:aa2ca19188a7
     7 
     7 
     8 #include <hugo/invalid.h>
     8 #include <hugo/invalid.h>
     9 
     9 
    10 namespace hugo {
    10 namespace hugo {
    11 
    11 
    12   template <typename It>
    12 //   template <typename It>
    13   int count(It it) { 
    13 //   int count(It it) { 
    14     int i=0;
    14 //     int i=0;
    15     for( ; it.valid(); ++it) { ++i; } 
    15 //     for( ; it.valid(); ++it) { ++i; } 
    16     return i;
    16 //     return i;
    17   }
    17 //   }
    18 
    18 
    19   class SageGraph {
    19   class SageGraph {
    20     struct node_item;
    20     struct node_item;
    21     struct edge_item;
    21     struct edge_item;
    22   public:
    22   public:
   383     class NodeIt : public Node {
   383     class NodeIt : public Node {
   384       friend class SageGraph;
   384       friend class SageGraph;
   385       //protected:
   385       //protected:
   386     public: //for everybody but marci
   386     public: //for everybody but marci
   387       NodeIt(const SageGraph& G) : Node(G._first_node) { }
   387       NodeIt(const SageGraph& G) : Node(G._first_node) { }
       
   388       NodeIt(const SageGraph& G, const Node& n) : Node(n) { } 
   388     public:
   389     public:
   389       NodeIt() : Node() { }
   390       NodeIt() : Node() { }
   390       NodeIt(const Invalid& i) : Node(i) { }
   391       NodeIt(const Invalid& i) : Node(i) { }
   391     protected:
   392     protected:
   392       NodeIt(node_item* v) : Node(v) { }
   393       NodeIt(node_item* v) : Node(v) { }
       
   394     public:
   393       NodeIt& operator++() { node=node->_next_node; return *this; }
   395       NodeIt& operator++() { node=node->_next_node; return *this; }
   394       //FIXME::
   396       //FIXME::
   395       //      NodeIt& operator=(const Node& e)
   397       //      NodeIt& operator=(const Node& e)
   396       //      { node=e.node; return *this; }
   398       //      { node=e.node; return *this; }
   397     };
   399     };
   423       friend std::ostream& operator<<(std::ostream& os, const Edge& i);
   425       friend std::ostream& operator<<(std::ostream& os, const Edge& i);
   424     };
   426     };
   425     
   427     
   426     class EdgeIt : public Edge {
   428     class EdgeIt : public Edge {
   427       friend class SageGraph;
   429       friend class SageGraph;
   428       //protected: 
   430     public:
   429     public: //for alpar
   431       EdgeIt() : Edge() { }
       
   432       EdgeIt(const Invalid& i) : Edge(i) { }
   430       EdgeIt(const SageGraph& G) {
   433       EdgeIt(const SageGraph& G) {
   431 	node_item* v=G._first_node;
   434 	node_item* v=G._first_node;
   432 	if (v) edge=v->_first_out_edge; else edge=0;
   435 	if (v) edge=v->_first_out_edge; else edge=0;
   433 	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   436 	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   434       }
   437       }
   435     public:
   438       EdgeIt(const SageGraph& G, const Edge& e) : Edge(e) { }
   436       EdgeIt() : Edge() { }
   439 //     protected:
   437       EdgeIt(const Invalid& i) : Edge(i) { }
   440 //       EdgeIt(edge_item* _e) : Edge(_e) { }
   438     protected:
   441     public:
   439       EdgeIt(edge_item* _e) : Edge(_e) { }
       
   440       EdgeIt& operator++() { 
   442       EdgeIt& operator++() { 
   441 	node_item* v=edge->_tail;
   443 	node_item* v=edge->_tail;
   442 	edge=edge->_next_out; 
   444 	edge=edge->_next_out; 
   443 	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   445 	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   444 	return *this;
   446 	return *this;
   445       }
   447       }
   446     };
   448     };
   447     
   449     
   448     class OutEdgeIt : public Edge {
   450     class OutEdgeIt : public Edge {
   449       friend class SageGraph;
   451       friend class SageGraph;
   450       //node_item* v;
   452     public:
   451       //protected: 
   453       OutEdgeIt() : Edge() { }
   452     protected: //for alpar
       
   453       OutEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
       
   454     public:
       
   455       OutEdgeIt() : Edge()/*, v(0)*/ { }
       
   456       OutEdgeIt(const Invalid& i) : Edge(i) { }
   454       OutEdgeIt(const Invalid& i) : Edge(i) { }
   457       OutEdgeIt(const SageGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
   455       OutEdgeIt(const SageGraph&, Node _v) : Edge(_v.node->_first_out_edge) { }
   458     protected:
   456       OutEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { }
   459       OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
   457       OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
   460     protected:
   458     protected:
   461       Node aNode() const { return Node(edge->_tail); }
   459       Node aNode() const { return Node(edge->_tail); }
   462       Node bNode() const { return Node(edge->_head); }
   460       Node bNode() const { return Node(edge->_head); }
   463     };
   461     };
   464     
   462     
   465     class InEdgeIt : public Edge {
   463     class InEdgeIt : public Edge {
   466       friend class SageGraph;
   464       friend class SageGraph;
   467       //node_item* v;
   465     public:
   468       //protected:
   466       InEdgeIt() : Edge() { }
   469     protected: //for alpar
   467       InEdgeIt(Invalid i) : Edge(i) { }
   470       InEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
   468       InEdgeIt(const SageGraph&, Node _v) : Edge(_v.node->_first_in_edge) { }
   471     public:
   469       InEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { }
   472       InEdgeIt() : Edge()/*, v(0)*/ { }
       
   473       InEdgeIt(const Invalid& i) : Edge(i) { }
       
   474       InEdgeIt(const SageGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
       
   475     protected:
       
   476       InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
   470       InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
   477     protected:
   471     protected:
   478       Node aNode() const { return Node(edge->_head); }
   472       Node aNode() const { return Node(edge->_head); }
   479       Node bNode() const { return Node(edge->_tail); }
   473       Node bNode() const { return Node(edge->_tail); }
   480     };
   474     };