COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/vector_map_factory.h @ 698:625de6f1e766

Last change on this file since 698:625de6f1e766 was 698:625de6f1e766, checked in by Balazs Dezso, 20 years ago
File size: 1.7 KB
Line 
1#ifndef VECTOR_MAP_H
2#define VECTOR_MAP_H
3
4#include <vector>
5
6namespace hugo {
7       
8  template <typename MapRegistry>
9    class VectorMapFactory {
10    public:
11               
12    typedef typename MapRegistry::Graph Graph;
13    typedef typename MapRegistry::Key Key;
14    typedef typename MapRegistry::KeyIt KeyIt;
15
16    typedef typename MapRegistry::MapBase MapBase;
17
18               
19    template <typename V>
20      class Map : public MapBase {
21      public:
22      typedef V Value;
23       
24      typedef std::vector<Value> Container;
25      Map() {}
26                       
27      Map(Graph& g, MapRegistry& r) : MapBase(g, r) {
28        init();
29      }
30                       
31                                               
32      virtual ~Map() {
33        destroy();
34      }
35       
36       
37      typename Container::reference operator[](const Key& key) {
38        int id = graph->id(key);
39        return container[id];
40      }
41               
42      typename Container::const_reference operator[](const Key& key) const {
43        int id = graph->id(key);
44        return container[id];
45      }
46       
47      void set(const Key& key, const Value& val) {
48        int id = graph->id(key);
49        container[id] = val;
50      }
51               
52      void add(const Key& key) {
53        int id = graph->id(key);
54        if (id >= container.size()) {
55          container.resize(id + 1);
56        }
57      }
58               
59      void erase(const Key& key) {}
60       
61      class const_iterator {
62
63      private:
64     
65      };
66
67      class iterator {
68      public:
69        iterator() {}
70     
71        std::pair<const Key&, Value&> operator*() {
72          return std::pair<const Key&, Value&>(static_cast<Key&>(it), map[it]);
73        }
74
75        iterator& operator++() { ++it; return *this; }
76        iterator operator++(int) { iterator tmp(it); ++it; return tmp; }
77      private:
78        Map& map;
79        KeyIt it;
80      };
81
82      private:
83      typedef std::vector<Value> Container;
84               
85      Container container;
86
87
88    };
89
90   
91
92               
93  };
94}
95
96#endif
Note: See TracBrowser for help on using the repository browser.