[Lemon-commits] [lemon_svn] deba: r1092 - hugo/trunk/src/hugo
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:43:12 CET 2006
Author: deba
Date: Fri Sep 3 17:11:17 2004
New Revision: 1092
Added:
hugo/trunk/src/hugo/default_map_factory.h
Modified:
hugo/trunk/src/hugo/full_graph.h
hugo/trunk/src/hugo/list_graph.h
hugo/trunk/src/hugo/smart_graph.h
hugo/trunk/src/hugo/sym_map_factory.h
hugo/trunk/src/hugo/vector_map_factory.h
Log:
Added: hugo/trunk/src/hugo/default_map_factory.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/hugo/default_map_factory.h Fri Sep 3 17:11:17 2004
@@ -0,0 +1,143 @@
+// -*- c++ -*-
+#ifndef DEFAULT_MAP_FACTORY_H
+#define DEFAULT_MAP_FACTORY_H
+
+
+#include <hugo/array_map_factory.h>
+#include <hugo/vector_map_factory.h>
+
+namespace hugo {
+
+#define DEFAULT_MAP_BODY(Factory, Val) \
+ { \
+ typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
+ \
+ public: \
+ \
+ typedef typename MapRegistry::Graph Graph; \
+ typedef typename MapRegistry::Key Key; \
+ typedef typename MapRegistry::KeyIt KeyIt; \
+ typedef Val Value; \
+ \
+ typedef typename MapRegistry::MapBase MapBase; \
+ \
+ DefaultMap() : MapImpl() {} \
+ \
+ DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
+ \
+ DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
+ : MapImpl(g, r, v) {} \
+ \
+ DefaultMap(const DefaultMap& copy) \
+ : MapImpl(static_cast<const MapImpl&>(copy)) {} \
+ \
+ template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
+ \
+ DefaultMap& operator=(const DefaultMap& copy) { \
+ MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
+ return *this; \
+ } \
+ \
+ template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
+ MapImpl::operator=(copy); \
+ return *this; \
+ } \
+ \
+ };
+
+
+ template <typename MapRegistry, typename Type>
+ class DefaultMap : public ArrayMapFactory<MapRegistry>::template Map<Type>
+ DEFAULT_MAP_BODY(ArrayMapFactory, Type);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, bool>
+ : public VectorMapFactory<MapRegistry>::template Map<bool>
+ DEFAULT_MAP_BODY(VectorMapFactory, bool);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, char>
+ : public VectorMapFactory<MapRegistry>::template Map<char>
+ DEFAULT_MAP_BODY(VectorMapFactory, char);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, int>
+ : public VectorMapFactory<MapRegistry>::template Map<int>
+ DEFAULT_MAP_BODY(VectorMapFactory, int);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, short>
+ : public VectorMapFactory<MapRegistry>::template Map<short>
+ DEFAULT_MAP_BODY(VectorMapFactory, short);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, long>
+ : public VectorMapFactory<MapRegistry>::template Map<long>
+ DEFAULT_MAP_BODY(VectorMapFactory, long);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, float>
+ : public VectorMapFactory<MapRegistry>::template Map<float>
+ DEFAULT_MAP_BODY(VectorMapFactory, float);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, double>
+ : public VectorMapFactory<MapRegistry>::template Map<double>
+ DEFAULT_MAP_BODY(VectorMapFactory, double);
+
+ template <typename MapRegistry>
+ class DefaultMap<MapRegistry, long double>
+ : public VectorMapFactory<MapRegistry>::template Map<long double>
+ DEFAULT_MAP_BODY(VectorMapFactory, long double);
+
+ template <typename MapRegistry, typename Type>
+ class DefaultMap<MapRegistry, Type*>
+ : public VectorMapFactory<MapRegistry>::template Map<Type*>
+ DEFAULT_MAP_BODY(VectorMapFactory, Type*);
+
+ template <typename MapRegistry>
+ class DefaultMapFactory {
+
+ public:
+
+ typedef typename MapRegistry::Graph Graph;
+ typedef typename MapRegistry::Key Key;
+ typedef typename MapRegistry::KeyIt KeyIt;
+
+ typedef typename MapRegistry::MapBase MapBase;
+
+ template <typename V>
+ class Map : public DefaultMap<MapRegistry, V> {
+
+ typedef DefaultMap<MapRegistry, V> MapImpl;
+
+ public:
+
+ typedef V Value;
+
+ Map() : MapImpl() {}
+
+ Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
+
+ Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
+
+ Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
+
+ template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
+
+ Map& operator=(const Map& copy) {
+ MapImpl::operator=(static_cast<const MapImpl&>(copy));
+ return *this;
+ }
+
+ template <typename CMap> Map& operator=(const CMap& copy) {
+ MapImpl::operator=(copy);
+ return *this;
+ }
+
+ };
+
+ };
+}
+
+#endif
Modified: hugo/trunk/src/hugo/full_graph.h
==============================================================================
--- hugo/trunk/src/hugo/full_graph.h (original)
+++ hugo/trunk/src/hugo/full_graph.h Fri Sep 3 17:11:17 2004
@@ -13,7 +13,7 @@
#include <hugo/invalid.h>
#include <hugo/map_registry.h>
-#include <hugo/array_map_factory.h>
+#include <hugo/default_map_factory.h>
namespace hugo {
@@ -48,7 +48,7 @@
class InEdgeIt;
CREATE_MAP_REGISTRIES;
- CREATE_MAPS(ArrayMapFactory);
+ CREATE_MAPS(DefaultMapFactory);
public:
Modified: hugo/trunk/src/hugo/list_graph.h
==============================================================================
--- hugo/trunk/src/hugo/list_graph.h (original)
+++ hugo/trunk/src/hugo/list_graph.h Fri Sep 3 17:11:17 2004
@@ -13,7 +13,7 @@
#include <hugo/invalid.h>
#include <hugo/map_registry.h>
-#include <hugo/array_map_factory.h>
+#include <hugo/default_map_factory.h>
#include <hugo/sym_map_factory.h>
@@ -80,7 +80,7 @@
class InEdgeIt;
CREATE_MAP_REGISTRIES;
- CREATE_MAPS(ArrayMapFactory);
+ CREATE_MAPS(DefaultMapFactory);
public:
@@ -425,7 +425,7 @@
KEEP_EDGE_MAP(ListGraph);
CREATE_SYM_EDGE_MAP_REGISTRY;
- CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
+ CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
SymListGraph() : ListGraph() { }
@@ -508,7 +508,7 @@
class InEdgeIt;
CREATE_MAP_REGISTRIES;
- CREATE_MAPS(ArrayMapFactory);
+ CREATE_MAPS(DefaultMapFactory);
public:
@@ -805,7 +805,7 @@
CREATE_EDGE_MAP_REGISTRY;
- CREATE_EDGE_MAP_FACTORY(ArrayMapFactory);
+ CREATE_EDGE_MAP_FACTORY(DefaultMapFactory);
IMPORT_EDGE_MAP(EdgeMapFactory);
Modified: hugo/trunk/src/hugo/smart_graph.h
==============================================================================
--- hugo/trunk/src/hugo/smart_graph.h (original)
+++ hugo/trunk/src/hugo/smart_graph.h Fri Sep 3 17:11:17 2004
@@ -12,7 +12,7 @@
#include <hugo/invalid.h>
-#include <hugo/array_map_factory.h>
+#include <hugo/default_map_factory.h>
#include <hugo/sym_map_factory.h>
#include <hugo/map_registry.h>
@@ -73,7 +73,7 @@
class InEdgeIt;
CREATE_MAP_REGISTRIES;
- CREATE_MAPS(ArrayMapFactory);
+ CREATE_MAPS(DefaultMapFactory);
public:
@@ -296,7 +296,7 @@
KEEP_EDGE_MAP(SmartGraph);
CREATE_SYM_EDGE_MAP_REGISTRY;
- CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
+ CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
SymSmartGraph() : SmartGraph() { }
@@ -305,7 +305,9 @@
Edge addEdge(Node u, Node v)
{
Edge e = SmartGraph::addEdge(u,v);
- SmartGraph::addEdge(v,u);
+ Edge f = SmartGraph::addEdge(v,u);
+ sym_edge_maps.add(e);
+ sym_edge_maps.add(f);
return e;
}
Modified: hugo/trunk/src/hugo/sym_map_factory.h
==============================================================================
--- hugo/trunk/src/hugo/sym_map_factory.h (original)
+++ hugo/trunk/src/hugo/sym_map_factory.h Fri Sep 3 17:11:17 2004
@@ -12,7 +12,11 @@
: EdgeIt() {}
SymEdgeIt(const Graph& graph)
- : EdgeIt(graph) {}
+ : EdgeIt(graph) {
+ while ( n != -1 && (n & 1)) {
+ EdgeIt::operator++();
+ }
+ }
SymEdgeIt(Invalid invalid)
: EdgeIt(invalid) {}
@@ -52,7 +56,8 @@
Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
- Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
+ Map(const Graph& g, MapRegistry& r, const Value& v)
+ : MapImpl(g, r, v) {}
Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
Modified: hugo/trunk/src/hugo/vector_map_factory.h
==============================================================================
--- hugo/trunk/src/hugo/vector_map_factory.h (original)
+++ hugo/trunk/src/hugo/vector_map_factory.h Fri Sep 3 17:11:17 2004
@@ -17,7 +17,7 @@
/** The VectorMapFactory template class is a factory class
* to create maps for the edge and nodes. This map factory
- * use the std::vector to implement the container function.
+ * uses the std::vector to implement the container function.
*
* The template parameter is the MapRegistry that the maps
* will belong to.
@@ -42,12 +42,27 @@
*/
template <typename V>
class Map : public MapBase {
+
+ typedef std::vector<V> Container;
+
public:
/// The value type of the map.
- typedef V Value;
+ typedef V ValueType;
- typedef std::vector<Value> Container;
+ /// The value type of the map.
+ typedef V Value;
+ /// The reference type of the map;
+ typedef typename Container::reference Reference;
+ /// The pointer type of the map;
+ typedef typename Container::pointer Pointer;
+
+ /// The const value type of the map.
+ typedef const Value ConstValue;
+ /// The const reference type of the map;
+ typedef typename Container::const_reference ConstReference;
+ /// The pointer type of the map;
+ typedef typename Container::const_pointer ConstPointer;
/** Default constructor for the map.
*/
@@ -64,7 +79,7 @@
Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
for (KeyIt it(*getGraph()); it != INVALID; ++it) {
int id = getGraph()->id(it);
- if (id >= container.size()) {
+ if (id >= (int)container.size()) {
container.resize(id + 1);
}
set(it, v);
@@ -77,7 +92,7 @@
if (getGraph()) {
for (KeyIt it(*getGraph()); it != INVALID; ++it) {
int id = getGraph()->id(it);
- if (id >= container.size()) {
+ if (id >= (int)container.size()) {
container.resize(id + 1);
}
set(it, copy[it]);
@@ -95,12 +110,13 @@
if (getGraph()) {
for (KeyIt it(*getGraph()); it != INVALID; ++it) {
int id = getGraph()->id(it);
- if (id >= container.size()) {
+ if (id >= (int)container.size()) {
container.resize(id + 1);
}
set(it, copy[it]);
}
}
+ return *this;
}
/** The destructor of the map.
@@ -112,7 +128,11 @@
* The subscript operator. The map can be subscripted by the
* actual keys of the graph.
*/
+<<<<<<< .mine
+ Reference operator[](const Key& key) {
+=======
typename Container::reference operator[](const KeyType& key) {
+>>>>>>> .r1091
int id = getGraph()->id(key);
return container[id];
}
@@ -121,7 +141,11 @@
* The const subscript operator. The map can be subscripted by the
* actual keys of the graph.
*/
+<<<<<<< .mine
+ ConstReference operator[](const Key& key) const {
+=======
typename Container::const_reference operator[](const KeyType& key) const {
+>>>>>>> .r1091
int id = getGraph()->id(key);
return container[id];
}
@@ -138,7 +162,7 @@
*/
void add(const KeyType& key) {
int id = getGraph()->id(key);
- if (id >= container.size()) {
+ if (id >= (int)container.size()) {
container.resize(id + 1);
}
}
@@ -173,7 +197,7 @@
iterator() {}
typedef extended_pair<const KeyType&, const KeyType&,
- Value&, Value&> Reference;
+ Map::Reference, Map::Reference> Reference;
/** Dereference operator for map.
*/
@@ -263,7 +287,7 @@
const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
typedef extended_pair<const KeyType&, const KeyType&,
- const Value&, const Value&> Reference;
+ Map::ConstReference, Map::ConstReference> Reference;
/** Dereference operator for map.
*/
More information about the Lemon-commits
mailing list