diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept/graph_component.h --- a/src/lemon/concept/graph_component.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept/graph_component.h Sat Nov 13 21:37:54 2004 +0000 @@ -37,90 +37,64 @@ /// base class, this is a template. For Node you should instantiate it /// with character 'n' and for Edge with 'e'. - template + template class GraphItem { public: + /// Default constructor. + + /// @warning The default constructor sets the item + /// to an undefined value. GraphItem() {} + /// Copy constructor. + + /// Copy constructor. + /// + GraphItem(GraphItem const&) {} + /// Invalid constructor \& conversion. + + /// This constructor initializes the item to be invalid. + /// \sa Invalid for more details. GraphItem(Invalid) {} + /// Assign operator for nodes. - // We explicitely list these: - GraphItem(GraphItem const&) {} + /// The nodes are assignable. + /// GraphItem& operator=(GraphItem const&) { return *this; } - + /// Equality operator. + + /// Two iterators are equal if and only if they represents the + /// same node in the graph or both are invalid. bool operator==(GraphItem) const { return false; } + /// Inequality operator. + + /// \sa operator==(const Node& n) + /// bool operator!=(GraphItem) const { return false; } // Technical requirement. Do we really need this? - bool operator<(GraphItem) const { return false; } + // bool operator<(GraphItem) const { return false; } + + + template + struct Constraints { + void constraints() { + _GraphItem i1; + _GraphItem i2 = i1; + _GraphItem i3 = INVALID; + + i1 = i2 = i3; + + bool b; + // b = (ia == ib) && (ia != ib) && (ia < ib); + b = (ia == ib) && (ia != ib); + b = (ia == INVALID) && (ib != INVALID); + } + + const _GraphItem &ia; + const _GraphItem &ib; + }; }; - - template - struct GraphItemConcept { - void constraints() { - GI i1; - GI i2 = i1; - GI i3 = INVALID; - - i1 = i2 = i3; - - bool b; - b = (ia == ib) && (ia != ib) && (ia < ib); - b = (ia == INVALID) && (ib != INVALID); - } - - const GI &ia; - const GI &ib; - }; - - - template - struct GraphIteratorConcept { - void constraints() { - function_requires< GraphItemConcept >(); - Iter it1(g); - - /// \todo Do we need NodeIt(Node) kind of constructor? - // Iter it2(bj); - Iter it2; - - it2 = ++it1; - ++it2 = it1; - ++(++it1); - /// \bug This should be: is_base_and_derived - BaseItem bi = it1; - bi = it2; - } - - BaseItem bj; - Graph g; - }; - - template - struct GraphIncIteratorConcept { - typedef typename Graph::Node Node; - typedef typename Graph::Edge Edge; - void constraints() { - function_requires< GraphItemConcept >(); - Iter it1(graph, node); - /// \todo Do we need OutEdgeIt(Edge) kind of constructor? - // Iter it2(edge); - Iter it2; - - it2 = ++it1; - ++it2 = it1; - ++(++it1); - Edge e = it1; - e = it2; - } - - Edge edge; - Node node; - Graph graph; - }; - - - /// An empty base graph class. /// This class provides the minimal set of features needed for a graph @@ -139,108 +113,13 @@ /// This class represents the Nodes of the graph. /// - class Node { - public: - - /// Default constructor. - - /// @warning The default constructor sets the iterator - /// to an undefined value. - - Node() {} - /// Copy constructor. - - /// Copy constructor. - /// - Node(const Node&) {} - - /// Invalid constructor \& conversion. - - /// This constructor initializes the iterator to be invalid. - /// \sa Invalid for more details. - Node(Invalid) {} - - - /// Assign operator for nodes. - - /// The nodes are assignable. - /// - Node& operator=(const Node&) { return *this;} - - /// Equality operator. - - /// Two iterators are equal if and only if they represents the - /// same node in the graph or both are invalid. - bool operator==(const Node&) const { return true;} - - - /// Inequality operator. - - /// \sa operator==(const Node& n) - /// - bool operator!=(const Node&) const { return true;} - - /// Comparison operator. - - /// This is a strict ordering between the nodes. - /// - /// This ordering can be different from the iterating order of nodes. - /// \todo Possibly we don't need it. - bool operator<(const Node&) const { return true;} - }; + typedef GraphItem<'n'> Node; /// Edge class of the graph. /// This class represents the Edges of the graph. /// - class Edge { - public: - - /// Default constructor. - - /// @warning The default constructor sets the iterator - /// to an undefined value. - - Edge() {} - /// Copy constructor. - - /// Copy constructor. - /// - Edge(const Edge&) {} - - /// Invalid constructor \& conversion. - - /// This constructor initializes the iterator to be invalid. - /// \sa Invalid for more details. - Edge(Invalid) {} - - /// Assign operator for edges. - - /// The edges are assignable. - /// - Edge& operator=(const Edge&) { return *this;} - - /// Equality operator. - - /// Two iterators are equal if and only if they represents the - /// same edge in the graph or both are invalid. - bool operator==(const Edge&) const { return true;} - - - /// Inequality operator. - - /// \sa operator==(const Edge& n) - /// - bool operator!=(const Edge&) const { return true;} - - /// Comparison operator. - - /// This is a strict ordering between the edges. - /// - /// This ordering can be different from the iterating order of edges. - /// \todo Possibly we don't need it. - bool operator<(const Edge&) const { return true;} - }; + typedef GraphItem<'e'> Edge; ///Gives back the target node of an edge. @@ -253,31 +132,26 @@ ///Gives back the source node of an edge. /// Node source(const Edge&) const { return INVALID;} - }; - /// Concept check structure for BaseGraph. - - /// Concept check structure for BaseGraph. - /// - - template - struct BaseGraphComponentConcept { - typedef typename Graph::Node Node; - typedef typename Graph::Edge Edge; + template + struct Constraints { + typedef typename _Graph::Node Node; + typedef typename _Graph::Edge Edge; - void constraints() { - function_requires< GraphItemConcept >(); - function_requires< GraphItemConcept >(); - { - Node n; - Edge e; - n = graph.source(e); - n = graph.target(e); - } - } + void constraints() { + checkConcept, Node>(); + checkConcept, Edge>(); + { + Node n; + Edge e; + n = graph.source(e); + n = graph.target(e); + } + } - const Graph& graph; + const _Graph& graph; + }; }; /// An empty iterable base graph class. @@ -340,39 +214,35 @@ /// Gives back the next of the Edges start from the given Node. /// void nextOut(Edge&) const {} - }; - /// Concept check structure for IterableBaseGraph. + template + struct Constraints { + + void constraints() { + checkConcept< BaseGraphComponent, _Graph >(); + typename _Graph::Node node; + typename _Graph::Edge edge; + { + graph.first(node); + graph.next(node); + } + { + graph.first(edge); + graph.next(edge); + } + { + graph.firstIn(edge, node); + graph.nextIn(edge); + } + { + graph.firstOut(edge, node); + graph.nextOut(edge); + } + } - /// Concept check structure for IterableBaseGraph. - /// - template - struct BaseIterableGraphComponentConcept { - - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node; - typename Graph::Edge edge; - { - graph.first(node); - graph.next(node); - } - { - graph.first(edge); - graph.next(edge); - } - { - graph.firstIn(edge, node); - graph.nextIn(edge); - } - { - graph.firstOut(edge, node); - graph.nextOut(edge); - } - } - - const Graph& graph; + const _Graph& graph; + }; }; /// An empty idable base graph class. @@ -381,7 +251,6 @@ /// core id functions for the graph structure. /// The most of the base graphs should be conform to this concept. /// The id's are unique and immutable. - class IDableGraphComponent : virtual public BaseGraphComponent { public: @@ -399,27 +268,22 @@ /// Gives back an unique integer id for the Edge. /// int id(const Edge&) const { return -1;} - }; + template + struct Constraints { - /// Concept check structure for IdableBaseGraph. + void constraints() { + checkConcept< BaseGraphComponent, _Graph >(); + typename _Graph::Node node; + int nid = graph.id(node); + nid = graph.id(node); + typename _Graph::Edge edge; + int eid = graph.id(edge); + eid = graph.id(edge); + } - /// Concept check structure for IdableBaseGraph. - /// - template - struct IDableGraphComponentConcept { - - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node; - int nid = graph.id(node); - nid = graph.id(node); - typename Graph::Edge edge; - int eid = graph.id(edge); - eid = graph.id(edge); - } - - const Graph& graph; + const _Graph& graph; + }; }; @@ -443,24 +307,20 @@ /// Gives back an integer greater or equal to the maximum Edge id. /// int maxId(Edge = INVALID) const { return -1;} - }; - /// Concept check structure for MaxIdableBaseGraph. + template + struct Constraints { - /// Concept check structure for MaxIdableBaseGraph. - /// - template - struct MaxIDableGraphComponentConcept { - - void constraints() { - function_requires< BaseGraphComponentConcept >(); - int nid = graph.maxId(typename Graph::Node()); - ignore_unused_variable_warning(nid); - int eid = graph.maxId(typename Graph::Edge()); - ignore_unused_variable_warning(eid); - } - - const Graph& graph; + void constraints() { + checkConcept(); + int nid = graph.maxId(typename _Graph::Node()); + ignore_unused_variable_warning(nid); + int eid = graph.maxId(typename _Graph::Edge()); + ignore_unused_variable_warning(eid); + } + + const _Graph& graph; + }; }; /// An empty extendable base graph class. @@ -490,23 +350,18 @@ return INVALID; } - }; + template + struct Constraints { + void constraints() { + checkConcept(); + typename _Graph::Node node_a, node_b; + node_a = graph.addNode(); + typename _Graph::Edge edge; + edge = graph.addEdge(node_a, node_b); + } - /// Concept check structure for ExtendableBaseGraph. - - /// Concept check structure for ExtendableBaseGraph. - /// - template - struct BaseExtendableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node_a, node_b; - node_a = graph.addNode(); - typename Graph::Edge edge; - edge = graph.addEdge(node_a, node_b); - } - - Graph& graph; + _Graph& graph; + }; }; /// An empty erasable base graph class. @@ -532,23 +387,18 @@ /// void erase(const Edge&) {} - }; + template + struct Constraints { + void constraints() { + checkConcept(); + typename _Graph::Node node; + graph.erase(node); + typename _Graph::Edge edge; + graph.erase(edge); + } - /// Concept check structure for ErasableBaseGraph. - - /// Concept check structure for ErasableBaseGraph. - /// - template - struct BaseErasableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node; - graph.erase(node); - typename Graph::Edge edge; - graph.erase(edge); - } - - Graph& graph; + _Graph& graph; + }; }; /// An empty clearable base graph class. @@ -564,25 +414,172 @@ /// Erase all the Nodes and Edges from the graph. /// void clear() {} + + template + struct Constraints { + void constraints() { + checkConcept< BaseGraphComponent, _Graph>(); + graph.clear(); + } + + _Graph& graph; + }; }; - /// Concept check function for ErasableBaseGraph. - /// Concept check function for ErasableBaseGraph. + /// Skeleton class for graph NodeIt and EdgeIt + + /// Skeleton class for graph NodeIt and EdgeIt. /// - template - struct BaseClearableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - graph.clear(); - } + template + class GraphIterator : public _Item { + public: + /// \todo Don't we need the Item type as typedef? - Graph& graph; + /// Default constructor. + + /// @warning The default constructor sets the iterator + /// to an undefined value. + GraphIterator() {} + /// Copy constructor. + + /// Copy constructor. + /// + GraphIterator(GraphIterator const&) {} + /// Sets the iterator to the first item. + + /// Sets the iterator to the first item of \c the graph. + /// + explicit GraphIterator(const _Graph&) {} + /// Invalid constructor \& conversion. + + /// This constructor initializes the item to be invalid. + /// \sa Invalid for more details. + GraphIterator(Invalid) {} + /// Assign operator for items. + + /// The items are assignable. + /// + GraphIterator& operator=(GraphIterator const&) { return *this; } + /// Next item. + + /// Assign the iterator to the next item. + /// + GraphIterator& operator++() { return *this; } + // Node operator*() const { return INVALID; } + /// Equality operator + + /// Two iterators are equal if and only if they point to the + /// same object or both are invalid. + bool operator==(const GraphIterator&) const { return true;} + /// Inequality operator + + /// \sa operator==(Node n) + /// + bool operator!=(const GraphIterator&) const { return true;} + + template + struct Constraints { + void constraints() { + // checkConcept< Item, _GraphIterator >(); + _GraphIterator it1(g); + + /// \todo Do we need NodeIt(Node) kind of constructor? + // _GraphIterator it2(bj); + _GraphIterator it2; + + it2 = ++it1; + ++it2 = it1; + ++(++it1); + /// \bug This should be: is_base_and_derived + _Item bi = it1; + bi = it2; + } + _Graph& g; + }; }; + /// Skeleton class for graph InEdgeIt and OutEdgeIt - class IterableGraphComponent : - virtual public BaseIterableGraphComponent { + /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same + /// base class, the _selector is a additional template parameter. For + /// InEdgeIt you should instantiate it with character 'i' and for + /// OutEdgeIt with 'o'. + /// \todo check the name of the concept GraphIncEdgeIterator + template + class GraphIncEdgeIterator : public _Graph::Edge { + public: + /// Default constructor. + + /// @warning The default constructor sets the iterator + /// to an undefined value. + GraphIncEdgeIterator() {} + /// Copy constructor. + + /// Copy constructor. + /// + GraphIncEdgeIterator(GraphIncEdgeIterator const&) {} + /// Sets the iterator to the first edge incoming into or outgoing from the node. + + /// Sets the iterator to the first edge incoming into or outgoing from the node. + /// + explicit GraphIncEdgeIterator(const _Graph&, const typename _Graph::Node&) {} + /// Invalid constructor \& conversion. + + /// This constructor initializes the item to be invalid. + /// \sa Invalid for more details. + GraphIncEdgeIterator(Invalid) {} + /// Assign operator for nodes. + + /// The nodes are assignable. + /// + GraphIncEdgeIterator& operator=(GraphIncEdgeIterator const&) { return *this; } + /// Next edge. + + /// Assign the iterator to the next node. + /// + GraphIncEdgeIterator& operator++() { return *this; } + // Node operator*() const { return INVALID; } + /// Equality operator + + /// Two iterators are equal if and only if they point to the + /// same object or both are invalid. + bool operator==(const GraphIncEdgeIterator&) const { return true;} + /// Inequality operator + + /// \sa operator==(Node n) + /// + bool operator!=(const GraphIncEdgeIterator&) const { return true;} + + template + struct Constraints { + typedef typename _Graph::Node Node; + typedef typename _Graph::Edge Edge; + void constraints() { + checkConcept, _GraphIncEdgeIterator>(); + _GraphIncEdgeIterator it1(graph, node); + /// \todo Do we need OutEdgeIt(Edge) kind of constructor? + // _GraphIncEdgeIterator it2(edge); + _GraphIncEdgeIterator it2; + + it2 = ++it1; + ++it2 = it1; + ++(++it1); + Edge e = it1; + e = it2; + } + + Edge& edge; + Node& node; + _Graph& graph; + }; + }; + /// An empty iterable base graph class. + + /// This class provides beside the core graph features + /// iterator based iterable interface for the graph structure. + /// This concept is part of the StaticGraphConcept. + class IterableGraphComponent : virtual public BaseGraphComponent { public: @@ -591,84 +588,80 @@ typedef BaseGraphComponent::Node Node; typedef BaseGraphComponent::Edge Edge; - class NodeIt : public Node { - public: - NodeIt() {} - NodeIt(Invalid) {} - // explicit NodeIt(Node) {} - explicit NodeIt(const Graph&) {} + /// This iterator goes through each node. - NodeIt& operator++() { return *this; } - // Node operator*() const { return INVALID; } + /// This iterator goes through each node. + /// + typedef GraphIterator NodeIt; + /// This iterator goes through each node. - bool operator==(const NodeIt&) const { return true;} - bool operator!=(const NodeIt&) const { return true;} - }; + /// This iterator goes through each node. + /// + typedef GraphIterator EdgeIt; + /// This iterator goes trough the incoming edges of a node. - class EdgeIt : public Edge { - public: - EdgeIt() {} - EdgeIt(Invalid) {} - // explicit EdgeIt(Edge) {} - explicit EdgeIt(const Graph&) {} + /// This iterator goes trough the \e inccoming edges of a certain node + /// of a graph. + typedef GraphIncEdgeIterator InEdgeIt; + /// This iterator goes trough the outgoing edges of a node. - EdgeIt& operator++() { return *this; } - // Edge operator*() const { return INVALID; } + /// This iterator goes trough the \e outgoing edges of a certain node + /// of a graph. + typedef GraphIncEdgeIterator OutEdgeIt; + }; + + template + struct Constraints { + void constraints() { + checkConcept< BaseGraphComponent, _Graph>(); - bool operator==(const EdgeIt&) const { return true;} - bool operator!=(const EdgeIt&) const { return true;} - }; + checkConcept, typename _Graph::EdgeIt >(); + checkConcept, typename _Graph::NodeIt >(); + checkConcept, typename _Graph::InEdgeIt >(); + checkConcept, typename _Graph::OutEdgeIt >(); + } + }; - class InEdgeIt : public Edge { - public: - InEdgeIt() {} - InEdgeIt(Invalid) {} - // explicit InEdgeIt(Edge) {} - explicit InEdgeIt(const Graph&, const Node&) {} - InEdgeIt& operator++() { return *this; } - // Edge operator*() const { return INVALID; } + template + class GraphMap : public ReadWriteMap { + protected: + GraphMap() {} + public: + explicit GraphMap(const Graph&) {} + GraphMap(const Graph&, const _Value&) {} + GraphMap(const GraphMap&) {} + + GraphMap& operator=(const GraphMap&) { return *this;} - bool operator==(const InEdgeIt&) const { return true;} - bool operator!=(const InEdgeIt&) const { return true;} - }; + template + struct Constraints { + void constraints() { + checkConcept, _Map >(); + // Construction with a graph parameter + _Map a(g); + // Constructor with a graph and a default value parameter + _Map a2(g,t); + // Copy constructor. Do we need it? + _Map b=c; + // Copy operator. Do we need it? + a=b; - class OutEdgeIt : public Edge { - public: - OutEdgeIt() {} - OutEdgeIt(Invalid) {} - // explicit OutEdgeIt(Edge) {} - explicit OutEdgeIt(const Graph&, const Node&) {} + ignore_unused_variable_warning(a2); + } - OutEdgeIt& operator++() { return *this; } - // Edge operator*() const { return INVALID; } - - bool operator==(const OutEdgeIt&) const { return true;} - bool operator!=(const OutEdgeIt&) const { return true;} + const _Map &c; + const Graph &g; + const typename GraphMap::Value &t; }; }; - - template - struct IterableGraphComponentConcept { - void constraints() { - function_requires< BaseIterableGraphComponentConcept >(); - typedef typename Graph::Node Node; - typedef typename Graph::NodeIt NodeIt; - typedef typename Graph::Edge Edge; - typedef typename Graph::EdgeIt EdgeIt; - typedef typename Graph::InEdgeIt InEdgeIt; - typedef typename Graph::OutEdgeIt OutEdgeIt; + /// An empty mappable base graph class. - function_requires< GraphIteratorConcept >(); - function_requires< GraphIteratorConcept >(); - function_requires< GraphIncIteratorConcept >(); - function_requires< GraphIncIteratorConcept >(); - } - }; - - + /// This class provides beside the core graph features + /// map interface for the graph structure. + /// This concept is part of the StaticGraphConcept. class MappableGraphComponent : virtual public BaseGraphComponent { public: @@ -677,65 +670,78 @@ typedef BaseGraphComponent::Node Node; typedef BaseGraphComponent::Edge Edge; + /// ReadWrite map of the nodes. + + /// ReadWrite map of the nodes. + /// template - class NodeMap : public ReferenceMap { + class NodeMap : public GraphMap { + private: + NodeMap(); public: - NodeMap(const Graph&) {} + // \todo call the right parent class constructor + explicit NodeMap(const Graph&) {} NodeMap(const Graph&, const _Value&) {} NodeMap(const NodeMap&) {} NodeMap& operator=(const NodeMap&) { return *this;} - + }; + /// ReadWrite map of the edges. + + /// ReadWrite map of the edges. + /// template - class EdgeMap : public ReferenceMap { + class EdgeMap : public GraphMap { + private: + EdgeMap(); public: - EdgeMap(const Graph&) {} + // \todo call the right parent class constructor + explicit EdgeMap(const Graph&) {} EdgeMap(const Graph&, const _Value&) {} EdgeMap(const EdgeMap&) {} EdgeMap& operator=(const EdgeMap&) { return *this;} - + }; - }; + template + struct Constraints { - template - struct MappableGraphComponentConcept { + struct Type { + int value; + Type() : value(0) {} + Type(int _v) : value(_v) {} + }; - struct Type { - int value; - Type() : value(0) {} - Type(int _v) : value(_v) {} + void constraints() { + checkConcept(); + { // int map test + typedef typename _Graph::template NodeMap IntNodeMap; + checkConcept, IntNodeMap >(); + } { // bool map test + typedef typename _Graph::template NodeMap BoolNodeMap; + checkConcept, BoolNodeMap >(); + } { // Type map test + typedef typename _Graph::template NodeMap TypeNodeMap; + checkConcept, TypeNodeMap >(); + } + + { // int map test + typedef typename _Graph::template EdgeMap IntEdgeMap; + checkConcept, IntEdgeMap >(); + } { // bool map test + typedef typename _Graph::template EdgeMap BoolEdgeMap; + checkConcept, BoolEdgeMap >(); + } { // Type map test + typedef typename _Graph::template EdgeMap TypeEdgeMap; + checkConcept, TypeEdgeMap >(); + } + } + + _Graph& graph; }; - - void constraints() { - function_requires< BaseGraphComponentConcept >(); - { // int map test - typedef typename Graph::template NodeMap IntNodeMap; - function_requires >(); - } { // bool map test - typedef typename Graph::template NodeMap BoolNodeMap; - function_requires >(); - } { // Type map test - typedef typename Graph::template NodeMap TypeNodeMap; - function_requires >(); - } - - { // int map test - typedef typename Graph::template EdgeMap IntEdgeMap; - function_requires >(); - } { // bool map test - typedef typename Graph::template EdgeMap BoolEdgeMap; - function_requires >(); - } { // Type map test - typedef typename Graph::template EdgeMap TypeEdgeMap; - function_requires >(); - } - } - - Graph& graph; }; @@ -755,20 +761,18 @@ return INVALID; } + template + struct Constraints { + void constraints() { + checkConcept(); + typename _Graph::Node node_a, node_b; + node_a = graph.addNode(); + typename _Graph::Edge edge; + edge = graph.addEdge(node_a, node_b); + } + _Graph& graph; + }; }; - - template - struct ExtendableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node_a, node_b; - node_a = graph.addNode(); - typename Graph::Edge edge; - edge = graph.addEdge(node_a, node_b); - } - Graph& graph; - }; - class ErasableGraphComponent : virtual public BaseGraphComponent { public: @@ -780,19 +784,18 @@ void erase(const Node&) {} void erase(const Edge&) {} - }; + template + struct Constraints { + void constraints() { + checkConcept(); + typename _Graph::Node node; + graph.erase(node); + typename _Graph::Edge edge; + graph.erase(edge); + } - template - struct ErasableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - typename Graph::Node node; - graph.erase(node); - typename Graph::Edge edge; - graph.erase(edge); - } - - Graph& graph; + _Graph& graph; + }; }; class ClearableGraphComponent : virtual public BaseGraphComponent { @@ -805,15 +808,15 @@ void clear() {} - }; - template - struct ClearableGraphComponentConcept { - void constraints() { - function_requires< BaseGraphComponentConcept >(); - graph.clear(); - } - Graph& graph; + template + struct ClearableGraphComponentConcept { + void constraints() { + checkConcept< BaseGraphComponent, _Graph >(); + graph.clear(); + } + _Graph& graph; + }; }; }