00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef LEMON_BITS_MAP_EXTENDER_H
00020 #define LEMON_BITS_MAP_EXTENDER_H
00021
00022 #include <iterator>
00023
00024 #include <lemon/traits.h>
00025
00028
00029 namespace lemon {
00030
00031 template <typename _Map>
00032 class IterableMapExtender : public _Map {
00033 public:
00034
00035 typedef _Map Parent;
00036 typedef IterableMapExtender Map;
00037
00038
00039 typedef typename Parent::Graph Graph;
00040 typedef typename Parent::Key Item;
00041
00042 typedef typename Parent::Key Key;
00043 typedef typename Parent::Value Value;
00044
00045 class MapIt;
00046 class ConstMapIt;
00047
00048 friend class MapIt;
00049 friend class ConstMapIt;
00050
00051 protected:
00052
00053 using Parent::getGraph;
00054
00055 public:
00056
00057 IterableMapExtender(const Graph& graph) : Parent(graph) {}
00058
00059 IterableMapExtender(const Graph& graph, const Value& value)
00060 : Parent(graph, value) {}
00061
00062
00063 class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
00064 public:
00065
00066 typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
00067
00068 typedef typename Map::Value Value;
00069
00070 MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {}
00071
00072 typename MapTraits<Map>::ConstReturnValue operator*() const {
00073 return map[*this];
00074 }
00075
00076 typename MapTraits<Map>::ReturnValue operator*() {
00077 return map[*this];
00078 }
00079
00080 void set(const Value& value) {
00081 map.set(*this, value);
00082 }
00083
00084 protected:
00085 Map& map;
00086
00087 };
00088
00089 class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt {
00090 public:
00091
00092 typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
00093
00094 typedef typename Map::Value Value;
00095
00096 ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {}
00097
00098 typename MapTraits<Map>::ConstReturnValue operator*() const {
00099 return map[*this];
00100 }
00101 protected:
00102 const Map& map;
00103 };
00104
00105 class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt {
00106 public:
00107
00108 typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
00109
00110 ItemIt(Map& _map) : Parent(*_map.getGraph()) {}
00111
00112 };
00113 };
00114
00115 }
00116
00117 #endif