src/lemon/concept/graph_component.h
changeset 1134 56b07afdbf8d
parent 1106 0a7d604a9763
child 1136 8d066154b66a
equal deleted inserted replaced
12:8a8898986536 13:bbb39b287e7e
    22 #ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
    22 #ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
    23 #define LEMON_CONCEPT_GRAPH_COMPONENT_H
    23 #define LEMON_CONCEPT_GRAPH_COMPONENT_H
    24 
    24 
    25 #include <lemon/invalid.h>
    25 #include <lemon/invalid.h>
    26 #include <lemon/concept/maps.h>
    26 #include <lemon/concept/maps.h>
       
    27 
       
    28 #include <lemon/alteration_notifier.h>
    27 
    29 
    28 namespace lemon {
    30 namespace lemon {
    29   namespace concept {
    31   namespace concept {
    30 
    32 
    31     /// \addtogroup graph_concepts
    33     /// \addtogroup graph_concepts
   569       /// Copy constructor.
   571       /// Copy constructor.
   570       
   572       
   571       /// Copy constructor.
   573       /// Copy constructor.
   572       ///
   574       ///
   573       GraphIncIterator(GraphIncIterator const&) {}
   575       GraphIncIterator(GraphIncIterator const&) {}
   574       /// Sets the iterator to the first edge incoming into or outgoing from the node.
   576       /// Sets the iterator to the first edge incoming into or outgoing 
   575       
   577       /// from the node.
   576       /// Sets the iterator to the first edge incoming into or outgoing from the node.
   578       
       
   579       /// Sets the iterator to the first edge incoming into or outgoing 
       
   580       /// from the node.
   577       ///
   581       ///
   578       explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
   582       explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
   579       /// Invalid constructor \& conversion.
   583       /// Invalid constructor \& conversion.
   580 
   584 
   581       /// This constructor initializes the item to be invalid.
   585       /// This constructor initializes the item to be invalid.
   669     template <typename _Graph> 
   673     template <typename _Graph> 
   670     struct Constraints {
   674     struct Constraints {
   671       void constraints() {
   675       void constraints() {
   672   	checkConcept< BaseGraphComponent, _Graph>();
   676   	checkConcept< BaseGraphComponent, _Graph>();
   673 
   677 
   674 	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >();
   678 	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>,
   675 	checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >();
   679 	  typename _Graph::EdgeIt >();
       
   680 	checkConcept<GraphIterator<_Graph, typename _Graph::Node>,
       
   681 	  typename _Graph::NodeIt >();
   676 	checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
   682 	checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
   677 	checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
   683 	checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
   678       }
   684       }
       
   685     };
       
   686 
       
   687     /// An empty alteration notifier base graph class.
       
   688   
       
   689     /// This class provides beside the core graph features
       
   690     /// alteration notifier interface for the graph structure.
       
   691     /// This is an observer-notifier pattern. More Obsevers can
       
   692     /// be registered into the notifier and whenever an alteration
       
   693     /// occured in the graph all the observers will notified about it.
       
   694     class AlterableGraphComponent : virtual public BaseGraphComponent {
       
   695     public:
       
   696 
       
   697       /// The edge observer registry.
       
   698       typedef AlterationNotifier<Edge> EdgeNotifier;
       
   699       /// The node observer registry.
       
   700       typedef AlterationNotifier<Node> NodeNotifier;
       
   701       
       
   702       /// \brief Gives back the edge alteration notifier.
       
   703       ///
       
   704       /// Gives back the edge alteration notifier.
       
   705       EdgeNotifier getNotifier(Edge) const {
       
   706 	return EdgeNotifier();
       
   707       }
       
   708       
       
   709       /// \brief Gives back the node alteration notifier.
       
   710       ///
       
   711       /// Gives back the node alteration notifier.
       
   712       NodeNotifier getNotifier(Node) const {
       
   713 	return NodeNotifier();
       
   714       }
       
   715       
   679     };
   716     };
   680 
   717 
   681 
   718 
   682     /// Class describing the concept of graph maps
   719     /// Class describing the concept of graph maps
   683 
   720 
   687     template <typename Graph, typename Item, typename _Value>
   724     template <typename Graph, typename Item, typename _Value>
   688     class GraphMap : public ReadWriteMap<Item, _Value> {
   725     class GraphMap : public ReadWriteMap<Item, _Value> {
   689     protected:      
   726     protected:      
   690       GraphMap() {}
   727       GraphMap() {}
   691     public:
   728     public:
       
   729       /// \brief Construct a new map.
       
   730       ///
       
   731       /// Construct a new map for the graph.
   692       explicit GraphMap(const Graph&) {}
   732       explicit GraphMap(const Graph&) {}
       
   733       /// \brief Construct a new map with default value.
       
   734       ///
       
   735       /// Construct a new map for the graph and initalise the values.
   693       GraphMap(const Graph&, const _Value&) {}
   736       GraphMap(const Graph&, const _Value&) {}
       
   737       /// \brief Copy constructor.
       
   738       ///
       
   739       /// Copy Constructor.
   694       GraphMap(const GraphMap&) {}
   740       GraphMap(const GraphMap&) {}
   695       
   741       
       
   742       /// \brief Assign operator.
       
   743       ///
       
   744       /// Assign operator.
   696       GraphMap& operator=(const GraphMap&) { return *this;}
   745       GraphMap& operator=(const GraphMap&) { return *this;}
   697 
   746 
   698       template<typename _Map>
   747       template<typename _Map>
   699       struct Constraints {
   748       struct Constraints {
   700 	void constraints() {
   749 	void constraints() {
   738       template <typename _Value>
   787       template <typename _Value>
   739       class NodeMap : public GraphMap<Graph, Node, _Value> {
   788       class NodeMap : public GraphMap<Graph, Node, _Value> {
   740       private:
   789       private:
   741 	NodeMap();
   790 	NodeMap();
   742       public:
   791       public:
   743 	// \todo call the right parent class constructor
   792 	/// \brief Construct a new map.
       
   793 	///
       
   794 	/// Construct a new map for the graph.
       
   795 	/// \todo call the right parent class constructor
   744 	explicit NodeMap(const Graph&) {}
   796 	explicit NodeMap(const Graph&) {}
       
   797 	/// \brief Construct a new map with default value.
       
   798 	///
       
   799 	/// Construct a new map for the graph and initalise the values.
   745 	NodeMap(const Graph&, const _Value&) {}
   800 	NodeMap(const Graph&, const _Value&) {}
       
   801 	/// \brief Copy constructor.
       
   802 	///
       
   803 	/// Copy Constructor.
   746 	NodeMap(const NodeMap&) {}
   804 	NodeMap(const NodeMap&) {}
   747 
   805 
       
   806 	/// \brief Assign operator.
       
   807 	///
       
   808 	/// Assign operator.
   748 	NodeMap& operator=(const NodeMap&) { return *this;}
   809 	NodeMap& operator=(const NodeMap&) { return *this;}
   749 
   810 
   750       };
   811       };
   751 
   812 
   752       /// ReadWrite map of the edges.
   813       /// ReadWrite map of the edges.
   756       template <typename _Value>
   817       template <typename _Value>
   757       class EdgeMap : public GraphMap<Graph, Edge, _Value> {
   818       class EdgeMap : public GraphMap<Graph, Edge, _Value> {
   758       private:
   819       private:
   759 	EdgeMap();
   820 	EdgeMap();
   760       public:
   821       public:
   761 	// \todo call the right parent class constructor
   822 	/// \brief Construct a new map.
       
   823 	///
       
   824 	/// Construct a new map for the graph.
       
   825 	/// \todo call the right parent class constructor
   762 	explicit EdgeMap(const Graph&) {}
   826 	explicit EdgeMap(const Graph&) {}
       
   827 	/// \brief Construct a new map with default value.
       
   828 	///
       
   829 	/// Construct a new map for the graph and initalise the values.
   763 	EdgeMap(const Graph&, const _Value&) {}
   830 	EdgeMap(const Graph&, const _Value&) {}
       
   831 	/// \brief Copy constructor.
       
   832 	///
       
   833 	/// Copy Constructor.
   764 	EdgeMap(const EdgeMap&) {}
   834 	EdgeMap(const EdgeMap&) {}
   765 
   835 
       
   836 	/// \brief Assign operator.
       
   837 	///
       
   838 	/// Assign operator.
   766 	EdgeMap& operator=(const EdgeMap&) { return *this;}
   839 	EdgeMap& operator=(const EdgeMap&) { return *this;}
   767 
   840 
   768       };
   841       };
   769 
   842 
   770       template <typename _Graph>
   843       template <typename _Graph>
   778 
   851 
   779 	void constraints() {
   852 	void constraints() {
   780 	  checkConcept<BaseGraphComponent, _Graph>();
   853 	  checkConcept<BaseGraphComponent, _Graph>();
   781 	  { // int map test
   854 	  { // int map test
   782 	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
   855 	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
   783 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, IntNodeMap >();
   856 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, 
       
   857 	      IntNodeMap >();
   784 	  } { // bool map test
   858 	  } { // bool map test
   785 	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
   859 	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
   786 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, BoolNodeMap >();
   860 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
       
   861 	      BoolNodeMap >();
   787 	  } { // Type map test
   862 	  } { // Type map test
   788 	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
   863 	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
   789 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, TypeNodeMap >();
   864 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
       
   865 	      TypeNodeMap >();
   790 	  } 
   866 	  } 
   791 
   867 
   792 	  { // int map test
   868 	  { // int map test
   793 	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
   869 	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
   794 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, IntEdgeMap >();
   870 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
       
   871 	      IntEdgeMap >();
   795 	  } { // bool map test
   872 	  } { // bool map test
   796 	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
   873 	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
   797 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, BoolEdgeMap >();
   874 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
       
   875 	      BoolEdgeMap >();
   798 	  } { // Type map test
   876 	  } { // Type map test
   799 	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
   877 	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
   800 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, TypeEdgeMap >();
   878 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, 
       
   879 	      TypeEdgeMap >();
   801 	  } 
   880 	  } 
   802 	}
   881 	}
   803 
   882 
   804 	_Graph& graph;
   883 	_Graph& graph;
   805       };
   884       };
   806     };
   885     };
   807 
   886 
   808 
   887     /// \brief An empty extendable extended graph class.
       
   888     ///
       
   889     /// This class provides beside the core graph features
       
   890     /// item addition interface for the graph structure.
       
   891     /// The difference between this class and the 
       
   892     /// \c BaseExtendableGraphComponent is that it should
       
   893     /// notify the item alteration observers.
   809     class ExtendableGraphComponent : virtual public BaseGraphComponent {
   894     class ExtendableGraphComponent : virtual public BaseGraphComponent {
   810     public:
   895     public:
   811 
   896 
   812       typedef ExtendableGraphComponent Graph;
   897       typedef ExtendableGraphComponent Graph;
   813 
   898 
   814       typedef BaseGraphComponent::Node Node;
   899       typedef BaseGraphComponent::Node Node;
   815       typedef BaseGraphComponent::Edge Edge;
   900       typedef BaseGraphComponent::Edge Edge;
   816 
   901 
       
   902       /// \brief Add a node to the graph.
       
   903       ///
       
   904       /// Add a node to the graph and notify the observers.
   817       Node addNode() {
   905       Node addNode() {
   818 	return INVALID;
   906 	return INVALID;
   819       }
   907       }
   820     
   908     
       
   909       /// \brief Add an edge to the graph.
       
   910       ///
       
   911       /// Add an edge to the graph and notify the observers.
   821       Edge addEdge(const Node& from, const Node& to) {
   912       Edge addEdge(const Node& from, const Node& to) {
   822 	return INVALID;
   913 	return INVALID;
   823       }
   914       }
   824 
   915 
   825       template <typename _Graph>
   916       template <typename _Graph>
   832 	  edge = graph.addEdge(node_a, node_b);      
   923 	  edge = graph.addEdge(node_a, node_b);      
   833 	}
   924 	}
   834 	_Graph& graph;
   925 	_Graph& graph;
   835       };
   926       };
   836     };
   927     };
       
   928 
       
   929     /// \brief An empty erasable extended graph class.
       
   930     ///
       
   931     /// This class provides beside the core graph features
       
   932     /// item erase interface for the graph structure.
       
   933     /// The difference between this class and the 
       
   934     /// \c BaseErasableGraphComponent is that it should
       
   935     /// notify the item alteration observers.
   837     class ErasableGraphComponent : virtual public BaseGraphComponent {
   936     class ErasableGraphComponent : virtual public BaseGraphComponent {
   838     public:
   937     public:
   839 
   938 
   840       typedef ErasableGraphComponent Graph;
   939       typedef ErasableGraphComponent Graph;
   841 
   940 
   842       typedef BaseGraphComponent::Node Node;
   941       typedef BaseGraphComponent::Node Node;
   843       typedef BaseGraphComponent::Edge Edge;
   942       typedef BaseGraphComponent::Edge Edge;
   844 
   943 
       
   944       /// \brief Erase the Node and notify the node alteration observers.
       
   945       ///
       
   946       ///  Erase the Node and notify the node alteration observers.
   845       void erase(const Node&) {}    
   947       void erase(const Node&) {}    
       
   948 
       
   949       /// \brief Erase the Edge and notify the edge alteration observers.
       
   950       ///
       
   951       ///  Erase the Edge and notify the edge alteration observers.
   846       void erase(const Edge&) {}
   952       void erase(const Edge&) {}
   847 
   953 
   848       template <typename _Graph>
   954       template <typename _Graph>
   849       struct Constraints {
   955       struct Constraints {
   850 	void constraints() {
   956 	void constraints() {