src/lemon/concept/graph.h
changeset 981 2e34b796d532
parent 959 c80ef5912903
child 986 e997802b855c
equal deleted inserted replaced
0:2f8dae23d160 1:0325f0fc2945
   763 
   763 
   764 
   764 
   765     /************* New GraphBase stuff **************/
   765     /************* New GraphBase stuff **************/
   766 
   766 
   767 
   767 
   768     /// \bug The nodes and edges are not allowed to inherit from the
       
   769     /// same baseclass.
       
   770 
       
   771     class BaseGraphItem {
       
   772     public:
       
   773       BaseGraphItem() {}
       
   774       BaseGraphItem(Invalid) {}
       
   775 
       
   776       // We explicitely list these:
       
   777       BaseGraphItem(BaseGraphItem const&) {}
       
   778       BaseGraphItem& operator=(BaseGraphItem const&) { return *this; }
       
   779 
       
   780       bool operator==(BaseGraphItem) const { return false; }
       
   781       bool operator!=(BaseGraphItem) const { return false; }
       
   782 
       
   783       // Technical requirement. Do we really need this?
       
   784       bool operator<(BaseGraphItem) const { return false; }
       
   785     };
       
   786 
       
   787 
       
   788     /// A minimal GraphBase concept
   768     /// A minimal GraphBase concept
   789 
   769 
   790     /// This class describes a minimal concept which can be extended to a
   770     /// This class describes a minimal concept which can be extended to a
   791     /// full-featured graph with \ref GraphFactory.
   771     /// full-featured graph with \ref GraphFactory.
   792     class GraphBase {
   772     class GraphBase {
   793     public:
   773     public:
   794 
   774 
   795       GraphBase() {}
   775       GraphBase() {}
   796 
   776 
   797 
   777       /// \bug Should we demand that Node and Edge be subclasses of the
   798       /// \bug Nodes and Edges are comparable each other
   778       /// Graph class???
   799       
   779 
   800       class Node : public BaseGraphItem {};
   780       typedef GraphItem<'n'> Node;
   801       class Edge : public BaseGraphItem {};
   781       typedef GraphItem<'e'> Edge;
       
   782 
       
   783 //       class Node : public BaseGraphItem<'n'> {};
       
   784 //       class Edge : public BaseGraphItem<'e'> {};
   802 
   785 
   803       // Graph operation
   786       // Graph operation
   804       void firstNode(Node &n) const { }
   787       void firstNode(Node &n) const { }
   805       void firstEdge(Edge &e) const { }
   788       void firstEdge(Edge &e) const { }
   806 
   789 
   838       class EdgeMap : public GraphMap<Edge, T, GraphBase> {};
   821       class EdgeMap : public GraphMap<Edge, T, GraphBase> {};
   839     };
   822     };
   840 
   823 
   841 
   824 
   842 
   825 
   843     /**************** Concept checking classes ****************/
   826 
   844 
   827     /**************** The full-featured graph concepts ****************/
   845     template<typename BGI>
   828 
   846     struct BaseGraphItemConcept {
       
   847       void constraints() {
       
   848 	BGI i1;
       
   849 	BGI i2 = i1;
       
   850 	BGI i3 = INVALID;
       
   851 	
       
   852 	i1 = i3;
       
   853 	if( i1 == i3 ) {
       
   854 	  if ( i2 != i3 && i3 < i2 )
       
   855 	    return;
       
   856 	}
       
   857       }
       
   858     };
       
   859 
       
   860     
       
   861     
   829     
   862     class StaticGraph 
   830     class StaticGraph 
   863       :  virtual public BaseGraphComponent, public IterableGraphComponent, public MappableGraphComponent {
   831       :  virtual public BaseGraphComponent,
       
   832 	 public IterableGraphComponent, public MappableGraphComponent {
   864     public:
   833     public:
   865       typedef BaseGraphComponent::Node Node;
   834       typedef BaseGraphComponent::Node Node;
   866       typedef BaseGraphComponent::Edge Edge;
   835       typedef BaseGraphComponent::Edge Edge;
   867     };
   836     };
   868 
   837 
   869     template <typename Graph>
   838     template <typename Graph>
   870     struct StaticGraphConcept {
   839     struct StaticGraphConcept {
   871       void constraints() {
   840       void constraints() {
   872 	function_requires<BaseGraphComponentConcept<Graph> >();
       
   873 	function_requires<IterableGraphComponentConcept<Graph> >();
   841 	function_requires<IterableGraphComponentConcept<Graph> >();
   874 	function_requires<MappableGraphComponentConcept<Graph> >();
   842 	function_requires<MappableGraphComponentConcept<Graph> >();
   875       }
   843       }
   876       Graph& graph;
       
   877     };
   844     };
   878 
   845 
   879     class ExtendableGraph 
   846     class ExtendableGraph 
   880       :  virtual public BaseGraphComponent, public StaticGraph, public ExtendableGraphComponent, public ClearableGraphComponent {
   847       :  virtual public BaseGraphComponent, public StaticGraph,
       
   848 	 public ExtendableGraphComponent, public ClearableGraphComponent {
   881     public:
   849     public:
   882       typedef BaseGraphComponent::Node Node;
   850       typedef BaseGraphComponent::Node Node;
   883       typedef BaseGraphComponent::Edge Edge;
   851       typedef BaseGraphComponent::Edge Edge;
   884     };
   852     };
   885 
   853 
   888       void constraints() {
   856       void constraints() {
   889 	function_requires<StaticGraphConcept<Graph> >();
   857 	function_requires<StaticGraphConcept<Graph> >();
   890 	function_requires<ExtendableGraphComponentConcept<Graph> >();
   858 	function_requires<ExtendableGraphComponentConcept<Graph> >();
   891 	function_requires<ClearableGraphComponentConcept<Graph> >();
   859 	function_requires<ClearableGraphComponentConcept<Graph> >();
   892       }
   860       }
   893       Graph& graph;
       
   894     };
   861     };
   895 
   862 
   896     class ErasableGraph 
   863     class ErasableGraph 
   897       :  virtual public BaseGraphComponent, public ExtendableGraph, public ErasableGraphComponent {
   864       :  virtual public BaseGraphComponent, public ExtendableGraph,
       
   865 	 public ErasableGraphComponent {
   898     public:
   866     public:
   899       typedef BaseGraphComponent::Node Node;
   867       typedef BaseGraphComponent::Node Node;
   900       typedef BaseGraphComponent::Edge Edge;
   868       typedef BaseGraphComponent::Edge Edge;
   901     };
   869     };
   902 
   870 
   904     struct ErasableGraphConcept {
   872     struct ErasableGraphConcept {
   905       void constraints() {
   873       void constraints() {
   906 	function_requires<ExtendableGraphConcept<Graph> >();
   874 	function_requires<ExtendableGraphConcept<Graph> >();
   907 	function_requires<ErasableGraphComponentConcept<Graph> >();
   875 	function_requires<ErasableGraphComponentConcept<Graph> >();
   908       }
   876       }
   909       Graph& graph;
       
   910     };
   877     };
   911 
   878 
   912     // @}
   879     // @}
   913   } //namespace concept  
   880   } //namespace concept  
   914 } //namespace lemon
   881 } //namespace lemon