lemon/graph_adaptor.h
changeset 1571 68ce4302fb0b
parent 1536 308150155bb5
child 1576 e5957f8866e6
equal deleted inserted replaced
2:990e1cad3100 3:ad9954449fbf
  1213       setFirstOutEdgesMap(_first_out_edges);
  1213       setFirstOutEdgesMap(_first_out_edges);
  1214     } 
  1214     } 
  1215 
  1215 
  1216   };
  1216   };
  1217 
  1217 
  1218   /// \e
       
  1219   template <typename _Graph>
  1218   template <typename _Graph>
  1220   class NewEdgeSetAdaptorBase {
  1219   class NewEdgeSetAdaptorBase {
  1221   public:
  1220   public:
  1222 
  1221 
  1223     typedef _Graph Graph;
  1222     typedef _Graph Graph;
  1411     Node source(const Edge& edge) const { return edges[edge.id].source;}
  1410     Node source(const Edge& edge) const { return edges[edge.id].source;}
  1412     Node target(const Edge& edge) const { return edges[edge.id].target;}
  1411     Node target(const Edge& edge) const { return edges[edge.id].target;}
  1413 
  1412 
  1414   };
  1413   };
  1415 
  1414 
       
  1415 
       
  1416   /// \brief Graph adaptor using a node set of another graph and an
       
  1417   /// own edge set.
       
  1418   ///
       
  1419   /// This structure can be used to establish another graph over a node set
       
  1420   /// of an existing one. The node iterator will go through the nodes of the
       
  1421   /// original graph.
       
  1422   ///
       
  1423   /// \param _Graph The type of the graph which shares its node set with 
       
  1424   /// this class. Its interface must conform to the \ref skeleton::StaticGraph
       
  1425   /// "StaticGraph" concept.
       
  1426   ///
       
  1427   /// In the edge extension and removing it conforms to the 
       
  1428   /// \ref skeleton::ExtendableGraph "ExtendableGraph" concept.
  1416   template <typename _Graph>
  1429   template <typename _Graph>
  1417   class NewEdgeSetAdaptor :
  1430   class NewEdgeSetAdaptor :
  1418     public ErasableGraphExtender<
  1431     public ErasableGraphExtender<
  1419     ClearableGraphExtender<
  1432     ClearableGraphExtender<
  1420     ExtendableGraphExtender<
  1433     ExtendableGraphExtender<
  1473 
  1486 
  1474     NodesImpl nodes;
  1487     NodesImpl nodes;
  1475     
  1488     
  1476   public:
  1489   public:
  1477 
  1490 
       
  1491     /// \brief Constructor of the adaptor.
       
  1492     /// 
       
  1493     /// Constructor of the adaptor.
  1478     NewEdgeSetAdaptor(const _Graph& _graph) : nodes(*this, _graph) {
  1494     NewEdgeSetAdaptor(const _Graph& _graph) : nodes(*this, _graph) {
  1479       Parent::initalize(_graph, nodes);
  1495       Parent::initalize(_graph, nodes);
  1480     }
  1496     }
  1481 
  1497 
  1482     void clear() {
  1498     void clear() {
       
  1499       Parent::getNotifier(Edge()).clear();      
       
  1500 
  1483       Parent::edges.clear();
  1501       Parent::edges.clear();
  1484       Parent::first_edge = -1;
  1502       Parent::first_edge = -1;
  1485       Parent::first_free_edge = -1;
  1503       Parent::first_free_edge = -1;
  1486 
  1504     }
       
  1505     
       
  1506   };
       
  1507 
       
  1508   /// \brief Graph adaptor using a node set of another graph and an
       
  1509   /// own undir edge set.
       
  1510   ///
       
  1511   /// This structure can be used to establish another undirected graph over 
       
  1512   /// a node set of an existing one. The node iterator will go through the 
       
  1513   /// nodes of the original graph.
       
  1514   ///
       
  1515   /// \param _Graph The type of the graph which shares its node set with 
       
  1516   /// this class. Its interface must conform to the \ref skeleton::StaticGraph
       
  1517   /// "StaticGraph" concept.
       
  1518   ///
       
  1519   /// In the edge extension and removing it conforms to the 
       
  1520   /// \ref skeleton::ExtendableGraph "ExtendableGraph" concept.
       
  1521   template <typename _Graph>
       
  1522   class NewUndirEdgeSetAdaptor :
       
  1523     public ErasableUndirGraphExtender<
       
  1524     ClearableUndirGraphExtender<
       
  1525     ExtendableUndirGraphExtender<
       
  1526     MappableUndirGraphExtender<
       
  1527     IterableUndirGraphExtender<
       
  1528     AlterableUndirGraphExtender<
       
  1529     UndirGraphExtender<
       
  1530     NewEdgeSetAdaptorBase<_Graph> > > > > > > > {
       
  1531 
       
  1532   public:
       
  1533 
       
  1534     typedef ErasableUndirGraphExtender<
       
  1535       ClearableUndirGraphExtender<
       
  1536       ExtendableUndirGraphExtender<
       
  1537       MappableUndirGraphExtender<
       
  1538       IterableUndirGraphExtender<
       
  1539       AlterableUndirGraphExtender<
       
  1540       UndirGraphExtender<
       
  1541       NewEdgeSetAdaptorBase<_Graph> > > > > > > > Parent;
       
  1542     
       
  1543 
       
  1544     typedef typename Parent::Node Node;
       
  1545     typedef typename Parent::Edge Edge;
       
  1546     typedef typename Parent::UndirEdge UndirEdge;
       
  1547 
       
  1548   private:
       
  1549 
       
  1550     virtual void _clear() {
       
  1551       Parent::edges.clear();
       
  1552       Parent::first_edge = -1;
       
  1553       Parent::first_free_edge = -1;
       
  1554       Parent::getNotifier(Edge()).clear();
       
  1555       Parent::getNotifier(Node()).clear();
       
  1556     }
       
  1557 
       
  1558     virtual void _add(const Node& node) {
       
  1559       Parent::getNotifier(Node()).add(node);
       
  1560     }
       
  1561 
       
  1562     virtual void _erase(const Node& node) {
       
  1563       Edge edge;
       
  1564       Parent::firstOut(edge, node);
       
  1565       while (edge != INVALID) {
       
  1566 	Parent::erase(edge);
       
  1567 	Parent::firstOut(edge, node);
       
  1568       }
       
  1569 
       
  1570       Parent::firstIn(edge, node);
       
  1571       while (edge != INVALID) {
       
  1572 	Parent::erase(edge);
       
  1573 	Parent::firstIn(edge, node);
       
  1574       }
       
  1575       
       
  1576       Parent::getNotifier(Node()).erase(node);
       
  1577     }
       
  1578 
       
  1579     typedef typename Parent::NodesImpl NodesImpl;
       
  1580 
       
  1581     NodesImpl nodes;
       
  1582     
       
  1583   public:
       
  1584 
       
  1585 
       
  1586     /// \brief Constructor of the adaptor.
       
  1587     /// 
       
  1588     /// Constructor of the adaptor.
       
  1589     NewUndirEdgeSetAdaptor(const _Graph& _graph) : nodes(*this, _graph) {
       
  1590       Parent::initalize(_graph, nodes);
       
  1591     }
       
  1592 
       
  1593     void clear() {
  1487       Parent::getNotifier(Edge()).clear();      
  1594       Parent::getNotifier(Edge()).clear();      
       
  1595       Parent::getNotifier(UndirEdge()).clear();      
       
  1596 
       
  1597       Parent::edges.clear();
       
  1598       Parent::first_edge = -1;
       
  1599       Parent::first_free_edge = -1;
  1488     }
  1600     }
  1489     
  1601     
  1490   };
  1602   };
  1491 
  1603 
  1492   ///@}
  1604   ///@}