[Lemon-commits] [lemon_svn] deba: r1281 - in hugo/branches/graph_factory/src: lemon/skeletons test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:21 CET 2006
Author: deba
Date: Thu Oct 7 14:43:25 2004
New Revision: 1281
Modified:
hugo/branches/graph_factory/src/lemon/skeletons/base_graph.h
hugo/branches/graph_factory/src/test/base_graph_test.cc
Log:
Struct based checks in BaseGraphs
Modified: hugo/branches/graph_factory/src/lemon/skeletons/base_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/skeletons/base_graph.h (original)
+++ hugo/branches/graph_factory/src/lemon/skeletons/base_graph.h Thu Oct 7 14:43:25 2004
@@ -1,4 +1,23 @@
-// -*- c++ -*-
+/* -*- C++ -*-
+ * src/lemon/skeletons/base_graph.h - Part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Combinatorial Optimization Research Group, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup skeletons
+///\file
+///\brief BaseGraph, IterableBaseGraph, IdableBaseGraph, MaxIdableBaseGraph
+/// ExtendableBaseGraph, ClearableBaseGraph, ErasableBaseGraph classes.
#ifndef LEMON_SKELETON_BASE_GRAPH_H
#define LEMON_SKELETON_BASE_GRAPH_H
@@ -8,108 +27,274 @@
namespace lemon {
namespace skeleton {
+
+
+ /// An empty base graph class.
+
+ /// This class provides the most minimal features of a graph structure.
+ /// All the graph concepts have to be conform to this base graph.
+
class BaseGraph {
public:
typedef BaseGraph Graph;
+
+ /// Node class of the graph.
+
+ /// 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) {}
- Node(const Graph&) {}
+
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&) { return true;}
+
+
+ /// Inequality operator.
+
+ /// \sa operator==(const Node& n)
+ ///
bool operator!=(const Node&) { 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&) { return true;}
};
+ /// 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) {}
- Edge(const Graph&) {}
+
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&) { return true;}
+
+
+ /// Inequality operator.
+
+ /// \sa operator==(const Edge& n)
+ ///
bool operator!=(const Edge&) { 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&) { return true;}
};
+ ///Gives back the head node of an edge.
+
+ ///Gives back the head node of an edge.
+ ///
Node head(const Edge&) const { return INVALID;}
+
+ ///Gives back the tail node of an edge.
+
+ ///Gives back the tail node of an edge.
+ ///
Node tail(const Edge&) const { return INVALID;}
};
+ /// Concept check structure for BaseGraph.
+
+ /// Concept check structure for BaseGraph.
+ ///
+
template <typename Graph>
- void checkBaseGraph(Graph& graph) {
+ struct BaseGraphConcept {
typedef typename Graph::Node Node;
typedef typename Graph::Edge Edge;
- {
- Node ni;
- Node nj(ni);
- Node nk(INVALID);
- ni = nj;
- bool b; b = true;
- b = (ni == INVALID); b = (ni != INVALID);
- b = (ni==nj); b = (ni != nj); b=( ni < nj);
- }
- {
- Edge ei;
- Edge ej(ei);
- Edge ek(INVALID);
- ei = ej;
- bool b; b = true;
- b = (ei == INVALID); b = (ei != INVALID);
- b = (ei==ej); b = (ei != ej); b=( ei < ej);
- }
- {
- const Graph& cgraph = graph;
- Node n;
- Edge e;
- n = cgraph.tail(e);
- n = cgraph.head(e);
- }
- }
+
+ void constraints() {
+ {
+ Node ni;
+ Node nj(ni);
+ Node nk(INVALID);
+ ni = nj;
+ bool b; b = true;
+ b = (ni == INVALID); b = (ni != INVALID);
+ b = (ni==nj); b = (ni != nj); b=( ni < nj);
+ }
+ {
+ Edge ei;
+ Edge ej(ei);
+ Edge ek(INVALID);
+ ei = ej;
+ bool b; b = true;
+ b = (ei == INVALID); b = (ei != INVALID);
+ b = (ei==ej); b = (ei != ej); b=( ei < ej);
+ }
+ {
+ const Graph& const_graph = graph;
+ Node n;
+ Edge e;
+ n = const_graph.tail(e);
+ n = const_graph.head(e);
+ }
+ }
+
+ Graph graph;
+ };
+
+ /// An empty iterable base graph class.
+
+ /// This class provides beside the core graph features
+ /// core iterable interface for the graph structure.
+ /// The most of the base graphs should be conform to this concept.
class IterableBaseGraph : public BaseGraph {
public:
typedef BaseGraph::Node Node;
typedef BaseGraph::Edge Edge;
+
+ /// Gives back the first Node in the iterating order.
+ /// Gives back the first Node in the iterating order.
+ ///
void first(Node&) const {}
+
+ /// Gives back the next Node in the iterating order.
+
+ /// Gives back the next Node in the iterating order.
+ ///
void next(Node&) const {}
+ /// Gives back the first Edge in the iterating order.
+
+ /// Gives back the first Edge in the iterating order.
+ ///
void first(Edge&) const {}
+ /// Gives back the next Edge in the iterating order.
+
+ /// Gives back the next Edge in the iterating order.
+ ///
void next(Edge&) const {}
+ /// Gives back the first of the Edges point to the given Node.
+
+ /// Gives back the first of the Edges point to the given Node.
+ ///
void firstInEdge(Edge&, const Node&) const {}
+
+ /// Gives back the next of the Edges points to the given Node.
+
+
+ /// Gives back the next of the Edges points to the given Node.
+ ///
void nextInEdge(Edge&) const {}
+ /// Gives back the first of the Edges start from the given Node.
+
+ /// Gives back the first of the Edges start from the given Node.
+ ///
void firstOutEdge(Edge&, const Node&) const {}
+
+ /// Gives back the next of the Edges start from the given Node.
+
+ /// Gives back the next of the Edges start from the given Node.
+ ///
void nextOutEdge(Edge&) const {}
};
+
+ /// Concept check structure for IterableBaseGraph.
+
+ /// Concept check structure for IterableBaseGraph.
+ ///
template <typename Graph>
- void checkIterableBaseGraph(Graph& graph) {
- const Graph& cgraph = graph;
- typename Graph::Node node;
- cgraph.first(node);
- cgraph.next(node);
- typename Graph::Edge edge;
- cgraph.first(edge);
- cgraph.next(edge);
- cgraph.firstInEdge(edge, node);
- cgraph.nextInEdge(edge);
- cgraph.firstOutEdge(edge, node);
- cgraph.nextOutEdge(edge);
- }
+ struct IterableBaseGraphConcept {
+
+ void constraints() {
+ const Graph& const_graph = graph;
+ typename Graph::Node node;
+ typename Graph::Edge edge;
+ {
+ const_graph.first(node);
+ const_graph.next(node);
+ }
+ {
+ const_graph.first(edge);
+ const_graph.next(edge);
+ }
+ {
+ const_graph.firstInEdge(edge, node);
+ const_graph.nextInEdge(edge);
+ }
+ {
+ const_graph.firstOutEdge(edge, node);
+ const_graph.nextOutEdge(edge);
+ }
+ }
+
+ Graph& graph;
+ };
+
+ /// An empty idable base graph class.
+
+ /// This class provides beside the core graph features
+ /// 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 IdableBaseGraph : public BaseGraph {
public:
@@ -117,85 +302,190 @@
typedef BaseGraph::Node Node;
typedef BaseGraph::Edge Edge;
+ /// Gives back an unique integer id for the Node.
+
+ /// Gives back an unique integer id for the Node.
+ ///
int id(const Node&) const { return -1;}
+
+ /// Gives back an unique integer id for the Edge.
+
+ /// Gives back an unique integer id for the Edge.
+ ///
int id(const Edge&) const { return -1;}
};
+
+ /// Concept check structure for IdableBaseGraph.
+
+ /// Concept check structure for IdableBaseGraph.
+ ///
template <typename Graph>
- void checkIdableBaseGraph(Graph& graph) {
- const Graph& cgraph = graph;
- typename Graph::Node node;
- int nid = cgraph.id(node);
- typename Graph::Edge edge;
- int eid = cgraph.id(edge);
- }
+ struct IdableBaseGraphConcept {
+
+ void constraints() {
+ const Graph& const_graph = graph;
+ typename Graph::Node node;
+ int nid = const_graph.id(node);
+ typename Graph::Edge edge;
+ int eid = const_graph.id(edge);
+ }
+ Graph& graph;
+ };
+
+
+ /// An empty max-idable base graph class.
+
+ /// This class provides beside the core graph features
+ /// core max 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 MaxIdableBaseGraph : public BaseGraph {
public:
+ /// Gives back an integer greater or equal to the maximum Node id.
+
+ /// Gives back an integer greater or equal to the maximum Node id.
+ ///
int maxEdgeId() const { return -1;}
+
+ /// Gives back an integer greater or equal to the maximum Edge id.
+
+ /// Gives back an integer greater or equal to the maximum Edge id.
+ ///
int maxNodeId() const { return -1;}
};
+ /// Concept check structure for MaxIdableBaseGraph.
+
+ /// Concept check structure for MaxIdableBaseGraph.
+ ///
template <typename Graph>
- void checkMaxIdableBaseGraph(Graph& graph) {
- const Graph& cgraph = graph;
- int nid = cgraph.maxEdgeId();
- int eid = cgraph.maxNodeId();
- }
+ struct MaxIdableBaseGraphConcept {
+
+ void constraints() {
+ const Graph& const_graph = graph;
+ int nid = const_graph.maxEdgeId();
+ int eid = const_graph.maxNodeId();
+ }
+ Graph& graph;
+ };
+
+ /// An empty extendable base graph class.
+
+ /// This class provides beside the core graph features
+ /// core graph extend interface for the graph structure.
+ /// The most of the base graphs should be conform to this concept.
class ExtendableBaseGraph : public BaseGraph {
public:
typedef BaseGraph::Node Node;
typedef BaseGraph::Edge Edge;
+ /// Adds a new Node to the graph.
+
+ /// Adds a new Node to the graph.
+ ///
Node addNode() {
return INVALID;
}
+ /// Adds a new Edge connects the two Nodes to the graph.
+
+ /// Adds a new Edge connects the two Nodes to the graph.
+ ///
Edge addEdge(const Node& from, const Node& to) {
return INVALID;
}
};
+ /// Concept check structure for ExtendableBaseGraph.
+
+ /// Concept check structure for ExtendableBaseGraph.
+ ///
template <typename Graph>
- void checkExtendableBaseGraph(Graph& graph) {
- typename Graph::Node node_a, node_b;
- node_a = graph.addNode();
- typename Graph::Edge edge;
- edge = graph.addEdge(node_a, node_b);
- }
+ struct ExtendableBaseGraphConcept {
+ void constraints() {
+ typename Graph::Node node_a, node_b;
+ node_a = graph.addNode();
+ typename Graph::Edge edge;
+ edge = graph.addEdge(node_a, node_b);
+ }
+ Graph& graph;
+ };
+
+ /// An empty erasable base graph class.
+
+ /// This class provides beside the core graph features
+ /// core erase functions for the graph structure.
+ /// The most of the base graphs should be conform to this concept.
class ErasableBaseGraph : public BaseGraph {
public:
typedef BaseGraph::Node Node;
typedef BaseGraph::Edge Edge;
+ /// Erase a Node from the graph.
+
+ /// Erase a Node from the graph. This function should not
+ /// erase edges connecting to the Node.
void erase(const Node&) {}
+
+ /// Erase an Edge from the graph.
+
+ /// Erase an Edge from the graph.
+ ///
void erase(const Edge&) {}
};
+ /// Concept check structure for ErasableBaseGraph.
+
+ /// Concept check structure for ErasableBaseGraph.
+ ///
template <typename Graph>
- void checkErasableBaseGraph(Graph& graph) {
- typename Graph::Node node;
- graph.erase(node);
- typename Graph::Edge edge;
- graph.erase(edge);
- }
+ struct ErasableBaseGraphConcept {
+ void constraints() {
+ typename Graph::Node node;
+ graph.erase(node);
+ typename Graph::Edge edge;
+ graph.erase(edge);
+ }
+
+ Graph& graph;
+ };
+ /// An empty clearable base graph class.
+
+ /// This class provides beside the core graph features
+ /// core clear functions for the graph structure.
+ /// The most of the base graphs should be conform to this concept.
class ClearableBaseGraph : public BaseGraph {
public:
+
+ /// Erase all the Nodes and Edges from the graph.
+
+ /// Erase all the Nodes and Edges from the graph.
+ ///
void clear() {}
};
+ /// Concept check function for ErasableBaseGraph.
+
+ /// Concept check function for ErasableBaseGraph.
+ ///
template <typename Graph>
- void checkClearableBaseGraph(Graph& graph) {
- graph.clear();
- }
+ struct ClearableBaseGraphConcept {
+ void constraints() {
+ graph.clear();
+ }
+
+ Graph& graph;
+ };
}
}
Modified: hugo/branches/graph_factory/src/test/base_graph_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/base_graph_test.cc (original)
+++ hugo/branches/graph_factory/src/test/base_graph_test.cc Thu Oct 7 14:43:25 2004
@@ -1,59 +1,50 @@
-// -*- c++ -*-
+/* -*- C++ -*-
+ * src/test/base_graph_test.h - Part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Combinatorial Optimization Research Group, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
#include <iostream>
+#include <lemon/concept_check.h>
+
#include <lemon/skeletons/base_graph.h>
#include <lemon/test_graph.h>
using namespace lemon;
-template void lemon::skeleton::checkBaseGraph
-<skeleton::BaseGraph>(skeleton::BaseGraph &);
-
-template void lemon::skeleton::checkIterableBaseGraph
-<skeleton::IterableBaseGraph>(skeleton::IterableBaseGraph &);
-
-template void lemon::skeleton::checkIdableBaseGraph
-<skeleton::IdableBaseGraph>(skeleton::IdableBaseGraph &);
-
-template void lemon::skeleton::checkMaxIdableBaseGraph
-<skeleton::MaxIdableBaseGraph>(skeleton::MaxIdableBaseGraph &);
-
-template void lemon::skeleton::checkExtendableBaseGraph
-<skeleton::ExtendableBaseGraph>(skeleton::ExtendableBaseGraph &);
-
-template void lemon::skeleton::checkClearableBaseGraph
-<skeleton::ClearableBaseGraph>(skeleton::ClearableBaseGraph &);
-
-template void lemon::skeleton::checkErasableBaseGraph
-<skeleton::ErasableBaseGraph>(skeleton::ErasableBaseGraph &);
-
+using namespace lemon::skeleton;
-template void lemon::skeleton::checkBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkIterableBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkIdableBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkMaxIdableBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkExtendableBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkClearableBaseGraph
-<TestGraphBase>(TestGraphBase &);
-
-template void lemon::skeleton::checkErasableBaseGraph
-<TestGraphBase>(TestGraphBase &);
+int main() {
+ function_requires<BaseGraphConcept<BaseGraph> >();
+ function_requires<IterableBaseGraphConcept<IterableBaseGraph> >();
+ function_requires<IdableBaseGraphConcept<IdableBaseGraph> >();
+ function_requires<MaxIdableBaseGraphConcept<MaxIdableBaseGraph> >();
+ function_requires<ExtendableBaseGraphConcept<ExtendableBaseGraph> >();
+ function_requires<ErasableBaseGraphConcept<ErasableBaseGraph> >();
+ function_requires<ClearableBaseGraphConcept<ClearableBaseGraph> >();
+
+ function_requires<BaseGraphConcept<TestGraphBase> >();
+ function_requires<IterableBaseGraphConcept<TestGraphBase> >();
+ function_requires<IdableBaseGraphConcept<TestGraphBase> >();
+ function_requires<MaxIdableBaseGraphConcept<TestGraphBase> >();
+ function_requires<ExtendableBaseGraphConcept<TestGraphBase> >();
+ function_requires<ErasableBaseGraphConcept<TestGraphBase> >();
+ function_requires<ClearableBaseGraphConcept<TestGraphBase> >();
-int main() {
///\file
///\todo map tests.
///\todo copy constr tests.
More information about the Lemon-commits
mailing list