Changeset 627:6cc21a9c9fda in lemon-0.x for src/work/deba/vector_map_factory.h
- Timestamp:
- 05/13/04 10:20:39 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@818
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/vector_map_factory.h
r595 r627 4 4 #include <vector> 5 5 6 #include "map_ base.h"6 #include "map_registry.h" 7 7 8 8 namespace hugo { 9 9 10 template <typename G, typename K, typename KIt> 11 class VectorMapFactory { 10 template <typename MapRegistry> 11 class VectorMapFactory { 12 public: 13 14 typedef typename MapRegistry::Graph Graph; 15 typedef typename MapRegistry::Key Key; 16 typedef typename MapRegistry::KeyIt KeyIt; 17 18 typedef typename MapRegistry::MapBase MapBase; 19 20 template <typename V> 21 class Map : public MapBase { 22 public: 23 typedef V Value; 24 25 Map() {} 26 27 Map(Graph& g, MapRegistry& r) : MapBase(g, r) { 28 init(); 29 } 30 31 32 virtual ~Map() { 33 destroy(); 34 } 12 35 13 36 14 public: 37 Value& operator[](const Key& key) { 38 int id = graph->id(key); 39 return container[id]; 40 } 15 41 16 typedef G Graph; 17 typedef K Key; 18 typedef KIt KeyIt; 42 const Value& operator[](const Key& key) const { 43 int id = graph->id(key); 44 return container[id]; 45 } 46 47 const Value& get(const Key& key) const { 48 int id = graph->id(key); 49 return container[id]; 50 } 19 51 20 template <typename V> 21 class Map : public MapBase<G, K, KIt> { 22 public: 23 typedef V Value; 52 void set(const Key& key, const Value& val) { 53 int id = graph->id(key); 54 container[id] = val; 55 } 56 57 void add(const Key& key) { 58 int id = graph->id(key); 59 if (id >= container.size()) { 60 container.resize(id + 1); 61 } 62 } 63 64 void erase(const Key& key) {} 24 65 25 Map() {} 26 27 Map(Graph& g, MapRegistry<G, K, KIt>& r) 28 : MapBase<G, K, KIt>(g, r) { 29 init(); 30 } 31 32 virtual ~Map() { 33 destroy(); 34 } 35 36 37 Value& operator[](const K& key) { 38 int id = graph->id(key); 39 return container[id]; 40 } 66 private: 67 typedef std::vector<Value> Container; 41 68 42 const Value& operator[](const K& key) const { 43 int id = graph->id(key); 44 return container[id]; 45 } 46 47 const Value& get(const K& key) const { 48 int id = graph->id(key); 49 return container[id]; 50 } 69 Container container; 70 }; 51 71 52 void set(const K& key, const Value& val) { 53 int id = graph->id(key); 54 container[id] = val; 55 } 56 57 void add(const K& key) { 58 int id = graph->id(key); 59 if (id >= container.size()) { 60 container.resize(id + 1); 61 } 62 } 63 64 void erase(const K& key) {} 65 66 private: 67 typedef std::vector<Value> Container; 68 69 Container container; 70 }; 71 72 }; 72 }; 73 73 } 74 74
Note: See TracChangeset
for help on using the changeset viewer.