# HG changeset patch # User deba # Date 1100381874 0 # Node ID ca95f8b5c9316a94e13b62fe5e82355c08954881 # Parent aa19ca32d9b05ef6adf36c6ca92b540fb62ffed6 XyzConcept moved to Xyz::Constraints use checkConcept in the next way: checkConcept(); checkConcept, PredMap>; diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept/graph.h --- a/src/lemon/concept/graph.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept/graph.h Sat Nov 13 21:37:54 2004 +0000 @@ -101,14 +101,6 @@ // /// // bool operator!=(Node) const { return true; } -// ///Comparison operator. - -// ///This is a strict ordering between the nodes. -// /// -// ///This ordering can be different from the order in which NodeIt -// ///goes through the nodes. -// ///\todo Possibly we don't need it. -// bool operator<(Node) const { return true; } // }; // /// This iterator goes through each node. @@ -188,14 +180,6 @@ // /// \sa operator==(Node n) // /// // bool operator!=(Edge) const { return true; } -// ///Comparison operator. - -// ///This is a strict ordering between the nodes. -// /// -// ///This ordering can be different from the order in which NodeIt -// ///goes through the nodes. -// ///\todo Possibly we don't need it. -// bool operator<(Edge) const { return true; } // }; // /// This iterator goes trough the outgoing edges of a node. @@ -339,30 +323,6 @@ // /// edge of the corresponding node. // EdgeIt& operator++() { return *this; } // }; - -// /// First node of the graph. - -// /// \retval i the first node. -// /// \return the first node. -// /// -// NodeIt& first(NodeIt& i) const { return i; } - -// /// The first incoming edge. - -// /// The first incoming edge. -// /// -// InEdgeIt& first(InEdgeIt &i, Node) const { return i; } -// /// The first outgoing edge. - -// /// The first outgoing edge. -// /// -// OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; } -// /// The first edge of the Graph. - -// /// The first edge of the Graph. -// /// -// EdgeIt& first(EdgeIt& i) const { return i; } - // ///Gives back the target node of an edge. // ///Gives back the target node of an edge. @@ -373,40 +333,15 @@ // ///Gives back the source node of an edge. // /// // Node source(Edge) const { return INVALID; } - -// ///Gives back the \e id of a node. - -// ///\warning Not all graph structures provide this feature. -// /// -// ///\todo Should each graph provide \c id? -// int id(const Node&) const { return 0; } -// ///Gives back the \e id of an edge. - -// ///\warning Not all graph structures provide this feature. -// /// -// ///\todo Should each graph provide \c id? -// int id(const Edge&) const { return 0; } - -// ///\e - -// ///\todo Should it be in the concept? -// /// -// int nodeNum() const { return 0; } -// ///\e - -// ///\todo Should it be in the concept? -// /// -// int edgeNum() const { return 0; } - - -// ///Reference map of the nodes to type \c T. +// /// Read write map of the nodes to type \c T. // /// \ingroup concept -// ///Reference map of the nodes to type \c T. +// /// ReadWrite map of the nodes to type \c T. // /// \sa Reference // /// \warning Making maps that can handle bool type (NodeMap) // /// needs some extra attention! -// template class NodeMap : public ReferenceMap< Node, T > +// template +// class NodeMap : public ReadWriteMap< Node, T > // { // public: @@ -416,21 +351,21 @@ // NodeMap(const StaticGraph&, T) { } // ///Copy constructor -// template NodeMap(const NodeMap&) { } +// NodeMap(const NodeMap&) { } // ///Assignment operator -// template NodeMap& operator=(const NodeMap&) -// { return *this; } +// NodeMap& operator=(const NodeMap&) { return *this; } +// // \todo fix this concept // }; -// ///Reference map of the edges to type \c T. +// /// Read write map of the edges to type \c T. // /// \ingroup concept // ///Reference map of the edges to type \c T. // /// \sa Reference // /// \warning Making maps that can handle bool type (EdgeMap) // /// needs some extra attention! -// template class EdgeMap -// : public ReferenceMap +// template +// class EdgeMap : public ReadWriteMap // { // public: @@ -438,213 +373,14 @@ // EdgeMap(const StaticGraph&) { } // ///\e // EdgeMap(const StaticGraph&, T) { } - // ///Copy constructor -// template EdgeMap(const EdgeMap&) { } +// EdgeMap(const EdgeMap&) { } // ///Assignment operator -// template EdgeMap &operator=(const EdgeMap&) -// { return *this; } +// EdgeMap& operator=(const EdgeMap&) { return *this; } +// // \todo fix this concept // }; // }; -// struct DummyType { -// int value; -// DummyType() {} -// DummyType(int p) : value(p) {} -// DummyType& operator=(int p) { value = p; return *this;} -// }; - -// ///\brief Checks whether \c G meets the -// ///\ref lemon::concept::StaticGraph "StaticGraph" concept -// template void checkCompileStaticGraph(Graph &G) -// { -// 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; - -// { -// Node i; Node j(i); Node k(INVALID); -// i=j; -// bool b; b=true; -// b=(i==INVALID); b=(i!=INVALID); -// b=(i==j); b=(i!=j); b=(iNodeIt conversion -// NodeIt ni(G,n); -// } -// { -// Edge i; Edge j(i); Edge k(INVALID); -// i=j; -// bool b; b=true; -// b=(i==INVALID); b=(i!=INVALID); -// b=(i==j); b=(i!=j); b=(iEdgeIt conversion -// EdgeIt ei(G,e); -// } -// { -// Node n; -// InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); -// i=j; -// j=G.first(i,n); -// j=++i; -// bool b; b=true; -// b=(i==INVALID); b=(i!=INVALID); -// Edge e(i); -// e=i; -// b=(i==j); b=(i!=j); b=(iInEdgeIt conversion -// InEdgeIt ei(G,e); -// } -// { -// Node n; -// OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); -// i=j; -// j=G.first(i,n); -// j=++i; -// bool b; b=true; -// b=(i==INVALID); b=(i!=INVALID); -// Edge e(i); -// e=i; -// b=(i==j); b=(i!=j); b=(iOutEdgeIt conversion -// OutEdgeIt ei(G,e); -// } -// { -// Node n,m; -// n=m=INVALID; -// Edge e; -// e=INVALID; -// n=G.source(e); -// n=G.target(e); -// } -// // id tests -// { Node n; int i=G.id(n); i=i; } -// { Edge e; int i=G.id(e); i=i; } -// //NodeMap tests -// { -// Node k; -// typename Graph::template NodeMap m(G); -// //Const map -// typename Graph::template NodeMap const &cm = m; -// //Inicialize with default value -// typename Graph::template NodeMap mdef(G,12); -// //Copy -// typename Graph::template NodeMap mm(cm); -// //Copy from another type -// typename Graph::template NodeMap dm(cm); -// //Copy to more complex type -// typename Graph::template NodeMap em(cm); -// int v; -// v=m[k]; m[k]=v; m.set(k,v); -// v=cm[k]; - -// m=cm; -// dm=cm; //Copy from another type -// em=cm; //Copy to more complex type -// { -// //Check the typedef's -// typename Graph::template NodeMap::Value val; -// val=1; -// typename Graph::template NodeMap::Key key; -// key = typename Graph::NodeIt(G); -// } -// } -// { //bool NodeMap -// Node k; -// typename Graph::template NodeMap m(G); -// typename Graph::template NodeMap const &cm = m; //Const map -// //Inicialize with default value -// typename Graph::template NodeMap mdef(G,12); -// typename Graph::template NodeMap mm(cm); //Copy -// typename Graph::template NodeMap dm(cm); //Copy from another type -// bool v; -// v=m[k]; m[k]=v; m.set(k,v); -// v=cm[k]; - -// m=cm; -// dm=cm; //Copy from another type -// m=dm; //Copy to another type - -// { -// //Check the typedef's -// typename Graph::template NodeMap::Value val; -// val=true; -// typename Graph::template NodeMap::Key key; -// key= typename Graph::NodeIt(G); -// } -// } -// //EdgeMap tests -// { -// Edge k; -// typename Graph::template EdgeMap m(G); -// typename Graph::template EdgeMap const &cm = m; //Const map -// //Inicialize with default value -// typename Graph::template EdgeMap mdef(G,12); -// typename Graph::template EdgeMap mm(cm); //Copy -// typename Graph::template EdgeMap dm(cm);//Copy from another type -// int v; -// v=m[k]; m[k]=v; m.set(k,v); -// v=cm[k]; - -// m=cm; -// dm=cm; //Copy from another type -// { -// //Check the typedef's -// typename Graph::template EdgeMap::Value val; -// val=1; -// typename Graph::template EdgeMap::Key key; -// key= typename Graph::EdgeIt(G); -// } -// } -// { //bool EdgeMap -// Edge k; -// typename Graph::template EdgeMap m(G); -// typename Graph::template EdgeMap const &cm = m; //Const map -// //Inicialize with default value -// typename Graph::template EdgeMap mdef(G,12); -// typename Graph::template EdgeMap mm(cm); //Copy -// typename Graph::template EdgeMap dm(cm); //Copy from another type -// bool v; -// v=m[k]; m[k]=v; m.set(k,v); -// v=cm[k]; - -// m=cm; -// dm=cm; //Copy from another type -// m=dm; //Copy to another type -// { -// //Check the typedef's -// typename Graph::template EdgeMap::Value val; -// val=true; -// typename Graph::template EdgeMap::Key key; -// key= typename Graph::EdgeIt(G); -// } -// } -// } - // /// An empty non-static graph class. // /// This class provides everything that \ref StaticGraph @@ -665,10 +401,10 @@ // Node addNode() { return INVALID; } // ///Add a new edge to the graph. -// ///Add a new edge to the graph with source node \c t -// ///and target node \c h. +// ///Add a new edge to the graph with source node \c s +// ///and target node \c t. // ///\return the new edge. -// Edge addEdge(Node h, Node t) { return INVALID; } +// Edge addEdge(Node s, Node t) { return INVALID; } // /// Resets the graph. @@ -678,30 +414,6 @@ // void clear() { } // }; - -// ///\brief Checks whether \c G meets the -// ///\ref lemon::concept::ExtendableGraph "ExtendableGraph" concept -// template void checkCompileExtendableGraph(Graph &G) -// { -// checkCompileStaticGraph(G); - -// 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; - -// Node n,m; -// n=G.addNode(); -// m=G.addNode(); -// Edge e; -// e=G.addEdge(n,m); - -// // G.clear(); -// } - - // /// An empty erasable graph class. // /// This class is an extension of \ref ExtendableGraph. It also makes it @@ -725,43 +437,8 @@ // /// // void erase(Edge e) { } // }; + -// template void checkCompileGraphEraseEdge(Graph &G) -// { -// typename Graph::Edge e; -// G.erase(e); -// } - -// template void checkCompileGraphEraseNode(Graph &G) -// { -// typename Graph::Node n; -// G.erase(n); -// } - -// ///\brief Checks whether \c G meets the -// ///\ref lemon::concept::EresableGraph "EresableGraph" concept -// template void checkCompileErasableGraph(Graph &G) -// { -// checkCompileExtendableGraph(G); -// checkCompileGraphEraseNode(G); -// checkCompileGraphEraseEdge(G); -// } - -// ///Checks whether a graph has findEdge() member function. - -// ///\todo findEdge() might be a global function. -// /// -// template void checkCompileGraphFindEdge(Graph &G) -// { -// typedef typename Graph::NodeIt Node; -// typedef typename Graph::NodeIt NodeIt; - -// G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); -// G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); -// } - - - /************* New GraphBase stuff **************/ @@ -815,10 +492,10 @@ // a required...) template - class NodeMap : public GraphMap {}; + class NodeMap : public GraphMap {}; template - class EdgeMap : public GraphMap {}; + class EdgeMap : public GraphMap {}; }; @@ -833,14 +510,14 @@ public: typedef BaseGraphComponent::Node Node; typedef BaseGraphComponent::Edge Edge; - }; - template - struct StaticGraphConcept { - void constraints() { - function_requires >(); - function_requires >(); - } + template + struct Constraints { + void constraints() { + checkConcept(); + checkConcept(); + } + }; }; class ExtendableGraph @@ -849,15 +526,15 @@ public: typedef BaseGraphComponent::Node Node; typedef BaseGraphComponent::Edge Edge; - }; - template - struct ExtendableGraphConcept { - void constraints() { - function_requires >(); - function_requires >(); - function_requires >(); - } + template + struct Constraints { + void constraints() { + checkConcept(); + checkConcept(); + checkConcept(); + } + }; }; class ErasableGraph @@ -866,14 +543,14 @@ public: typedef BaseGraphComponent::Node Node; typedef BaseGraphComponent::Edge Edge; - }; - template - struct ErasableGraphConcept { - void constraints() { - function_requires >(); - function_requires >(); - } + template + struct Constraints { + void constraints() { + checkConcept(); + checkConcept(); + } + }; }; // @} 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; + }; }; } diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept/maps.h --- a/src/lemon/concept/maps.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept/maps.h Sat Nov 13 21:37:54 2004 +0000 @@ -40,11 +40,28 @@ /// Map's value type. (The type of objects associated with the keys). typedef T Value; + // \bug Value don't need to be default constructible. /// Returns the value associated with a key. - Value operator[](const Key &k) const {return Value();} + Value operator[](const Key &) const {return Value();} - ///Default constructor - ReadMap() {} + template + struct Constraints { + + void constraints() { + Value val = m[key]; + val = m[key]; + typename _ReadMap::Value own_val = m[own_key]; + own_val = m[own_key]; + + ignore_unused_variable_warning(val); + ignore_unused_variable_warning(own_val); + ignore_unused_variable_warning(key); + } + Key& key; + typename _ReadMap::Key& own_key; + _ReadMap& m; + }; + }; @@ -63,6 +80,26 @@ ///Default constructor WriteMap() {} + + template + struct Constraints { + void constraints() { + // No constraints for constructor. + m.set(key, val); + m.set(own_key, own_val); + ignore_unused_variable(key); + ignore_unused_variable(val); + ignore_unused_variable(own_key); + ignore_unused_variable(own_val); + } + + Value& val; + typename _WriteMap::Value own_val; + Key& key; + typename _WriteMap::Key& own_key; + WriteMap& m; + + }; }; ///Read/Writable map concept @@ -81,13 +118,18 @@ /// Sets the value associated with a key. void set(const Key &k,const Value &t) {} - ///Default constructor - ReadWriteMap() {} + template + struct Constraints { + void constraints() { + checkConcept, _ReadWriteMap >(); + checkConcept, _ReadWriteMap >(); + } + }; }; ///Dereferable map concept - template + template class ReferenceMap : public ReadWriteMap { public: @@ -95,13 +137,14 @@ typedef K Key; /// Map's value type. (The type of objects associated with the keys). typedef T Value; + /// Map's reference type. + typedef R Reference; + /// Map's const reference type. + typedef CR ConstReference; protected: Value tmp; public: - typedef Value& Reference; - /// Map's const reference type. - typedef const Value& ConstReference; ///Returns a reference to the value associated to a key. Reference operator[](const Key &i) { return tmp; } @@ -111,134 +154,32 @@ /// Sets the value associated with a key. void set(const Key &k,const Value &t) { operator[](k)=t; } - ///Default constructor - ReferenceMap() {} + // \todo rethink this concept + template + struct ReferenceMapConcept { + + void constraints() { + checkConcept(); + m[key] = val; + val = m[key]; + m[key] = ref; + ref = m[key]; + m[own_key] = own_val; + own_val = m[own_key]; + m[own_key] = own_ref; + own_ref = m[own_key]; + } + + typename _ReferenceMap::Key& own_key; + typename _ReferenceMap::Value& own_val; + typename _ReferenceMap::Reference& own_ref; + Key& key; + Value& val; + Reference& ref; + ReferenceMap& m; + }; }; - - template - class GraphMap : public ReadWriteMap { - // I really, really don't like the idea that every graph should have - // reference maps! --klao - - private: - // We state explicitly that graph maps have no default constructor? - GraphMap(); - - public: - explicit GraphMap(Graph const&) {} - // value for initializing - GraphMap(Graph const&, T) {} - - // this probably should be required: - GraphMap(GraphMap const&) {} - GraphMap& operator=(GraphMap const&) { return *this; } - - // but this is a absolute no-op! We should provide a more generic - // graph-map-copy operation. - // - // template - // GraphMap(GraphMap const&); - // - // template - // GraphMap& operator=(const GraphMap&); - }; - - - /**************** Concept-checking classes ****************/ - - template - struct ReadMapConcept { - typedef typename ReadMap::Key Key; - typedef typename ReadMap::Value Value; - - void constraints() { - // No constraints for constructor. - - // What are the requirement for the Value? - // CopyConstructible? Assignable? None of these? - Value v = m[k]; - v = m[k]; - - // FIXME: - ignore_unused_variable_warning(v); - } - - ReadMap m; - Key k; - }; - - template - struct WriteMapConcept { - typedef typename WriteMap::Key Key; - typedef typename WriteMap::Value Value; - - void constraints() { - // No constraints for constructor. - - m.set(k, v); - } - - WriteMap m; - Key k; - Value v; - }; - - template - struct ReadWriteMapConcept { - void constraints() { - function_requires< ReadMapConcept >(); - function_requires< WriteMapConcept >(); - } - }; - - template - struct ReferenceMapConcept { - typedef typename ReferenceMap::Key Key; - typedef typename ReferenceMap::Value Value; - typedef typename ReferenceMap::Reference Reference; - - // What for is this? - typedef typename ReferenceMap::ConstReference ConstReference; - - void constraints() { - function_requires< ReadWriteMapConcept >(); - - m[k] = v; - // Or should we require real reference? - // Like this: - // Value &vv = m[k]; - // ignore_unused_variable_warning(vv); - } - - ReferenceMap m; - Key k; - Value v; - }; - - /// \todo GraphMapConceptCheck - - template - struct GraphMapConcept { - void constraints() { - function_requires< ReadWriteMapConcept >(); - // Construction with a graph parameter - GraphMap a(g); - // Ctor with a graph and a default value parameter - GraphMap a2(g,t); - // Copy ctor. Do we need it? - GraphMap b=c; - // Copy operator. Do we need it? - a=b; - - ignore_unused_variable_warning(a2); - } - const GraphMap &c; - const Graph &g; - const typename GraphMap::Value &t; - }; - - // @} } //namespace concept diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept/undir_graph.h --- a/src/lemon/concept/undir_graph.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept/undir_graph.h Sat Nov 13 21:37:54 2004 +0000 @@ -38,9 +38,10 @@ typedef typename Graph::UndirEdge UndirEdge; typedef typename Graph::Edge Edge; typedef typename Graph::Node Node; + void constraints() { - function_requires< BaseIterableGraphComponentConcept >(); - function_requires< GraphItemConcept >(); + checkConcept(); + checkConcept, UndirEdge >(); /// \bug this should be base_and_derived: UndirEdge ue = e; @@ -60,14 +61,14 @@ template struct IterableUndirGraphConcept { void constraints() { - function_requires< BaseIterableUndirGraphConcept > (); - function_requires< IterableGraphComponentConcept > (); + /// \todo we don't need the iterable component should base iterable + // checkConcept< BaseIterableUndirGraph, Graph > (); + checkConcept< IterableGraphComponent, Graph > (); typedef typename Graph::UndirEdge UndirEdge; typedef typename Graph::UndirEdgeIt UndirEdgeIt; - function_requires< - GraphIteratorConcept >(); + checkConcept< GraphIterator, UndirEdgeIt >(); } }; diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept_check.h --- a/src/lemon/concept_check.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept_check.h Sat Nov 13 21:37:54 2004 +0000 @@ -39,6 +39,11 @@ #endif } + template + inline void checkConcept() { + function_requires >(); + } + #define BOOST_CLASS_REQUIRE(type_var, ns, concept) \ typedef void (ns::concept ::* func##type_var##concept)(); \ template \ diff -r aa19ca32d9b0 -r ca95f8b5c931 src/test/graph_test.cc --- a/src/test/graph_test.cc Sat Nov 13 17:47:44 2004 +0000 +++ b/src/test/graph_test.cc Sat Nov 13 21:37:54 2004 +0000 @@ -20,46 +20,46 @@ int main() { ///\file { // checking graph components - function_requires >(); + checkConcept(); - function_requires >(); + checkConcept(); - function_requires >(); - function_requires >(); + checkConcept(); + checkConcept(); - function_requires >(); - function_requires >(); - function_requires >(); + checkConcept(); + checkConcept(); + checkConcept(); - function_requires >(); + checkConcept(); - function_requires >(); + checkConcept(); - function_requires >(); - function_requires >(); - function_requires >(); + checkConcept(); + checkConcept(); + checkConcept(); } { // checking skeleton graphs - function_requires >(); - function_requires >(); - function_requires >(); + checkConcept(); + checkConcept(); + checkConcept(); } { // checking list graph - function_requires >(); + checkConcept(); checkGraph(); checkGraphNodeMap(); checkGraphEdgeMap(); } { // checking smart graph - function_requires >(); + checkConcept(); checkGraph(); checkGraphNodeMap(); checkGraphEdgeMap(); } { // checking full graph - function_requires >(); + checkConcept(); } std::cout << __FILE__ ": All tests passed.\n"; diff -r aa19ca32d9b0 -r ca95f8b5c931 src/test/graph_wrapper_test.cc --- a/src/test/graph_wrapper_test.cc Sat Nov 13 17:47:44 2004 +0000 +++ b/src/test/graph_wrapper_test.cc Sat Nov 13 21:37:54 2004 +0000 @@ -38,13 +38,11 @@ using namespace lemon::concept; -typedef SmartGraph Graph; - int main() { { - function_requires > >(); + checkConcept >(); // function_requires > >();