[Lemon-commits] [lemon_svn] deba: r1694 - in hugo/trunk/src: lemon work/deba
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:47:02 CET 2006
Author: deba
Date: Sat Mar 26 00:31:57 2005
New Revision: 1694
Added:
hugo/trunk/src/work/deba/iterator_test.cpp
Modified:
hugo/trunk/src/lemon/array_map.h
hugo/trunk/src/lemon/default_map.h
hugo/trunk/src/lemon/graph_utils.h
hugo/trunk/src/lemon/map_iterator.h
hugo/trunk/src/lemon/map_utils.h
hugo/trunk/src/lemon/vector_map.h
hugo/trunk/src/work/deba/test.cpp
Log:
First version of iterable maps.
Modified: hugo/trunk/src/lemon/array_map.h
==============================================================================
--- hugo/trunk/src/lemon/array_map.h (original)
+++ hugo/trunk/src/lemon/array_map.h Sat Mar 26 00:31:57 2005
@@ -18,6 +18,7 @@
#define LEMON_ARRAY_MAP_H
#include <memory>
+#include <lemon/map_iterator.h>
///\ingroup graphmaps
///\file
@@ -35,16 +36,16 @@
* the map. This map factory uses the allocators to implement
* the container functionality.
*
- * The template parameter is the MapRegistry that the maps
+ * The template parameter is the AlterationNotifier that the maps
* will belong to and the Value.
*/
template <typename _Graph,
typename _Item,
- typename _ItemIt,
typename _Value>
class ArrayMap : public AlterationNotifier<_Item>::ObserverBase {
+ typedef _Item Item;
public:
/// The graph type of the maps.
@@ -54,29 +55,11 @@
typedef AlterationNotifier<_Item> Registry;
- private:
- /// The iterator to iterate on the keys.
- typedef _ItemIt KeyIt;
-
/// The MapBase of the Map which imlements the core regisitry function.
typedef typename Registry::ObserverBase Parent;
-
- public:
-
/// The value type of the map.
typedef _Value Value;
- /// The reference type of the map;
- typedef Value& Reference;
- /// The pointer type of the map;
- typedef Value* Pointer;
-
- /// The const value type of the map.
- typedef const Value ConstValue;
- /// The const reference type of the map;
- typedef const Value& ConstReference;
- /// The pointer type of the map;
- typedef const Value* ConstPointer;
private:
@@ -88,9 +71,10 @@
/** Graph and Registry initialized map constructor.
*/
ArrayMap(const Graph& _g) : graph(&_g) {
- attach(_g.getNotifier(_Item()));
+ Item it;
+ attach(_g.getNotifier(Item()));
allocate_memory();
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.construct(&(values[id]), Value());
}
@@ -101,9 +85,10 @@
/// It constrates a map and initialize all of the the map.
ArrayMap(const Graph& _g, const Value& _v) : graph(&_g) {
+ Item it;
attach(_g.getNotifier(_Item()));
allocate_memory();
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.construct(&(values[id]), _v);
}
@@ -118,7 +103,8 @@
capacity = copy.capacity;
if (capacity == 0) return;
values = allocator.allocate(capacity);
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ Item it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.construct(&(values[id]), copy.values[id]);
}
@@ -146,7 +132,8 @@
values = allocator.allocate(capacity);
}
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ Item it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.construct(&(values[id]), copy.values[id]);
}
@@ -168,7 +155,7 @@
* The subscript operator. The map can be subscripted by the
* actual keys of the graph.
*/
- Reference operator[](const Key& key) {
+ Value& operator[](const Key& key) {
int id = graph->id(key);
return values[id];
}
@@ -177,7 +164,7 @@
* The const subscript operator. The map can be subscripted by the
* actual keys of the graph.
*/
- ConstReference operator[](const Key& key) const {
+ const Value& operator[](const Key& key) const {
int id = graph->id(key);
return values[id];
}
@@ -199,7 +186,8 @@
new_capacity <<= 1;
}
Value* new_values = allocator.allocate(new_capacity);
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ Item it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int jd = graph->id(it);;
if (id != jd) {
allocator.construct(&(new_values[jd]), values[jd]);
@@ -222,7 +210,8 @@
void build() {
allocate_memory();
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ Item it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.construct(&(values[id]), Value());
}
@@ -230,7 +219,8 @@
void clear() {
if (capacity != 0) {
- for (KeyIt it(*graph); it != INVALID; ++it) {
+ Item it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
int id = graph->id(it);;
allocator.destroy(&(values[id]));
}
@@ -313,18 +303,6 @@
Value* values;
Allocator allocator;
- public:
-// // STL compatibility typedefs.
-// typedef Iterator iterator;
-// typedef ConstIterator const_iterator;
-// typedef typename Iterator::PairValue value_type;
-// typedef typename Iterator::Key key_type;
-// typedef typename Iterator::Value data_type;
-// typedef typename Iterator::PairReference reference;
-// typedef typename Iterator::PairPointer pointer;
-// typedef typename ConstIterator::PairReference const_reference;
-// typedef typename ConstIterator::PairPointer const_pointer;
-// typedef int difference_type;
};
template <typename _Base>
@@ -345,14 +323,15 @@
template <typename _Value>
- class NodeMap : public ArrayMap<Graph, Node, NodeIt, _Value> {
+ class NodeMap
+ : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
public:
typedef ArrayMappableGraphExtender<_Base> Graph;
typedef typename Graph::Node Node;
typedef typename Graph::NodeIt NodeIt;
- typedef ArrayMap<Graph, Node, NodeIt, _Value> Parent;
+ typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
//typedef typename Parent::Graph Graph;
typedef typename Parent::Value Value;
@@ -365,14 +344,15 @@
};
template <typename _Value>
- class EdgeMap : public ArrayMap<Graph, Edge, EdgeIt, _Value> {
+ class EdgeMap
+ : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
public:
typedef ArrayMappableGraphExtender<_Base> Graph;
typedef typename Graph::Edge Edge;
typedef typename Graph::EdgeIt EdgeIt;
- typedef ArrayMap<Graph, Edge, EdgeIt, _Value> Parent;
+ typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
//typedef typename Parent::Graph Graph;
typedef typename Parent::Value Value;
Modified: hugo/trunk/src/lemon/default_map.h
==============================================================================
--- hugo/trunk/src/lemon/default_map.h (original)
+++ hugo/trunk/src/lemon/default_map.h Sat Mar 26 00:31:57 2005
@@ -42,66 +42,66 @@
- template <typename _Graph, typename _Item, typename _ItemIt, typename _Value>
+ template <typename _Graph, typename _Item, typename _Value>
struct DefaultMapSelector {
- typedef ArrayMap<_Graph, _Item, _ItemIt, _Value> Map;
+ typedef ArrayMap<_Graph, _Item, _Value> Map;
};
// bool
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, bool> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, bool> {
typedef VectorMap<_Graph, _Item, bool> Map;
};
// char
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, char> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, char> {
typedef VectorMap<_Graph, _Item, char> Map;
};
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed char> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, signed char> {
typedef VectorMap<_Graph, _Item, signed char> Map;
};
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned char> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, unsigned char> {
typedef VectorMap<_Graph, _Item, unsigned char> Map;
};
// int
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed int> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, signed int> {
typedef VectorMap<_Graph, _Item, signed int> Map;
};
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned int> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, unsigned int> {
typedef VectorMap<_Graph, _Item, unsigned int> Map;
};
// short
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed short> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, signed short> {
typedef VectorMap<_Graph, _Item, signed short> Map;
};
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned short> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, unsigned short> {
typedef VectorMap<_Graph, _Item, unsigned short> Map;
};
// long
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed long> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, signed long> {
typedef VectorMap<_Graph, _Item, signed long> Map;
};
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned long> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, unsigned long> {
typedef VectorMap<_Graph, _Item, unsigned long> Map;
};
@@ -109,42 +109,43 @@
// float
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, float> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, float> {
typedef VectorMap<_Graph, _Item, float> Map;
};
// double
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, double> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, double> {
typedef VectorMap<_Graph, _Item, double> Map;
};
// long double
- template <typename _Graph, typename _Item, typename _ItemIt>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, long double> {
+ template <typename _Graph, typename _Item>
+ struct DefaultMapSelector<_Graph, _Item, long double> {
typedef VectorMap<_Graph, _Item, long double> Map;
};
// pointer
- template <typename _Graph, typename _Item, typename _ItemIt, typename _Ptr>
- struct DefaultMapSelector<_Graph, _Item, _ItemIt, _Ptr*> {
+ template <typename _Graph, typename _Item, typename _Ptr>
+ struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
typedef VectorMap<_Graph, _Item, _Ptr*> Map;
};
- template <typename _Graph,
- typename _Item,
- typename _ItemIt,
- typename _Value>
- class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map {
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Value>
+ class DefaultMap
+ : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
public:
- typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map Parent;
- typedef DefaultMap<_Graph, _Item, _ItemIt, _Value> Map;
+ typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
+ typedef DefaultMap<_Graph, _Item, _Value> Map;
typedef typename Parent::Graph Graph;
typedef typename Parent::Value Value;
@@ -170,10 +171,11 @@
template <typename _Value>
- class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
+ class NodeMap
+ : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
public:
typedef DefaultMappableGraphExtender Graph;
- typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
+ typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
NodeMap(const Graph& _g)
: Parent(_g) {}
@@ -182,10 +184,11 @@
};
template <typename _Value>
- class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
+ class EdgeMap
+ : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
public:
typedef DefaultMappableGraphExtender Graph;
- typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
+ typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
EdgeMap(const Graph& _g)
: Parent(_g) {}
@@ -204,14 +207,14 @@
typedef DefaultMappableGraphExtender<_Base> Parent;
typedef typename Parent::UndirEdge UndirEdge;
- typedef typename Parent::UndirEdgeIt UndirEdgeIt;
template <typename _Value>
- class UndirEdgeMap :
- public DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> {
+ class UndirEdgeMap
+ : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
public:
typedef MappableUndirGraphExtender Graph;
- typedef DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> Parent;
+ typedef IterableMapExtender<
+ DefaultMap<Graph, UndirEdge, _Value> > Parent;
UndirEdgeMap(const Graph& _g)
: Parent(_g) {}
Modified: hugo/trunk/src/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/src/lemon/graph_utils.h (original)
+++ hugo/trunk/src/lemon/graph_utils.h Sat Mar 26 00:31:57 2005
@@ -21,7 +21,6 @@
#include <lemon/invalid.h>
#include <lemon/utility.h>
-#include <lemon/map_utils.h>
///\ingroup gutils
///\file
@@ -34,8 +33,8 @@
namespace lemon {
-/// \addtogroup gutils
-/// @{
+ /// \addtogroup gutils
+ /// @{
/// \brief Function to count the items in the graph.
///
@@ -160,8 +159,8 @@
/// \bug Untested ...
template <typename Graph>
typename Graph::Edge findEdge(const Graph &g,
- typename Graph::Node u, typename Graph::Node v,
- typename Graph::Edge prev = INVALID)
+ typename Graph::Node u, typename Graph::Node v,
+ typename Graph::Edge prev = INVALID)
{
typename Graph::OutEdgeIt e(g,prev);
// if(prev==INVALID) g.first(e,u);
@@ -225,46 +224,51 @@
edgeCopy(_d, _s, _nb, _eb);
}
- template <
+ template <
typename _DestinationGraph,
typename _SourceGraph,
typename _NodeBijection
=typename _SourceGraph::template NodeMap<typename _DestinationGraph::Node>,
typename _EdgeBijection
- =typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
- >
- class GraphCopy {
- public:
+ = typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
+ >
+ class GraphCopy {
+ public:
+
+ typedef _DestinationGraph DestinationGraph;
+ typedef _SourceGraph SourceGraph;
- typedef _DestinationGraph DestinationGraph;
- typedef _SourceGraph SourceGraph;
+ typedef _NodeBijection NodeBijection;
+ typedef _EdgeBijection EdgeBijection;
+
+ protected:
+
+ NodeBijection node_bijection;
+ EdgeBijection edge_bijection;
- typedef _NodeBijection NodeBijection;
- typedef _EdgeBijection EdgeBijection;
+ public:
+
+ GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
+ copyGraph(_d, _s, node_bijection, edge_bijection);
+ }
+
+ const NodeBijection& getNodeBijection() const {
+ return node_bijection;
+ }
- protected:
+ const EdgeBijection& getEdgeBijection() const {
+ return edge_bijection;
+ }
+
+ };
- NodeBijection node_bijection;
- EdgeBijection edge_bijection;
- public:
-
- GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
- copyGraph(_d, _s, node_bijection, edge_bijection);
- }
-
- const NodeBijection& getNodeBijection() const {
- return node_bijection;
- }
-
- const EdgeBijection& getEdgeBijection() const {
- return edge_bijection;
- }
-
- };
+ template <typename _Graph, typename _Item>
+ class ItemSetTraits {
+ };
template <typename _Graph>
- class GraphNodeSet {
+ class ItemSetTraits<_Graph, typename _Graph::Node> {
public:
typedef _Graph Graph;
@@ -283,14 +287,10 @@
: Parent(_graph, _value) {}
};
- typedef IdMap<Graph, Item> IdMap;
-
- private:
- Graph* graph;
};
template <typename _Graph>
- class GraphEdgeSet {
+ class ItemSetTraits<_Graph, typename _Graph::Edge> {
public:
typedef _Graph Graph;
@@ -309,12 +309,29 @@
: Parent(_graph, _value) {}
};
- typedef IdMap<Graph, Item> IdMap;
-
- private:
- Graph* graph;
};
+ template <typename _Graph>
+ class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
+ public:
+
+ typedef _Graph Graph;
+
+ typedef typename Graph::UndirEdge Item;
+ typedef typename Graph::UndirEdgeIt ItemIt;
+
+ template <typename _Value>
+ class Map : public Graph::template UndirEdgeMap<_Value> {
+ public:
+ typedef typename Graph::template UndirEdgeMap<_Value> Parent;
+ typedef typename Parent::Value Value;
+
+ Map(const Graph& _graph) : Parent(_graph) {}
+ Map(const Graph& _graph, const Value& _value)
+ : Parent(_graph, _value) {}
+ };
+
+ };
/// @}
Modified: hugo/trunk/src/lemon/map_iterator.h
==============================================================================
--- hugo/trunk/src/lemon/map_iterator.h (original)
+++ hugo/trunk/src/lemon/map_iterator.h Sat Mar 26 00:31:57 2005
@@ -20,6 +20,7 @@
#include <iterator>
#include <lemon/extended_pair.h>
+#include <lemon/map_utils.h>
///\ingroup graphmaps
///\file
@@ -35,39 +36,23 @@
* simple step functions and equality operators.
*/
- template <typename Map>
+ template <
+ typename _Graph,
+ typename _Item>
class MapIteratorBase {
- public:
+ protected:
/// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
-
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
-
- protected:
-
- KeyIt it;
+ ItemIt it;
/// Default constructor.
MapIteratorBase() {}
- /// KeyIt initialized MapIteratorBase constructor.
- MapIteratorBase(const KeyIt pit) : it(pit) {}
+ /// ItemIt initialized MapIteratorBase constructor.
+ MapIteratorBase(const ItemIt _it) : it(_it) {}
public:
@@ -77,330 +62,333 @@
}
/// The equality operator of the map.
- bool operator==(const MapIteratorBase& pit) const {
- return pit.it == it;
+ bool operator==(const MapIteratorBase& _it) const {
+ return _it.it == it;
}
/// The not-equality operator of the map.
- bool operator!=(const MapIteratorBase& pit) const {
- return !(*this == pit);
+ bool operator!=(const MapIteratorBase& _it) const {
+ return !(*this == _it);
}
};
- template <typename Map> class MapConstIterator;
+
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapConstIterator;
/** Compatible iterator with the stl maps' iterators.
* It iterates on pairs of a key and a value.
*/
- template <typename Map>
- class MapIterator : public MapIteratorBase<Map> {
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapIterator : public MapIteratorBase<_Graph, _Item> {
- friend class MapConstIterator<Map>;
+ friend class MapConstIterator<_Graph, _Item, _Map>;
public:
/// The iterator base class.
- typedef MapIteratorBase<Map> Base;
+ typedef MapIteratorBase<_Graph, _Item> Parent;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef _Item Item;
+ typedef _Map Map;
+ typedef _Graph Graph;
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
+ protected:
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
+ typedef typename Parent::ItemIt ItemIt;
+
+ typedef typename ReferenceMapTraits<_Map>::Value MapValue;
+ typedef typename ReferenceMapTraits<_Map>::Reference MapReference;
public:
/// The value type of the iterator.
- typedef extended_pair<Key, const Key&,
- Value, const Value&> PairValue;
+ typedef extended_pair<Item, const Item&,
+ MapValue, const MapValue&> Value;
/// The reference type of the iterator.
- typedef extended_pair<const Key&, const Key&,
- Reference, Reference> PairReference;
+ typedef extended_pair<const Item&, const Item&,
+ MapReference, MapReference> Reference;
/// Default constructor.
MapIterator() {}
/// Constructor to initalize the iterators returned
/// by the begin() and end().
- MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
+ MapIterator(Map& _map, const ItemIt& _it)
+ : Parent(_it), map(&_map) {}
/// Dereference operator for the iterator.
- PairReference operator*() {
- return PairReference(Base::it, (*map)[Base::it]);
+ Reference operator*() {
+ return Reference(Parent::it, (*map)[Parent::it]);
}
/// The pointer type of the iterator.
- class PairPointer {
+ class Pointer {
friend class MapIterator;
- private:
- PairReference data;
- PairPointer(const Key& key, Reference val)
- : data(key, val) {}
+ protected:
+ Reference data;
+ Pointer(const Item& item, MapReference val)
+ : data(item, val) {}
public:
- PairReference* operator->() {return &data;}
+ Reference* operator->() {return &data;}
};
/// Arrow operator for the iterator.
- PairPointer operator->() {
- return PairPointer(Base::it, ((*map)[Base::it]));
+ Pointer operator->() {
+ return Pointer(Parent::it, (*map)[Parent::it]);
}
/// The pre increment operator of the iterator.
MapIterator& operator++() {
- Base::increment();
+ Parent::increment();
return *this;
}
/// The post increment operator of the iterator.
MapIterator operator++(int) {
MapIterator tmp(*this);
- Base::increment();
+ Parent::increment();
return tmp;
}
- private:
+ protected:
+
Map* map;
public:
// STL compatibility typedefs.
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
- typedef PairValue value_type;
- typedef PairReference reference;
- typedef PairPointer pointer;
+ typedef Value value_type;
+ typedef Reference reference;
+ typedef Pointer pointer;
};
/** Compatible iterator with the stl maps' iterators.
* It iterates on pairs of a key and a value.
*/
- template <typename Map>
- class MapConstIterator : public MapIteratorBase<Map> {
-
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapConstIterator : public MapIteratorBase<_Graph, _Item> {
+
public:
/// The iterator base class.
- typedef MapIteratorBase<Map> Base;
+ typedef MapIteratorBase<_Graph, _Item> Parent;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
+ protected:
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
+ typedef typename Parent::ItemIt ItemIt;
- public:
+ typedef typename ReferenceMapTraits<_Map>::Value MapValue;
+ typedef typename ReferenceMapTraits<_Map>::ConstReference
+ MapReference;
+
+ public:
- /// Default constructor.
- MapConstIterator() {}
+ /// The value type of the iterator.
+ typedef extended_pair<Item, const Item&,
+ MapValue, const MapValue&> Value;
- /// Constructor to initalize the the iterators returned
- /// by the begin() and end().
- MapConstIterator(const Map& pmap, const KeyIt& pit)
- : Base(pit), map(&pmap) {}
-
- /// Constructor to create const iterator from a non const.
- MapConstIterator(const MapIterator<Map>& pit) {
- Base::it = pit.Base::it;
- map = pit.map;
- }
+ /// The reference type of the iterator.
+ typedef extended_pair<const Item&, const Item&,
+ MapReference, MapReference> Reference;
- /// The value type of the iterator.
- typedef extended_pair<Key, const Key&,
- Value, const Value&> PairValue;
+ /// Default constructor.
+ MapConstIterator() {}
- /// The reference type of map.
- typedef extended_pair<const Key&, const Key&,
- ConstReference, ConstReference> PairReference;
+ /// Constructor to initalize the iterators returned
+ /// by the begin() and end().
+ MapConstIterator(const Map& _map, const ItemIt& _it)
+ : Parent(_it), map(&_map) {}
/// Dereference operator for the iterator.
- PairReference operator*() {
- return PairReference(Base::it, (*map)[Base::it]);
+ Reference operator*() {
+ return Reference(Parent::it, (*map)[Parent::it]);
}
/// The pointer type of the iterator.
- class PairPointer {
+ class Pointer {
friend class MapConstIterator;
- private:
- PairReference data;
- PairPointer(const Key& key, ConstReference val)
- : data(key, val) {}
+ protected:
+ Reference data;
+ Pointer(const Item& item, MapReference val)
+ : data(item, val) {}
public:
- PairReference* operator->() {return &data;}
+ Reference* operator->() {return &data;}
};
/// Arrow operator for the iterator.
- PairPointer operator->() {
- return PairPointer(Base::it, (*map)[Base::it]);
+ Pointer operator->() {
+ return Pointer(Parent::it, ((*map)[Parent::it]));
}
-
+
/// The pre increment operator of the iterator.
MapConstIterator& operator++() {
- Base::increment();
+ Parent::increment();
return *this;
}
/// The post increment operator of the iterator.
MapConstIterator operator++(int) {
MapConstIterator tmp(*this);
- Base::increment();
+ Parent::increment();
return tmp;
}
- private:
+ protected:
const Map* map;
public:
// STL compatibility typedefs.
- typedef std::input_iterator_tag iterator_category;
+ typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
- typedef PairValue value_type;
- typedef PairReference reference;
- typedef PairPointer pointer;
+ typedef Value value_type;
+ typedef Reference reference;
+ typedef Pointer pointer;
};
-
- /** The class makes the KeyIt to an stl compatible iterator
+
+ /** The class makes the ItemIt to an stl compatible iterator
* with dereferencing operator.
*/
- template <typename Map>
- class MapKeyIterator : public MapIteratorBase<Map> {
+ template <
+ typename _Graph,
+ typename _Item>
+ class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> {
public:
/// The iterator base class.
- typedef MapIteratorBase<Map> Base;
+ typedef MapIteratorBase<_Graph, _Item> Parent;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
+ typedef _Graph Graph;
+ typedef _Item Item;
+
+ protected:
/// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef typename Parent::ItemIt ItemIt;
public:
+ typedef Item Value;
+ typedef const Item& Reference;
+ typedef const Item* Pointer;
+
/// Default constructor.
- MapKeyIterator() {}
+ MapConstKeyIterator() {}
- /// KeyIt initialized iterator.
- MapKeyIterator(const KeyIt& pit) : Base(pit) {}
+ /// ItemIt initialized iterator.
+ MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {}
/// The pre increment operator of the iterator.
- MapKeyIterator& operator++() {
- Base::increment();
+ MapConstKeyIterator& operator++() {
+ Parent::increment();
return *this;
}
/// The post increment operator of the iterator.
- MapKeyIterator operator++(int) {
- MapKeyIterator tmp(*this);
- Base::increment();
+ MapConstKeyIterator operator++(int) {
+ MapConstKeyIterator tmp(*this);
+ Parent::increment();
return tmp;
}
/// The dereferencing operator of the iterator.
- Key operator*() const {
- return static_cast<Key>(Base::it);
+ Item operator*() const {
+ return static_cast<Item>(Parent::it);
}
public:
// STL compatibility typedefs.
typedef std::input_iterator_tag iterator_category;
typedef int difference_type;
- typedef Key value_type;
- typedef const Key& reference;
- typedef const Key* pointer;
+ typedef Value value_type;
+ typedef Reference reference;
+ typedef Pointer pointer;
};
- template <typename Map> class MapConstValueIterator;
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapConstValueIterator;
/** MapValueIterator creates an stl compatible iterator
* for the values.
*/
- template <typename Map>
- class MapValueIterator : public MapIteratorBase<Map> {
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapValueIterator : public MapIteratorBase<_Graph, _Item> {
- friend class MapConstValueIterator<Map>;
+ friend class MapConstValueIterator<_Graph, _Item, _Map>;
public:
/// The iterator base class.
- typedef MapIteratorBase<Map> Base;
+ typedef MapIteratorBase<_Graph, _Item> Parent;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
+ protected:
+
+ /// The iterator to iterate on the keys.
+ typedef typename Parent::ItemIt ItemIt;
/// The value type of the iterator.
- typedef typename Map::Value Value;
+ typedef typename ReferenceMapTraits<Map>::Value MapValue;
/// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
-
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
+ typedef typename ReferenceMapTraits<Map>::Reference MapReference;
/// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
-
- private:
-
- Map* map;
+ typedef typename ReferenceMapTraits<Map>::Pointer MapPointer;
public:
+ typedef MapValue Value;
+ typedef MapReference Reference;
+ typedef MapPointer Pointer;
+
/// Default constructor.
MapValueIterator() {}
- /// Map and KeyIt initialized iterator.
- MapValueIterator(Map& pmap, const KeyIt& pit)
- : Base(pit), map(&pmap) {}
+ /// Map and ItemIt initialized iterator.
+ MapValueIterator(Map& _map, const ItemIt& _it)
+ : Parent(_it), map(&_map) {}
/// The pre increment operator of the iterator.
MapValueIterator& operator++() {
- Base::increment();
+ Parent::increment();
return *this;
}
/// The post increment operator of the iterator.
MapValueIterator operator++(int) {
MapValueIterator tmp(*this);
- Base::increment();
+ Parent::increment();
return tmp;
}
/// The dereferencing operator of the iterator.
Reference operator*() const {
- return (*map)[Base::it];
+ return (*map)[Parent::it];
}
/// The arrow operator of the iterator.
@@ -408,6 +396,10 @@
return &(operator*());
}
+ protected:
+
+ Map* map;
+
public:
// STL compatibility typedefs.
typedef std::forward_iterator_tag iterator_category;
@@ -418,133 +410,130 @@
};
/** MapValueIterator creates an stl compatible iterator
- * for the const values.
+ * for the values.
*/
-
- template <typename Map>
- class MapConstValueIterator : public MapIteratorBase<Map> {
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map>
+ class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> {
public:
/// The iterator base class.
- typedef MapIteratorBase<Map> Base;
+ typedef MapIteratorBase<_Graph, _Item> Parent;
+
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
+
+ protected:
- /// The key type of the iterator.
- typedef typename Map::Key Key;
/// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ typedef typename Parent::ItemIt ItemIt;
/// The value type of the iterator.
- typedef typename Map::Value Value;
+ typedef typename ReferenceMapTraits<Map>::Value MapValue;
/// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
-
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
+ typedef typename ReferenceMapTraits<Map>::ConstReference MapReference;
/// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
-
- private:
-
- const Map* map;
+ typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer;
public:
+ typedef MapValue Value;
+ typedef MapReference Reference;
+ typedef MapPointer Pointer;
+
/// Default constructor.
MapConstValueIterator() {}
- /// Constructor to create const iterator from a non const.
- MapConstValueIterator(const MapValueIterator<Map>& pit) {
- Base::it = pit.Base::it;
- map = pit.map;
- }
-
- /// Map and KeyIt initialized iterator.
- MapConstValueIterator(const Map& pmap, const KeyIt& pit)
- : Base(pit), map(&pmap) {}
+ /// Map and ItemIt initialized iterator.
+ MapConstValueIterator(const Map& _map, const ItemIt& _it)
+ : Parent(_it), map(&_map) {}
+
/// The pre increment operator of the iterator.
MapConstValueIterator& operator++() {
- Base::increment();
+ Parent::increment();
return *this;
}
/// The post increment operator of the iterator.
MapConstValueIterator operator++(int) {
MapConstValueIterator tmp(*this);
- Base::increment();
+ Parent::increment();
return tmp;
}
/// The dereferencing operator of the iterator.
- ConstReference operator*() const {
- return (*map)[Base::it];
+ Reference operator*() const {
+ return (*map)[Parent::it];
}
/// The arrow operator of the iterator.
- ConstPointer operator->() const {
+ Pointer operator->() const {
return &(operator*());
}
+ protected:
+
+ const Map* map;
+
public:
// STL compatibility typedefs.
- typedef std::input_iterator_tag iterator_category;
+ typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
typedef Value value_type;
- typedef ConstReference reference;
- typedef ConstPointer pointer;
+ typedef Reference reference;
+ typedef Pointer pointer;
};
/** This class makes from a map an iteratable set
* which contains all the keys of the map.
*/
- template <typename Map>
+ template <typename _Graph, typename _Item>
class MapConstKeySet {
- const Map* map;
-
public:
+ typedef _Graph Graph;
/// The key type of the iterator.
- typedef typename Map::Key Key;
+ typedef _Item Item;
/// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ protected:
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
+ typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
+ public:
/// The map initialized const key set.
- MapConstKeySet(const Map& pmap) : map(&pmap) {}
+ MapConstKeySet(const Graph& _graph) : graph(&_graph) {}
/// The const iterator of the set.
- typedef MapKeyIterator<Map> ConstIterator;
+ typedef MapConstKeyIterator<_Graph, _Item> ConstIterator;
+
+ typedef typename ConstIterator::Value Value;
+ /// The reference type of the iterator.
+ typedef typename ConstIterator::Reference ConstReference;
+ /// The pointer type of the iterator.
+ typedef typename ConstIterator::Pointer ConstPointer;
/// It gives back the const iterator pointed to the first element.
ConstIterator begin() const {
- return ConstIterator(KeyIt(*map->getGraph()));
+ return ConstIterator(ItemIt(*graph));
}
/// It gives back the const iterator pointed to the first ivalid element.
ConstIterator end() const {
- return ConstIterator(KeyIt(INVALID));
+ return ConstIterator(ItemIt(INVALID));
}
+
+ protected:
+
+ const Graph* graph;
public:
// STL compatibility typedefs.
@@ -559,49 +548,48 @@
* which contains all the values of the map.
* The values cannot be modified.
*/
- template <typename Map>
+ template <typename _Graph, typename _Item, typename _Map>
class MapConstValueSet {
- const Map* map;
-
public:
+
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
-
+ protected:
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
+ /// The iterator to iterate on the keys.
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
+ public:
/// The map initialized const value set.
- MapConstValueSet(const Map& pmap) : map(&pmap) {}
+ MapConstValueSet(const Graph& _graph, const Map& _map)
+ : graph(&_graph), map(&_map) {}
/// The const iterator of the set.
- typedef MapConstValueIterator<Map> ConstIterator;
+ typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
+
+ typedef typename ConstIterator::Value Value;
+ typedef typename ConstIterator::Reference ConstReference;
+ typedef typename ConstIterator::Pointer ConstPointer;
/// It gives back the const iterator pointed to the first element.
ConstIterator begin() const {
- return ConstIterator(*map, KeyIt(*map->getGraph()));
+ return ConstIterator(*map, ItemIt(*graph));
}
/// It gives back the const iterator pointed to the first invalid element.
ConstIterator end() const {
- return ConstIterator(*map, KeyIt(INVALID));
+ return ConstIterator(*map, ItemIt(INVALID));
}
+ protected:
+
+ const Map* map;
+ const Graph * graph;
+
public:
// STL compatibility typedefs.
typedef Value value_type;
@@ -616,61 +604,137 @@
* which contains all the values of the map.
* The values can be modified.
*/
- template <typename Map>
+ template <typename _Graph, typename _Item, typename _Map>
class MapValueSet {
+ public:
+
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
+
+ protected:
+
+ /// The iterator to iterate on the keys.
+ typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
+
+ public:
+
+ /// The map initialized const value set.
+ MapValueSet(const Graph& _graph, Map& _map)
+ : graph(&_graph), map(&_map) {}
+
+ /// The const iterator of the set.
+ typedef MapValueIterator<_Graph, _Item, _Map> Iterator;
+ /// The const iterator of the set.
+ typedef MapConstValueIterator<_Graph, _Item, _Map> ConstIterator;
+
+ typedef typename ConstIterator::Value Value;
+ typedef typename Iterator::Reference Reference;
+ typedef typename Iterator::Pointer Pointer;
+ typedef typename ConstIterator::Reference ConstReference;
+ typedef typename ConstIterator::Pointer ConstPointer;
+
+ /// It gives back the const iterator pointed to the first element.
+ ConstIterator begin() const {
+ return ConstIterator(*map, ItemIt(*graph));
+ }
+
+ /// It gives back the const iterator pointed to the first invalid element.
+ ConstIterator end() const {
+ return ConstIterator(*map, ItemIt(INVALID));
+ }
+
+ /// It gives back the iterator pointed to the first element.
+ Iterator begin() {
+ return Iterator(*map, ItemIt(*graph));
+ }
+
+ /// It gives back the iterator pointed to the first invalid element.
+ Iterator end() {
+ return Iterator(*map, ItemIt(INVALID));
+ }
+
+ protected:
+
Map* map;
+ const Graph * graph;
public:
+ // STL compatibility typedefs.
+ typedef Value value_type;
+ typedef Iterator iterator;
+ typedef ConstIterator const_iterator;
+ typedef Reference reference;
+ typedef ConstReference const_reference;
+ typedef Pointer pointer;
+ typedef ConstPointer const_pointer;
+ typedef int difference_type;
- /// The key type of the iterator.
- typedef typename Map::Key Key;
- /// The iterator to iterate on the keys.
- typedef typename Map::KeyIt KeyIt;
+ };
+ /** This class makes from a map an iteratable set
+ * which contains all the values of the map.
+ * The values can be modified.
+ */
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map
+ >
+ class MapSet {
+ public:
- /// The value type of the iterator.
- typedef typename Map::Value Value;
- /// The reference type of the iterator.
- typedef typename Map::Reference Reference;
- /// The pointer type of the iterator.
- typedef typename Map::Pointer Pointer;
+ typedef _Graph Graph;
+ typedef _Item Item;
+ typedef _Map Map;
- /// The const value type of the iterator.
- typedef typename Map::ConstValue ConstValue;
- /// The const reference type of the iterator.
- typedef typename Map::ConstReference ConstReference;
- /// The pointer type of the iterator.
- typedef typename Map::ConstPointer ConstPointer;
+ protected:
+
+ typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
+
+ public:
/// The map initialized value set.
- MapValueSet(Map& pmap) : map(&pmap) {}
+ MapSet(const Graph& _graph, Map& _map) : graph(&_graph), map(&_map) {}
/// The const iterator of the set.
- typedef MapConstValueIterator<Map> ConstIterator;
+ typedef MapIterator<_Graph, _Item, _Map> Iterator;
+ typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
+
+ typedef typename ConstIterator::Value Value;
+ typedef typename Iterator::Reference Reference;
+ typedef typename Iterator::Pointer Pointer;
+ typedef typename ConstIterator::Reference ConstReference;
+ typedef typename ConstIterator::Pointer ConstPointer;
+
/// It gives back the const iterator pointed to the first element.
ConstIterator begin() const {
- return ConstIterator(*map, KeyIt(*map->getGraph()));
+ return ConstIterator(*map, ItemIt(*graph));
}
/// It gives back the const iterator pointed to the first invalid element.
ConstIterator end() const {
- return ConstIterator(*map, KeyIt(INVALID));
+ return ConstIterator(*map, ItemIt(INVALID));
}
/// The iterator of the set.
- typedef MapValueIterator<Map> Iterator;
/// It gives back the iterator pointed to the first element.
Iterator begin() {
- return Iterator(*map, KeyIt(*map->getGraph()));
+ return Iterator(*map, ItemIt(*graph));
}
/// It gives back the iterator pointed to the first invalid element.
Iterator end() {
- return Iterator(*map, KeyIt(INVALID));
+ return Iterator(*map, ItemIt(INVALID));
}
+
+ protected:
+
+ const Graph* graph;
+ Map* map;
public:
// STL compatibility typedefs.
@@ -685,6 +749,105 @@
};
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Map
+ >
+ class ConstMapSet {
+
+ typedef _Graph Graph;
+ typedef _Map Map;
+
+ const Graph* graph;
+ const Map* map;
+
+ public:
+
+ typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt;
+
+
+ /// The map initialized value set.
+ ConstMapSet(const Graph& _graph, const Map& _map)
+ : graph(&_graph), map(&_map) {}
+
+ /// The const iterator of the set.
+ typedef MapConstIterator<_Graph, _Item, _Map> ConstIterator;
+
+ typedef typename ConstIterator::Value Value;
+ typedef typename ConstIterator::Reference ConstReference;
+ typedef typename ConstIterator::Pointer ConstPointer;
+
+
+ /// It gives back the const iterator pointed to the first element.
+ ConstIterator begin() const {
+ return ConstIterator(*map, ItemIt(*graph));
+ }
+
+ /// It gives back the const iterator pointed to the first invalid element.
+ ConstIterator end() const {
+ return ConstIterator(*map, ItemIt(INVALID));
+ }
+
+ public:
+ // STL compatibility typedefs.
+ typedef Value value_type;
+ typedef ConstIterator const_iterator;
+ typedef ConstReference const_reference;
+ typedef ConstPointer const_pointer;
+ typedef int difference_type;
+
+ };
+
+ template <typename _Map>
+ class IterableMapExtender : public _Map {
+ public:
+
+ typedef _Map Parent;
+ typedef Parent Map;
+ typedef typename Map::Graph Graph;
+ typedef typename Map::Key Item;
+ typedef typename Map::Value Value;
+
+ typedef MapSet<Graph, Item, Map> MapSet;
+
+ IterableMapExtender() : Parent() {}
+
+ IterableMapExtender(const Graph& graph) : Parent(graph) {}
+
+ IterableMapExtender(const Graph& graph, const Value& value)
+ : Parent(graph, value) {}
+
+ MapSet mapSet() {
+ return MapSet(*Parent::getGraph(), *this);
+ }
+
+ typedef ConstMapSet<Graph, Item, Map> ConstMapSet;
+
+ ConstMapSet mapSet() const {
+ return ConstMapSet(*Parent::getGraph(), *this);
+ }
+
+ typedef MapConstKeySet<Graph, Item> ConstKeySet;
+
+ ConstKeySet keySet() const {
+ return ConstKeySet(*Parent::getGraph());
+ }
+
+ typedef MapValueSet<Graph, Item, Map> ValueSet;
+
+ ValueSet valueSet() {
+ return ValueSet(*Parent::getGraph(), *this);
+ }
+
+ typedef MapConstValueSet<Graph, Item, Map> ConstValueSet;
+
+ ConstValueSet valueSet() const {
+ return ConstValueSet(*Parent::getGraph(), *this);
+ }
+
+ };
+
/// @}
}
Modified: hugo/trunk/src/lemon/map_utils.h
==============================================================================
--- hugo/trunk/src/lemon/map_utils.h (original)
+++ hugo/trunk/src/lemon/map_utils.h Sat Mar 26 00:31:57 2005
@@ -25,11 +25,35 @@
#include <map>
#include <vector>
+#include <lemon/graph_utils.h>
+
namespace lemon {
/// \addtogroup mutils
/// @{
+
+ template <typename Map, typename Enable = void>
+ struct ReferenceMapTraits {
+ typedef typename Map::Value Value;
+ typedef typename Map::Value& Reference;
+ typedef const typename Map::Value& ConstReference;
+ typedef typename Map::Value* Pointer;
+ typedef const typename Map::Value* ConstPointer;
+ };
+
+ template <typename Map>
+ struct ReferenceMapTraits<
+ Map,
+ typename enable_if<typename Map::FullTypeTag, void>::type
+ > {
+ typedef typename Map::Value Value;
+ typedef typename Map::Reference Reference;
+ typedef typename Map::ConstReference ConstReference;
+ typedef typename Map::Pointer Pointer;
+ typedef typename Map::ConstPointer ConstPointer;
+ };
+
/// \brief General inversable map type.
/// This type provides simple inversable map functions.
@@ -39,19 +63,23 @@
/// \param _Graph The graph type.
/// \param _Map The map to extend with inversable functionality.
template <
- typename _Graph,
- typename _Map
+ typename _Graph,
+ typename _Item,
+ typename _Value,
+ typename _Map
+ = typename ItemSetTraits<_Graph, _Item>::template Map<_Value>
>
class InversableMap : protected _Map {
public:
- typedef _Graph Graph;
-
+
typedef _Map Map;
- /// The key type of InversableMap (Node, Edge, UndirEdge).
+ typedef _Graph Graph;
+ /// The key type of InversableMap (Node, Edge, UndirEdge).
typedef typename _Map::Key Key;
/// The value type of the InversableMap.
typedef typename _Map::Value Value;
+
typedef std::map<Value, Key> InverseMap;
typedef typename _Map::ConstReference ConstReference;
@@ -64,7 +92,7 @@
/// \brief The setter function of the map.
///
- /// It sets the map and the inverse map to given key-value pair.
+
void set(const Key& key, const Value& val) {
Value oldval = Map::operator[](key);
typename InverseMap::iterator it = invMap.find(oldval);
@@ -140,7 +168,7 @@
template <
typename _Graph,
typename _Item,
- typename _Map
+ typename _Map = typename ItemSetTraits<_Graph, _Item>::template Map<int>
>
class DescriptorMap : protected _Map {
@@ -237,6 +265,7 @@
typedef _Graph Graph;
typedef int Value;
typedef _Item Item;
+ typedef _Item Key;
/// \brief The class represents the inverse of the map.
///
Modified: hugo/trunk/src/lemon/vector_map.h
==============================================================================
--- hugo/trunk/src/lemon/vector_map.h (original)
+++ hugo/trunk/src/lemon/vector_map.h Sat Mar 26 00:31:57 2005
@@ -20,6 +20,8 @@
#include <vector>
#include <algorithm>
+#include <lemon/utility.h>
+#include <lemon/map_iterator.h>
#include <lemon/alteration_notifier.h>
///\ingroup graphmaps
@@ -44,9 +46,11 @@
/// \author Balazs Dezso
- template <typename _Graph,
- typename _Item,
- typename _Value>
+ template <
+ typename _Graph,
+ typename _Item,
+ typename _Value
+ >
class VectorMap : public AlterationNotifier<_Item>::ObserverBase {
public:
@@ -83,6 +87,8 @@
/// The pointer type of the map;
typedef typename Container::const_pointer ConstPointer;
+ typedef True FullTypeTag;
+
/// Constructor to attach the new map into the registry.
/// It construates a map and attachs it into the registry.
@@ -205,7 +211,7 @@
void clear() {
container.clear();
}
-
+
private:
Container container;
@@ -232,15 +238,15 @@
typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
-
template <typename _Value>
- class NodeMap : public VectorMap<Graph, Node, _Value> {
+ class NodeMap :
+ public IterableMapExtender<VectorMap<Graph, Node, _Value> > {
public:
typedef VectorMappableGraphExtender<_Base> Graph;
typedef typename Graph::Node Node;
- typedef VectorMap<Graph, Node, _Value> Parent;
+ typedef IterableMapExtender<VectorMap<Graph, Node, _Value> > Parent;
//typedef typename Parent::Graph Graph;
typedef typename Parent::Value Value;
@@ -253,13 +259,14 @@
};
template <typename _Value>
- class EdgeMap : public VectorMap<Graph, Edge, _Value> {
+ class EdgeMap
+ : public IterableMapExtender<VectorMap<Graph, Edge, _Value> > {
public:
typedef VectorMappableGraphExtender<_Base> Graph;
typedef typename Graph::Edge Edge;
- typedef VectorMap<Graph, Edge, _Value> Parent;
+ typedef IterableMapExtender<VectorMap<Graph, Edge, _Value> > Parent;
//typedef typename Parent::Graph Graph;
typedef typename Parent::Value Value;
Added: hugo/trunk/src/work/deba/iterator_test.cpp
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/deba/iterator_test.cpp Sat Mar 26 00:31:57 2005
@@ -0,0 +1,115 @@
+#include <iostream>
+#include <algorithm>
+#include <iterator>
+#include <functional>
+#include <lemon/list_graph.h>
+#include <lemon/map_iterator.h>
+#include <lemon/graph_reader.h>
+#include <lemon/maps.h>
+
+using namespace std;
+using namespace lemon;
+
+template <typename F, typename G>
+struct unary_compose {
+ typedef typename G::argument_type argument_type;
+ typedef typename F::result_type result_type;
+
+ unary_compose(const F& _f, const G& _g) : f(_f), g(_g) {}
+
+ result_type operator()(const argument_type& x) {
+ return f(g(x));
+ }
+
+private:
+ F f;
+ G g;
+};
+
+template <typename F, typename G>
+unary_compose<F, G> compose1(const F& f, const G& g) {
+ return unary_compose<F, G>(f, g);
+}
+
+
+
+
+template <typename T>
+struct Second {
+ typedef T argument_type;
+ typedef typename T::second_type result_type;
+
+ typename T::second_type operator()(const T& t) const {
+ return t.second;
+ }
+};
+
+template <typename T>
+struct First {
+ typedef T argument_type;
+ typedef typename T::first_type result_type;
+ typename T::first_type operator()(const T& t) const {
+ return t.first;
+ }
+};
+
+
+int main() {
+
+ typedef ListGraph Graph;
+
+ typedef Graph::Edge Edge;
+ typedef Graph::Node Node;
+ typedef Graph::EdgeIt EdgeIt;
+ typedef Graph::NodeIt NodeIt;
+ typedef Graph::EdgeMap<int> LengthMap;
+
+ typedef IdMap<Graph, Edge> EdgeIdMap;
+
+ Graph graph;
+ LengthMap length(graph);
+
+ readGraph(std::cin, graph, length);
+
+ const LengthMap& constLength = length;
+
+ copy(length.valueSet().begin(), length.valueSet().end(),
+ ostream_iterator<int>(cout, " "));
+ cout << endl;
+
+
+ copy(constLength.valueSet().begin(), constLength.valueSet().end(),
+ ostream_iterator<int>(cout, " "));
+ cout << endl;
+
+
+ transform(constLength.keySet().begin(), constLength.keySet().end(),
+ ostream_iterator<int>(cout, " "),
+ MapFunctor<EdgeIdMap>(EdgeIdMap(graph)));
+ cout << endl;
+
+
+ transform(constLength.mapSet().begin(), constLength.mapSet().end(),
+ ostream_iterator<int>(cout, " "),
+ Second<LengthMap::MapSet::Value>());
+ cout << endl;
+
+ transform(constLength.mapSet().begin(), constLength.mapSet().end(),
+ ostream_iterator<int>(cout, " "),
+ compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
+ First<LengthMap::MapSet::Value>() ));
+ cout << endl;
+
+ transform(length.mapSet().begin(), length.mapSet().end(),
+ ostream_iterator<int>(cout, " "),
+ Second<LengthMap::MapSet::Value>());
+ cout << endl;
+
+ transform(length.mapSet().begin(), length.mapSet().end(),
+ ostream_iterator<int>(cout, " "),
+ compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
+ First<LengthMap::MapSet::Value>() ));
+ cout << endl;
+
+ return 0;
+}
Modified: hugo/trunk/src/work/deba/test.cpp
==============================================================================
--- hugo/trunk/src/work/deba/test.cpp (original)
+++ hugo/trunk/src/work/deba/test.cpp Sat Mar 26 00:31:57 2005
@@ -4,7 +4,7 @@
#include <lemon/utility.h>
-using namespace std;
+using namespace lemon;
/*
struct _EmptyList {
void write() const {}
@@ -57,31 +57,28 @@
class A {
public:
typedef int X;
+ typedef True XD;
};
class C {
};
-template <typename A>
-class TRUE {
-public:
- static const bool state = true;
-};
-template <typename _A>
+template <typename _A, bool _B = false>
class B {
public:
- typedef enable_if<A::X, int> state;
+ static const bool state = false;
};
-template <typename _A>
-class B<_A, void> {
+template <typename _A>
+class B<_A, typename enable_if<typename _A::XD, void>::type> {
public:
static const bool state = true;
};
+
int main() {
- printf("%s\n", B<A>::state(), true ? "true" : "false");
- printf("%s\n", B<C>::state(), true ? "true" : "false");
+ printf("%s\n", B<A>::state ? "true" : "false");
+ printf("%s\n", B<C>::state ? "true" : "false");
return 0;
}
More information about the Lemon-commits
mailing list