[Lemon-commits] [lemon_svn] deba: r1295 - in hugo/branches/graph_factory/src: lemon lemon/skeletons test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:26 CET 2006
Author: deba
Date: Thu Oct 21 00:01:42 2004
New Revision: 1295
Added:
hugo/branches/graph_factory/src/lemon/iterable_graph_extender.h
- copied, changed from r1286, /hugo/branches/graph_factory/src/lemon/graph_extender.h
Modified:
hugo/branches/graph_factory/src/lemon/alteration_registry.h
hugo/branches/graph_factory/src/lemon/clearable_graph_extender.h
hugo/branches/graph_factory/src/lemon/erasable_graph_extender.h
hugo/branches/graph_factory/src/lemon/extendable_graph_extender.h
hugo/branches/graph_factory/src/lemon/idmappable_graph_extender.h
hugo/branches/graph_factory/src/lemon/mappable_graph_extender.h
hugo/branches/graph_factory/src/lemon/skeletons/base_graph.h
hugo/branches/graph_factory/src/lemon/skeletons/extended_graph.h
hugo/branches/graph_factory/src/lemon/test_graph.h
hugo/branches/graph_factory/src/lemon/vector_map.h
hugo/branches/graph_factory/src/test/extended_graph_test.cc
hugo/branches/graph_factory/src/test/graph_test.h
Log:
under construction commit
working on new graph structure
Modified: hugo/branches/graph_factory/src/lemon/alteration_registry.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/alteration_registry.h (original)
+++ hugo/branches/graph_factory/src/lemon/alteration_registry.h Thu Oct 21 00:01:42 2004
@@ -18,6 +18,7 @@
#define LEMON_OBSERVER_REGISTRY_H
#include <vector>
+#include <algorithm>
///\ingroup graphmaps
///\file
@@ -49,12 +50,10 @@
///
/// \author Balazs Dezso
- template <typename G, typename I, typename IIt>
+ template <typename _Item>
class AlterationObserverRegistry {
public:
- typedef G Graph;
- typedef I Item;
- typedef IIt ItemIt;
+ typedef _Item Item;
/// ObserverBase is the base class of the dynamic maps.
@@ -69,12 +68,8 @@
/// observer.
class ObserverBase {
- public:
- typedef G Graph;
- typedef I Item;
- typedef IIt ItemIt;
-
- typedef AlterationObserverRegistry<Graph, Item, ItemIt> Registry;
+ protected:
+ typedef AlterationObserverRegistry<Item> Registry;
friend class Registry;
@@ -82,75 +77,40 @@
/// Default constructor for ObserverBase.
///
- ObserverBase() : graph(0), registry(0) {}
+ ObserverBase() : registry(0) {}
/// Constructor to register observer into an observer registry.
- /// It constrates an observer and then registers it into an observer registry.
- /// This calls also the build() member to notify the observer about it is registered.
- ObserverBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
- r.attach(*this);
- build();
- }
-
- /// Copy constructor.
-
- /// Copy constructor to register observer into a registry.
- /// If the copiable obse is registered into a registry
- /// the construated map will be registered to the same registry.
- ///
-
- ObserverBase(const ObserverBase& copy) : graph(copy.graph), registry(0) {
- if (copy.registry) {
- copy.registry->attach(*this);
- build();
- }
- }
+ /// It constrates an observer and then registers it into an
+ /// observer registry. This calls also the build() member
+ /// to notify the observer about it is registered.
- /// Assign operator.
-
- /// Assign operator. This member detach first the observer
- /// from the current registry and then it attach to the
- /// copiable observer's registry if it exists.
-
- const ObserverBase& operator=(const ObserverBase& copy) {
+ void attach(AlterationObserverRegistry& r) {
if (registry) {
- clean();
registry->detach(*this);
}
- graph = copy.graph;
- if (copy.registry) {
- copy.registry->attach(*this);
- build();
- }
- return *this;
+ registry = &r;
+ registry->attach(*this);
}
-
- /// Destructor
- /// The destructor detach the observer from its registry.
- ///
-
- virtual ~ObserverBase() {
+ void detach() {
if (registry) {
registry->detach(*this);
}
}
-
- /// Pointer to the observed graph.
+
+ Registry* getRegistry() const { return registry; }
- /// The getGraph() member function gives back a pointer to the observed graph
- /// if the observer is already registered. Elsewhere gives back null pointer.
+ bool attached() const { return registry != 0; }
+
+ protected:
- const Graph* getGraph() const { return graph; }
+ ObserverBase(const ObserverBase& copy) {}
+ const ObserverBase& operator=(const ObserverBase& copy) {}
- Registry* getRegistry() const { return registry; }
-
protected:
-
- const Graph* graph;
+
mutable Registry* registry;
-
int registry_index;
protected:
@@ -173,24 +133,16 @@
/// The member function to notificate the observer about the graph is builded.
/// The build member function notificates the observer about
- /// the graph is builded. It can be overrided in the subclasses.
+ /// the graph is builded. It have to be overrided in the subclasses.
- virtual void build() {
- for (ItemIt it(*graph); it != INVALID; ++it) {
- add(*it);
- }
- }
+ virtual void build() = 0;
/// The member function to notificate the observer about all items are erased from the graph.
/// The clear member function notificates the observer about
- /// all items are erased from the graph. It can be overrided in the subclasses.
+ /// all items are erased from the graph. It have to be overrided in the subclasses.
- virtual void clear() {
- for (ItemIt it(*getGraph()); it != INVALID; ++it) {
- erase(*it);
- }
- }
+ virtual void clear() = 0;
/// Exception class to throw at unsupported operation.
@@ -235,42 +187,36 @@
AlterationObserverRegistry& operator=(const AlterationObserverRegistry&) {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
- (*it)->clear();
- (*it)->graph = 0;
(*it)->registry = 0;
}
}
/// Destructor.
- /// Destructor of the AlterationObserverRegistry. It calls first the clean()
+ /// Destructor of the AlterationObserverRegistry. It calls first the clear()
/// member function of the attached observers and then detachs them.
~AlterationObserverRegistry() {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
- (*it)->clear();
(*it)->registry = 0;
- (*it)->graph = 0;
}
}
- public:
+ protected:
- /// Attachs the observer into the registry.
+ /// Attaches the observer into the registry.
- /// Attachs the observer into the registry. If the observer has been still attached
- /// into an other registry it is detached from that automaticly.
+ /// This function attaches the observer into the registry.
+ /// It is not allowed to call the attach() function when
+ /// observer is already registered into an other registry.
void attach(ObserverBase& observer) {
- if (observer.registry) {
- observer.registry->detach(observer);
- }
container.push_back(&observer);
observer.registry = this;
observer.registry_index = container.size()-1;
}
- /// Detachs a observer from the \e AlterationObserverRegistry.
+ /// Detaches a observer from the \e AlterationObserverRegistry.
/**
* Detachs a observer from the \e AlterationObserverRegistry.
@@ -280,8 +226,9 @@
container[base.registry_index] = container.back();
container.pop_back();
base.registry = 0;
- base.graph = 0;
}
+
+ public:
/// Notify all the registered observers about a Key added.
@@ -299,17 +246,23 @@
/// Notify all the registered observers about a Key erased.
- /**
- * Notify all the registered observers about a Key erased.
- * This member should be called whenever a node or edge
- * is erased from the graph.
- */
+ /// Notify all the registered observers about a Key erased.
+ /// This member should be called whenever a node or edge
+ /// is erased from the graph.
void erase(const Item& key) {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
(*it)->erase(key);
}
}
+
+
+ void build() {
+ typename Container::iterator it;
+ for (it = container.begin(); it != container.end(); ++it) {
+ (*it)->build();
+ }
+ }
/// Notify all the registered observers about all the Keys are erased.
@@ -327,6 +280,42 @@
}
};
+ template <typename _Base>
+ class AlterableGraphExtender : public _Base {
+ public:
+
+ typedef AlterableGraphExtender Graph;
+ typedef _Base Parent;
+
+ typedef typename Parent::Node Node;
+
+ typedef typename Parent::Edge Edge;
+
+ protected:
+
+ typedef AlterationObserverRegistry<Edge> EdgeObserverRegistry;
+ mutable EdgeObserverRegistry edge_observers;
+
+ typedef AlterationObserverRegistry<Node> NodeObserverRegistry;
+ mutable NodeObserverRegistry node_observers;
+
+ public:
+
+ EdgeObserverRegistry& getEdgeObserverRegistry() const {
+ return edge_observers;
+ }
+
+ NodeObserverRegistry& getNodeObserverRegistry() const {
+ return node_observers;
+ }
+
+ ~AlterableGraphExtender() {
+ node_observers.clear();
+ edge_observers.clear();
+ }
+
+ };
+
/// @}
Modified: hugo/branches/graph_factory/src/lemon/clearable_graph_extender.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/clearable_graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/clearable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -8,19 +8,19 @@
namespace lemon {
- template <typename Base>
- class ClearableGraphExtender : public Base {
+ template <typename _Base>
+ class ClearableGraphExtender : public _Base {
public:
typedef ClearableGraphExtender Graph;
- typedef Base Parent;
+ typedef _Base Parent;
typedef typename Parent::Node Node;
typedef typename Parent::Edge Edge;
void clear() {
- Parent::edge_maps.clear();
- Parent::node_maps.clear();
+ Parent::getNodeObserverRegistry().clear();
+ Parent::getEdgeObserverRegistry().clear();
Parent::clear();
}
Modified: hugo/branches/graph_factory/src/lemon/erasable_graph_extender.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/erasable_graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/erasable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -8,36 +8,36 @@
namespace lemon {
- template <typename Base>
- class ErasableGraphExtender : public Base {
+ template <typename _Base>
+ class ErasableGraphExtender : public _Base {
public:
typedef ErasableGraphExtender Graph;
- typedef Base Parent;
+ typedef _Base Parent;
typedef typename Parent::Node Node;
typedef typename Parent::Edge Edge;
void erase(const Node& node) {
Edge edge;
- Parent::firstOutEdge(edge, node);
+ Parent::firstOut(edge, node);
while (edge != INVALID ) {
erase(edge);
- Parent::firstOutEdge(edge, node);
+ Parent::firstOut(edge, node);
}
- Parent::firstInEdge(edge, node);
+ Parent::firstIn(edge, node);
while (edge != INVALID ) {
erase(edge);
- Parent::firstInEdge(edge, node);
+ Parent::firstIn(edge, node);
}
- Parent::node_maps.erase(node);
+ Parent::getNodeObserverRegistry().erase(node);
Parent::erase(node);
}
void erase(const Edge& edge) {
- Parent::edge_maps.erase(edge);
+ Parent::getEdgeObserverRegistry().erase(edge);
Parent::erase(edge);
}
Modified: hugo/branches/graph_factory/src/lemon/extendable_graph_extender.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/extendable_graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/extendable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -5,25 +5,25 @@
namespace lemon {
- template <typename Base>
- class ExtendableGraphExtender : public Base {
+ template <typename _Base>
+ class ExtendableGraphExtender : public _Base {
public:
typedef ExtendableGraphExtender Graph;
- typedef Base Parent;
+ typedef _Base Parent;
typedef typename Parent::Node Node;
typedef typename Parent::Edge Edge;
Node addNode() {
Node node = Parent::addNode();
- Parent::node_maps.add(node);
+ Parent::getNodeObserverRegistry().add(node);
return node;
}
Edge addEdge(const Node& from, const Node& to) {
Edge edge = Parent::addEdge(from, to);
- Parent::edge_maps.add(edge);
+ Parent::getEdgeObserverRegistry().add(edge);
return edge;
}
Modified: hugo/branches/graph_factory/src/lemon/idmappable_graph_extender.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/idmappable_graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/idmappable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -13,11 +13,12 @@
typedef IdMappableGraphExtender Graph;
typedef Base Parent;
-
typedef typename Parent::Node Node;
typedef typename Parent::Edge Edge;
+ public:
+
class NodeIdMap {
private:
const Graph* graph;
@@ -25,7 +26,7 @@
public:
NodeIdMap(const Graph& g) : graph(&g) {}
- int operator[](const Node& node) { return graph->id(node); }
+ int operator[](const Node& node) const { return graph->id(node); }
int maxId() const {return graph->maxNodeId(); }
Copied: hugo/branches/graph_factory/src/lemon/iterable_graph_extender.h (from r1286, /hugo/branches/graph_factory/src/lemon/graph_extender.h)
==============================================================================
--- /hugo/branches/graph_factory/src/lemon/graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/iterable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -1,17 +1,17 @@
// -*- c++ -*-
-#ifndef LEMON_GRAPH_EXTENDER_H
-#define LEMON_GRAPH_EXTENDER_H
+#ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
+#define LEMON_ITERABLE_GRAPH_EXTENDER_H
#include <lemon/invalid.h>
namespace lemon {
template <typename GraphBase>
- class GraphFactory : public GraphBase {
+ class IterableGraphExtender : public GraphBase {
typedef GraphBase Parent;
- typedef GraphFactory<GraphBase> Graph;
+ typedef IterableGraphExtender<GraphBase> Graph;
public:
- GraphFactory() : Parent() { }
+ IterableGraphExtender() : Parent() { }
typedef typename GraphBase::Node Node;
@@ -21,7 +21,7 @@
public:
NodeIt() { }
NodeIt(Invalid i) : Node(i) { }
- NodeIt(const Graph& _g) : Node() {
+ NodeIt(const Graph& _g) : Node(), g(&_g) {
_g.first(*this);
}
NodeIt(const Graph& _g, const Node& n) :
@@ -39,7 +39,7 @@
public:
EdgeIt() { }
EdgeIt(Invalid i) : Edge(i) { }
- EdgeIt(const Graph& _g) : Edge() {
+ EdgeIt(const Graph& _g) : Edge(), g(&_g) {
_g.first(*this);
}
EdgeIt(const Graph& _g, const Edge& e) :
@@ -55,7 +55,7 @@
public:
OutEdgeIt() { }
OutEdgeIt(Invalid i) : Edge(i) { }
- OutEdgeIt(const Graph& _g, const Node& n) : Edge() {
+ OutEdgeIt(const Graph& _g, const Node& n) : Edge(), g(&_g) {
_g.firstOut(*this, n);
}
OutEdgeIt(const Graph& _g, const Edge& e) :
@@ -71,7 +71,7 @@
public:
InEdgeIt() { }
InEdgeIt(Invalid i) : Edge(i) { }
- InEdgeIt(const Graph& _g, const Node& n) : Edge() {
+ InEdgeIt(const Graph& _g, const Node& n) : Edge(), g(&_g) {
_g.firstIn(*this, n);
}
InEdgeIt(const Graph& _g, const Edge& e) :
@@ -82,47 +82,6 @@
}
};
-// NodeIt& first(NodeIt& i) const {
-// i=NodeIt(*this); return i;
-// }
-// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
-// i=OutEdgeIt(*this, p); return i;
-// }
-// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
-// i=InEdgeIt(*this, p); return i;
-// }
-// EdgeIt& first(EdgeIt& i) const {
-// i=EdgeIt(*this); return i;
-// }
-
-// Node tail(const Edge& e) const {
-// return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
-// Node head(const Edge& e) const {
-// return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
-
-// int nodeNum() const { return graph->nodeNum(); }
-// int edgeNum() const { return graph->edgeNum(); }
-
-// Node addNode() const { return Node(graph->addNode()); }
-// Edge addEdge(const Node& tail, const Node& head) const {
-// return Edge(graph->addEdge(tail, head)); }
-
-// void erase(const Node& i) const { graph->erase(i); }
-// void erase(const Edge& i) const { graph->erase(i); }
-
-// void clear() const { graph->clear(); }
-
-// bool forward(const Edge& e) const { return graph->forward(e); }
-// bool backward(const Edge& e) const { return graph->backward(e); }
-
-// int id(const Node& v) const { return graph->id(v); }
-// int id(const Edge& e) const { return graph->id(e); }
-
-// Edge opposite(const Edge& e) const { return Edge(graph->opposite(e)); }
-
-
-// IMPORT_NODE_MAP(Graph, *(gw.graph), GraphWrapper, gw);
-// IMPORT_EDGE_MAP(Graph, *(gw.graph), GraphWrapper, gw);
};
Modified: hugo/branches/graph_factory/src/lemon/mappable_graph_extender.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/mappable_graph_extender.h (original)
+++ hugo/branches/graph_factory/src/lemon/mappable_graph_extender.h Thu Oct 21 00:01:42 2004
@@ -3,11 +3,9 @@
#ifndef LEMON_MAPPABLE_GRAPH_EXTENDER_H
#define LEMON_MAPPABLE_GRAPH_EXTENDER_H
-#include <lemon/map_registry.h>
-
namespace lemon {
- template <typename Base, template <typename,typename,typename> class DynMap>
+ template <typename Base, template <class,class,class,class,class,class> class DynMap>
class MappableGraphExtender : public Base {
public:
@@ -16,40 +14,77 @@
typedef typename Parent::Node Node;
typedef typename Parent::NodeIt NodeIt;
- typedef typename Parent::NodeIdMap NodeIdMap;
+ typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
typedef typename Parent::Edge Edge;
typedef typename Parent::EdgeIt EdgeIt;
- typedef typename Parent::EdgeIdMap EdgeIdMap;
+ typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
+
+ public:
+
+ class NodeIdMap {
+ private:
+ const Graph* graph;
+
+ public:
+ NodeIdMap(const Graph& g) : graph(&g) {}
+
+ int operator[](const Node& node) { return graph->id(node); }
+ int maxId() const {return graph->maxNodeId(); }
- protected:
+ };
+
+ // template <typename Value>
+ // friend class DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
+ // NodeIdMap, Value>;
+
+ class EdgeIdMap {
+ private:
+ const Graph* graph;
+
+ public:
+ EdgeIdMap(const Graph& g) : graph(&g) {}
- typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry;
- mutable EdgeMapRegistry edge_maps;
+ int operator[](const Edge& edge) const { return graph->id(edge); }
+
+ int maxId() const {return graph->maxEdgeId(); }
+
+ };
- typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry;
- mutable NodeMapRegistry node_maps;
+ // template <typename Value>
+ // friend class DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
+ // EdgeIdMap, Value>;
public:
template <typename Value>
- class NodeMap : public DynMap<NodeMapRegistry, NodeIdMap, Value> {
+ class NodeMap
+ : public DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
+ NodeIdMap, Value> {
public:
- typedef DynMap<NodeMapRegistry, NodeIdMap, Value> Parent;
+ typedef DynMap<NodeObserverRegistry, Graph, Node, NodeIt,
+ NodeIdMap, Value> Parent;
- NodeMap(const Graph& g) : Parent(g, g.node_maps) {}
- NodeMap(const Graph& g, const Value& v) : Parent(g, g.node_maps, v) {}
+ NodeMap(const Graph& g)
+ : Parent(g, g.Graph::Parent::getNodeObserverRegistry()) {}
+ NodeMap(const Graph& g, const Value& v)
+ : Parent(g, g.Graph::Parent::getNodeObserverRegistry(), v) {}
};
template <typename Value>
- class EdgeMap : public DynMap<EdgeMapRegistry, EdgeIdMap, Value> {
+ class EdgeMap
+ : public DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
+ EdgeIdMap, Value> {
public:
- typedef DynMap<EdgeMapRegistry, EdgeIdMap, Value> Parent;
+ typedef DynMap<EdgeObserverRegistry, Graph, Edge, EdgeIt,
+ EdgeIdMap, Value> Parent;
- EdgeMap(const Graph& g) : Parent(g, g.edge_maps) {}
- EdgeMap(const Graph& g, const Value& v) : Parent(g, g.edge_maps, v) {}
+ EdgeMap(const Graph& g)
+ : Parent(g, g.Graph::Parent::getEdgeObserverRegistry()) {}
+ EdgeMap(const Graph& g, const Value& v)
+ : Parent(g, g.Graph::Parent::getEdgeObserverRegistry(), v) {}
};
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 21 00:01:42 2004
@@ -234,26 +234,26 @@
/// Gives back the first of the Edges point to the given Node.
///
- void firstInEdge(Edge&, const Node&) const {}
+ void firstIn(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 {}
+ void nextIn(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 {}
+ void firstOut(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 {}
+ void nextOut(Edge&) const {}
};
@@ -277,12 +277,12 @@
const_graph.next(edge);
}
{
- const_graph.firstInEdge(edge, node);
- const_graph.nextInEdge(edge);
+ const_graph.firstIn(edge, node);
+ const_graph.nextIn(edge);
}
{
- const_graph.firstOutEdge(edge, node);
- const_graph.nextOutEdge(edge);
+ const_graph.firstOut(edge, node);
+ const_graph.nextOut(edge);
}
}
Modified: hugo/branches/graph_factory/src/lemon/skeletons/extended_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/skeletons/extended_graph.h (original)
+++ hugo/branches/graph_factory/src/lemon/skeletons/extended_graph.h Thu Oct 21 00:01:42 2004
@@ -20,53 +20,53 @@
typedef BaseGraph::Node Node;
typedef BaseGraph::Edge Edge;
- class NodeIt {
+ class NodeIt : public Node {
public:
NodeIt() {}
NodeIt(Invalid) {}
NodeIt(const Graph&) {}
NodeIt& operator++() { return *this; }
- Node operator*() const { return INVALID; }
+ // Node operator*() const { return INVALID; }
bool operator==(const NodeIt&) { return true;}
bool operator!=(const NodeIt&) { return true;}
};
- class EdgeIt {
+ class EdgeIt : public Edge {
public:
EdgeIt() {}
EdgeIt(Invalid) {}
EdgeIt(const Graph&) {}
EdgeIt& operator++() { return *this; }
- Edge operator*() const { return INVALID; }
+ // Edge operator*() const { return INVALID; }
bool operator==(const EdgeIt&) { return true;}
bool operator!=(const EdgeIt&) { return true;}
};
- class InEdgeIt {
+ class InEdgeIt : public Edge {
public:
InEdgeIt() {}
InEdgeIt(Invalid) {}
InEdgeIt(const Graph&, const Node&) {}
InEdgeIt& operator++() { return *this; }
- Edge operator*() const { return INVALID; }
+ // Edge operator*() const { return INVALID; }
bool operator==(const InEdgeIt&) { return true;}
bool operator!=(const InEdgeIt&) { return true;}
};
- class OutEdgeIt {
+ class OutEdgeIt : public Edge {
public:
OutEdgeIt() {}
OutEdgeIt(Invalid) {}
OutEdgeIt(const Graph&, const Node&) {}
OutEdgeIt& operator++() { return *this; }
- Edge operator*() const { return INVALID; }
+ // Edge operator*() const { return INVALID; }
bool operator==(const OutEdgeIt&) { return true;}
bool operator!=(const OutEdgeIt&) { return true;}
@@ -96,8 +96,8 @@
b = (it != INVALID);
b = (it == jt);
b = (it != jt);
- Node node = *it;
- node = *it;
+ Node node = it;
+ node = it;
}
{
EdgeIt it;
@@ -111,8 +111,8 @@
b = (it != INVALID);
b = (it == jt);
b = (it != jt);
- Edge edge = *it;
- edge = *it;
+ Edge edge = it;
+ edge = it;
}
{
InEdgeIt it;
@@ -127,8 +127,8 @@
b = (it != INVALID);
b = (it == jt);
b = (it != jt);
- Edge edge = *it;
- edge = *it;
+ Edge edge = it;
+ edge = it;
}
{
OutEdgeIt it;
@@ -143,8 +143,8 @@
b = (it != INVALID);
b = (it == jt);
b = (it != jt);
- Edge edge = *it;
- edge = *it;
+ Edge edge = it;
+ edge = it;
}
}
Modified: hugo/branches/graph_factory/src/lemon/test_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/test_graph.h (original)
+++ hugo/branches/graph_factory/src/lemon/test_graph.h Thu Oct 21 00:01:42 2004
@@ -1,21 +1,23 @@
// -*- c++ -*-
-#ifndef LEMON_TEST_GRAPH_H
-#define LEMON_TEST_GRAPH_H
+#ifndef LEMON_LIST_GRAPH_H
+#define LEMON_LIST_GRAPH_H
#include <lemon/erasable_graph_extender.h>
#include <lemon/clearable_graph_extender.h>
#include <lemon/extendable_graph_extender.h>
-#include <lemon/mappable_graph_extender.h>
+
#include <lemon/idmappable_graph_extender.h>
+
#include <lemon/iterable_graph_extender.h>
+#include <lemon/alteration_registry.h>
#include <lemon/vector_map.h>
namespace lemon {
- class TestGraphBase {
+ class ListGraphBase {
struct NodeT {
int first_in,first_out;
@@ -40,7 +42,7 @@
public:
- typedef TestGraphBase Graph;
+ typedef ListGraphBase Graph;
class Node {
friend class Graph;
@@ -74,11 +76,11 @@
- TestGraphBase()
+ ListGraphBase()
: nodes(), first_node(-1),
first_free_node(-1), edges(), first_free_edge(-1) {}
- TestGraphBase(const TestGraphBase &g)
+ ListGraphBase(const ListGraphBase &g)
: nodes(g.nodes), first_node(g.first_node),
first_free_node(g.first_free_node), edges(g.edges),
first_free_edge(g.first_free_edge) {}
@@ -131,17 +133,17 @@
}
}
- void firstOutEdge(Edge &e, const Node& v) const {
+ void firstOut(Edge &e, const Node& v) const {
e.id = nodes[v.id].first_out;
}
- void nextOutEdge(Edge &e) const {
+ void nextOut(Edge &e) const {
e.id=edges[e.id].next_out;
}
- void firstInEdge(Edge &e, const Node& v) const {
+ void firstIn(Edge &e, const Node& v) const {
e.id = nodes[v.id].first_in;
}
- void nextInEdge(Edge &e) const {
+ void nextIn(Edge &e) const {
e.id=edges[e.id].next_in;
}
@@ -260,13 +262,16 @@
};
- typedef ErasableGraphExtender<
- ClearableGraphExtender<
- ExtendableGraphExtender<
- MappableGraphExtender<
- IdMappableGraphExtender<
- IterableGraphExtender<
- TestGraphBase> >, VectorMap> > > > TestGraph;
+ typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
+ typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
+ typedef IdMappableGraphExtender<IterableListGraphBase> IdMappableListGraphBase;
+ typedef VectorMappableGraphExtender<IdMappableListGraphBase> MappableListGraphBase;
+ typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
+ typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
+ typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
+
+ typedef ErasableListGraphBase ListGraph;
+
}
Modified: hugo/branches/graph_factory/src/lemon/vector_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/vector_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/vector_map.h Thu Oct 21 00:01:42 2004
@@ -20,6 +20,8 @@
#include <vector>
#include <algorithm>
+#include <lemon/alteration_registry.h>
+
///\ingroup graphmaps
///\file
///\brief Vector based graph maps.
@@ -41,21 +43,29 @@
///
/// \author Balazs Dezso
- template <typename Registry, typename IdMap, typename Value>
- class VectorMap : public Registry::ObserverBase {
+
+ template <typename _Graph,
+ typename _Item,
+ typename _IdMap,
+ typename _Value>
+ class VectorMap : public AlterationObserverRegistry<_Item>::ObserverBase {
public:
- /// The graph type of the maps.
- typedef typename Registry::Graph Graph;
- /// The key type of the maps.
- typedef typename Registry::ItemType KeyType;
- /// The iterator to iterate on the keys.
- typedef typename Registry::ItemIt KeyIt;
+ /// The graph type of the map.
+ typedef _Graph Graph;
+ /// The key type of the map.
+ typedef _Item KeyType;
+ /// The id map type of the map.
+ typedef _IdMap IdMap;
+ /// The registry type of the map.
+ typedef AlterationObserverRegistry<_Item> Registry;
+ /// The value type of the map.
+ typedef _Value Value;
/// The map type.
typedef VectorMap Map;
- /// The ObserverBase of the Map which implements the core regisitry function.
- typedef typename Registry::ObserverBase ObserverBase;
+ /// The base class of the map.
+ typedef typename Registry::ObserverBase Parent;
private:
@@ -83,26 +93,46 @@
/// It construates a map and attachs it into the registry.
/// It adds all the items of the graph to the map.
- VectorMap(const Graph& g, Registry& r)
- : ObserverBase(g, r) {}
+ VectorMap(const Graph& g, Registry& r) : graph(&g) {
+ attach(r);
+ build();
+ }
/// Constructor uses given value to initialize the map.
/// It construates a map uses a given value to initialize the map.
/// It adds all the items of the graph to the map.
- VectorMap(const Graph& g, Registry& r, const Value& v)
- : ObserverBase(g, r) {
+ VectorMap(const Graph& g, Registry& r, const Value& v) : graph(&g) {
+ attach(r);
+ build();
std::fill(container.begin(), container.end(), v);
}
+ VectorMap(const VectorMap& copy) : graph(copy.getGraph()) {
+ if (copy.attached()) {
+ attach(*copy.getRegistry());
+ build();
+ }
+ }
+
+ ~VectorMap() {
+ if (attached()) {
+ detach();
+ }
+ }
+
+ const Graph* getGraph() const {
+ return graph;
+ }
+
/// The subcript operator.
/// The subscript operator. The map can be subscripted by the
/// actual items of the graph.
ReferenceType operator[](const KeyType& key) {
- return container[IdMap(*ObserverBase::getGraph())[key]];
+ return container[IdMap(*graph)[key]];
}
/// The const subcript operator.
@@ -111,7 +141,7 @@
/// actual items of the graph.
ConstReferenceType operator[](const KeyType& key) const {
- return container[IdMap(*ObserverBase::getGraph())[key]];
+ return container[IdMap(*graph)[key]];
}
@@ -121,7 +151,7 @@
///
void set(const KeyType& key, const ValueType& value) const {
- container[IdMap(*ObserverBase::getGraph())[key]] = value;
+ (*this)[key] = value;
}
/// Adds a new key to the map.
@@ -130,7 +160,7 @@
/// and it overrides the add() member function of the observer base.
void add(const KeyType& key) {
- int id = IdMap(*ObserverBase::getGraph())[key];
+ int id = IdMap(*graph)[key];
if (id >= (int)container.size()) {
container.resize(id + 1);
}
@@ -146,8 +176,9 @@
/// It buildes the map. It called by the observer registry
/// and it overrides the build() member function of the observer base.
+
void build() {
- container.resize(IdMap(g).maxId()+1);
+ container.resize(IdMap(*graph).maxId() + 1);
}
/// Clear the map.
@@ -161,7 +192,70 @@
private:
Container container;
+ const Graph *graph;
+
+ };
+
+
+ template <typename _Base>
+ class VectorMappableGraphExtender : public _Base {
+ public:
+
+ typedef VectorMappableGraphExtender<_Base> Graph;
+ typedef _Base Parent;
+
+ typedef typename Parent::Node Node;
+ typedef typename Parent::NodeIt NodeIt;
+ typedef typename Parent::NodeIdMap NodeIdMap;
+ typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
+
+ typedef typename Parent::Edge Edge;
+ typedef typename Parent::EdgeIt EdgeIt;
+ typedef typename Parent::EdgeIdMap EdgeIdMap;
+ typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
+
+
+
+ template <typename _Value>
+ class NodeMap : public VectorMap<Graph, Node, NodeIdMap, _Value> {
+ public:
+ typedef VectorMappableGraphExtender<_Base> Graph;
+
+ typedef typename Graph::Node Node;
+ typedef typename Graph::NodeIdMap NodeIdMap;
+
+ typedef VectorMap<Graph, Node, NodeIdMap, _Value> Parent;
+
+ typedef typename Parent::Graph Graph;
+ typedef typename Parent::Value Value;
+
+ NodeMap(const Graph& g)
+ : Parent(g, g.getNodeObserverRegistry()) {}
+ NodeMap(const Graph& g, const Value& v)
+ : Parent(g, g.getNodeObserverRegistry(), v) {}
+
+ };
+
+ template <typename _Value>
+ class EdgeMap : public VectorMap<Graph, Edge, EdgeIdMap, _Value> {
+ public:
+ typedef VectorMappableGraphExtender<_Base> Graph;
+
+ typedef typename Graph::Edge Edge;
+ typedef typename Graph::EdgeIdMap EdgeIdMap;
+
+ typedef VectorMap<Graph, Edge, EdgeIdMap, _Value> Parent;
+
+ typedef typename Parent::Graph Graph;
+ typedef typename Parent::Value Value;
+
+ EdgeMap(const Graph& g)
+ : Parent(g, g.getEdgeObserverRegistry()) {}
+ EdgeMap(const Graph& g, const Value& v)
+ : Parent(g, g.getEdgeObserverRegistry(), v) {}
+ };
+
};
/// @}
Modified: hugo/branches/graph_factory/src/test/extended_graph_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/extended_graph_test.cc (original)
+++ hugo/branches/graph_factory/src/test/extended_graph_test.cc Thu Oct 21 00:01:42 2004
@@ -33,22 +33,22 @@
template void lemon::skeleton::checkIterableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
template void lemon::skeleton::checkIdMappableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
template void lemon::skeleton::checkMappableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
template void lemon::skeleton::checkExtendableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
template void lemon::skeleton::checkErasableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
template void lemon::skeleton::checkClearableExtendedGraph
-<TestGraph>(TestGraph &);
+<ListGraph>(ListGraph &);
@@ -61,7 +61,7 @@
std::vector<Edge> ee;
- for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(*e);
+ for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
G.addEdge(G.head(*p),G.tail(*p));
@@ -78,8 +78,8 @@
checkGraphEdgeList(G,30);
for(NodeIt n(G);n!=INVALID;++n) {
- checkGraphInEdgeList(G,*n,3);
- checkGraphOutEdgeList(G,*n,3);
+ checkGraphInEdgeList(G,n,3);
+ checkGraphOutEdgeList(G,n,3);
}
}
@@ -87,7 +87,7 @@
int main() {
///\file
{
- TestGraph G;
+ ListGraph G;
addPetersen(G);
bidirPetersen(G);
checkPetersen(G);
Modified: hugo/branches/graph_factory/src/test/graph_test.h
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.h (original)
+++ hugo/branches/graph_factory/src/test/graph_test.h Thu Oct 21 00:01:42 2004
@@ -25,52 +25,51 @@
namespace lemon {
template<class Graph> void checkGraphNodeList(Graph &G, int nn)
- {
- typename Graph::NodeIt n(G);
- for(int i=0;i<nn;i++) {
- check(n!=INVALID,"Wrong Node list linking.");
- ++n;
- }
- check(n==INVALID,"Wrong Node list linking.");
+ {
+ typename Graph::NodeIt n(G);
+ for(int i=0;i<nn;i++) {
+ check(n!=INVALID,"Wrong Node list linking.");
+ ++n;
}
+ check(n==INVALID,"Wrong Node list linking.");
+ }
- template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
- {
- typedef typename Graph::EdgeIt EdgeIt;
-
- EdgeIt e(G);
- for(int i=0;i<nn;i++) {
- check(e!=INVALID,"Wrong Edge list linking.");
- ++e;
- }
- check(e==INVALID,"Wrong Edge list linking.");
+ template<class Graph>
+ void checkGraphEdgeList(Graph &G, int nn)
+ {
+ typedef typename Graph::EdgeIt EdgeIt;
+
+ EdgeIt e(G);
+ for(int i=0;i<nn;i++) {
+ check(e!=INVALID,"Wrong Edge list linking.");
+ ++e;
}
+ check(e==INVALID,"Wrong Edge list linking.");
+ }
- template<class Graph> void checkGraphOutEdgeList(Graph &G,
- typename Graph::Node n,
- int nn)
- {
- typename Graph::OutEdgeIt e(G,n);
- for(int i=0;i<nn;i++) {
- check(e!=INVALID,"Wrong OutEdge list linking.");
- check(n==G.tail(*e), "Wrong OutEdge list linking.");
- ++e;
- }
- check(e==INVALID,"Wrong OutEdge list linking.");
+ template<class Graph>
+ void checkGraphOutEdgeList(Graph &G, typename Graph::Node n, int nn)
+ {
+ typename Graph::OutEdgeIt e(G,n);
+ for(int i=0;i<nn;i++) {
+ check(e!=INVALID,"Wrong OutEdge list linking.");
+ check(n==G.tail(e), "Wrong OutEdge list linking.");
+ ++e;
}
+ check(e==INVALID,"Wrong OutEdge list linking.");
+ }
- template<class Graph> void checkGraphInEdgeList(Graph &G,
- typename Graph::Node n,
- int nn)
- {
- typename Graph::InEdgeIt e(G,n);
- for(int i=0;i<nn;i++) {
- check(e!=INVALID,"Wrong InEdge list linking.");
- check(n==G.head(*e), "Wrong InEdge list linking.");
- ++e;
- }
- check(e==INVALID,"Wrong InEdge list linking.");
+ template<class Graph> void
+ checkGraphInEdgeList(Graph &G, typename Graph::Node n, int nn)
+ {
+ typename Graph::InEdgeIt e(G,n);
+ for(int i=0;i<nn;i++) {
+ check(e!=INVALID,"Wrong InEdge list linking.");
+ check(n==G.head(e), "Wrong InEdge list linking.");
+ ++e;
}
+ check(e==INVALID,"Wrong InEdge list linking.");
+ }
///\file
///\todo Check head(), tail() as well;
More information about the Lemon-commits
mailing list