9 /** The VectorMapFactory template class is a factory class
10 * to create maps for the edge and nodes. This map factory
11 * use the std::vector to implement the container function.
13 * The template parameter is the MapRegistry that the maps
17 template <typename MapRegistry>
18 class VectorMapFactory {
21 /// The graph type of the maps.
22 typedef typename MapRegistry::Graph Graph;
23 /// The key type of the maps.
24 typedef typename MapRegistry::Key Key;
25 /// The iterator to iterate on the keys.
26 typedef typename MapRegistry::KeyIt KeyIt;
28 /// The MapBase of the Map which imlements the core regisitry function.
29 typedef typename MapRegistry::MapBase MapBase;
32 /** The template Map type.
35 class Map : public MapBase {
38 /// The value type of the map.
41 typedef std::vector<Value> Container;
43 /** Default constructor for the map.
47 /** Graph and Registry initialized map constructor.
49 Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
53 /** Constructor to use default value to initialize the map.
55 Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
57 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
62 /** Constructor to copy a map of an other map type.
64 template <typename CMap> Map(const CMap& copy) : MapBase(copy) {
67 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
73 /** Assign operator to copy a map an other map type.
75 template <typename CMap> Map& operator=(const CMap& copy) {
79 this->MapBase::operator=(copy);
82 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
88 /** The destructor of the map.
95 * The subscript operator. The map can be subscripted by the
96 * actual keys of the graph.
98 typename Container::reference operator[](const Key& key) {
99 int id = getGraph()->id(key);
100 return container[id];
104 * The const subscript operator. The map can be subscripted by the
105 * actual keys of the graph.
107 typename Container::const_reference operator[](const Key& key) const {
108 int id = getGraph()->id(key);
109 return container[id];
112 /** Setter function of the map. Equivalent with map[key] = val.
113 * This is a compatibility feature with the not dereferable maps.
115 void set(const Key& key, const Value& val) {
116 int id = getGraph()->id(key);
120 /** Add a new key to the map. It called by the map registry.
122 void add(const Key& key) {
123 int id = getGraph()->id(key);
124 if (id >= container.size()) {
125 container.resize(id + 1);
129 /** Erease a key from the map. It called by the map registry.
131 void erase(const Key& key) {}
133 /** Compatible iterator with the stl maps' iterators.
134 * It iterates on pairs of a key and a value.
138 friend class const_iterator;
141 /** Private constructor to initalize the the iterators returned
142 * by the begin() and end().
144 iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {}
148 /** Default constructor.
152 /** Dereference operator for map.
154 std::pair<const Key, Value> operator*() {
155 return std::pair<const Key, Value>(it, (*map)[it]);
158 /** Arrow operator for map.
160 std::pair<const Key, Value>* operator->() {
161 static std::pair<const Key, Value> tmp = operator*();
165 /** The pre increment operator of the map.
167 iterator& operator++() {
168 map->getGraph()->next(it);
172 /** The post increment operator of the map.
174 iterator operator++(int) {
176 map.getGraph()->next(it);
180 /** The equality operator of the map.
182 bool operator==(const_iterator p_it) {
183 return p_it.it == it;
186 /** The not-equality operator of the map.
188 bool operator!=(const_iterator p_it) {
189 return !(*this == p_it);
197 /** Returns the begin iterator of the map.
200 return iterator(*this, KeyIt(*getGraph()));
203 /** Returns the end iterator of the map.
206 return iterator(*this, INVALID);
209 class const_iterator {
211 friend class iterator;
214 /** Private constructor to initalize the the iterators returned
215 * by the begin() and end().
217 const_iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {}
221 /** Default constructor.
225 /** Constructor to convert iterator to const_iterator.
227 const_iterator(iterator p_it) {
231 /** Dereference operator for map.
233 std::pair<const Key, const Value> operator*() const {
234 return std::pair<const Key, const Value>(it, (*map)[it]);
237 /** Arrow operator for map.
239 std::pair<const Key, const Value>* operator->() const {
240 static std::pair<const Key, const Value> tmp = operator*();
244 /** The pre increment operator of the map.
246 const_iterator& operator++() {
247 map->getGraph()->next(it);
251 /** The post increment operator of the map.
253 const_iterator operator++(int) {
254 const_iterator tmp(it);
255 map->getGraph()->next(it);
259 /** The equality operator of the map.
261 bool operator==(const_iterator p_it) {
262 return p_it.it == it;
265 /** The not-equality operator of the map.
267 bool operator!=(const_iterator p_it) {
268 return !(*this == p_it);
276 /** Returns the begin const_iterator of the map.
278 const_iterator begin() const {
279 return const_iterator(*this, KeyIt(*getGraph()));
282 /** Returns the end const_iterator of the map.
284 const_iterator end() const {
285 return const_iterator(*this, INVALID);