1.1 --- a/src/lemon/map_utils.h Fri Mar 25 22:11:28 2005 +0000
1.2 +++ b/src/lemon/map_utils.h Fri Mar 25 23:31:57 2005 +0000
1.3 @@ -25,11 +25,35 @@
1.4 #include <map>
1.5 #include <vector>
1.6
1.7 +#include <lemon/graph_utils.h>
1.8 +
1.9 namespace lemon {
1.10
1.11 /// \addtogroup mutils
1.12 /// @{
1.13
1.14 +
1.15 + template <typename Map, typename Enable = void>
1.16 + struct ReferenceMapTraits {
1.17 + typedef typename Map::Value Value;
1.18 + typedef typename Map::Value& Reference;
1.19 + typedef const typename Map::Value& ConstReference;
1.20 + typedef typename Map::Value* Pointer;
1.21 + typedef const typename Map::Value* ConstPointer;
1.22 + };
1.23 +
1.24 + template <typename Map>
1.25 + struct ReferenceMapTraits<
1.26 + Map,
1.27 + typename enable_if<typename Map::FullTypeTag, void>::type
1.28 + > {
1.29 + typedef typename Map::Value Value;
1.30 + typedef typename Map::Reference Reference;
1.31 + typedef typename Map::ConstReference ConstReference;
1.32 + typedef typename Map::Pointer Pointer;
1.33 + typedef typename Map::ConstPointer ConstPointer;
1.34 + };
1.35 +
1.36 /// \brief General inversable map type.
1.37
1.38 /// This type provides simple inversable map functions.
1.39 @@ -39,19 +63,23 @@
1.40 /// \param _Graph The graph type.
1.41 /// \param _Map The map to extend with inversable functionality.
1.42 template <
1.43 - typename _Graph,
1.44 - typename _Map
1.45 + typename _Graph,
1.46 + typename _Item,
1.47 + typename _Value,
1.48 + typename _Map
1.49 + = typename ItemSetTraits<_Graph, _Item>::template Map<_Value>
1.50 >
1.51 class InversableMap : protected _Map {
1.52
1.53 public:
1.54 +
1.55 + typedef _Map Map;
1.56 typedef _Graph Graph;
1.57 -
1.58 - typedef _Map Map;
1.59 - /// The key type of InversableMap (Node, Edge, UndirEdge).
1.60 + /// The key type of InversableMap (Node, Edge, UndirEdge).
1.61 typedef typename _Map::Key Key;
1.62 /// The value type of the InversableMap.
1.63 typedef typename _Map::Value Value;
1.64 +
1.65 typedef std::map<Value, Key> InverseMap;
1.66
1.67 typedef typename _Map::ConstReference ConstReference;
1.68 @@ -64,7 +92,7 @@
1.69
1.70 /// \brief The setter function of the map.
1.71 ///
1.72 - /// It sets the map and the inverse map to given key-value pair.
1.73 +
1.74 void set(const Key& key, const Value& val) {
1.75 Value oldval = Map::operator[](key);
1.76 typename InverseMap::iterator it = invMap.find(oldval);
1.77 @@ -140,7 +168,7 @@
1.78 template <
1.79 typename _Graph,
1.80 typename _Item,
1.81 - typename _Map
1.82 + typename _Map = typename ItemSetTraits<_Graph, _Item>::template Map<int>
1.83 >
1.84 class DescriptorMap : protected _Map {
1.85
1.86 @@ -237,6 +265,7 @@
1.87 typedef _Graph Graph;
1.88 typedef int Value;
1.89 typedef _Item Item;
1.90 + typedef _Item Key;
1.91
1.92 /// \brief The class represents the inverse of the map.
1.93 ///