Changeset 703:32f280a5ed7d in lemon-0.x for src/work/deba/vector_map_factory.h
- Timestamp:
- 07/15/04 14:15:58 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@954
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/vector_map_factory.h
r702 r703 1 // -*- c++ -*- 1 2 #ifndef VECTOR_MAP_H 2 3 #define VECTOR_MAP_H 3 4 4 5 #include <vector> 5 #include <iostream>6 6 7 7 #include "extended_pair.h" … … 56 56 */ 57 57 Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) { 58 init();59 58 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) { 60 set(it, v); 59 int id = getGraph->id(it); 60 if (id >= container.size) { 61 container.resize(id + 1); 62 } 63 set(it, v); 61 64 } 62 65 } … … 66 69 template <typename CMap> Map(const CMap& copy) : MapBase(copy) { 67 70 if (getGraph()) { 68 init();69 71 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) { 72 int id = getGraph->id(it); 73 if (id >= container.size) { 74 container.resize(id + 1); 75 } 70 76 set(it, copy[it]); 71 77 } … … 81 87 this->MapBase::operator=(copy); 82 88 if (getGraph()) { 83 init();84 89 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) { 90 int id = getGraph->id(it); 91 if (id >= container.size) { 92 container.resize(id + 1); 93 } 85 94 set(it, copy[it]); 86 95 } … … 91 100 */ 92 101 virtual ~Map() { 93 destroy();94 102 } 95 103 … … 152 160 iterator() {} 153 161 162 typedef extended_pair<const Key&, const Key&, 163 Value&, Value&> Reference; 164 154 165 /** Dereference operator for map. 155 166 */ 156 std::pair<const Key, Value> operator*() { 157 return std::pair<const Key, Value>(it, (*map)[it]); 158 } 159 167 Reference operator*() { 168 return Reference(it, (*map)[it]); 169 } 160 170 161 171 class Pointer { 162 172 friend class iterator; 163 173 private: 164 typedef extended_pair<const Key&, const Key&, Value&, Value&> Pair; 165 Pair data; 174 Reference data; 166 175 Pointer(const Key& key, Value& val) : data(key, val) {} 167 176 public: 168 Pair* operator->() {return &data;}177 Reference* operator->() {return &data;} 169 178 }; 170 179 … … 228 237 * by the begin() and end(). 229 238 */ 230 const_iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {} 239 const_iterator (const Map& pmap, const KeyIt& pit) 240 : map(&pmap), it(pit) {} 231 241 232 242 public: … … 238 248 /** Constructor to convert iterator to const_iterator. 239 249 */ 240 const_iterator(iterator p_it) { 241 it = p_it.it; 242 } 250 const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {} 243 251 252 typedef extended_pair<const Key&, const Key&, 253 const Value&, const Value&> Reference; 254 244 255 /** Dereference operator for map. 245 256 */ 246 std::pair<const Key, const Value> operator*() const { 247 return std::pair<const Key, const Value>(it, (*map)[it]); 248 } 257 Reference operator*() { 258 return Reference(it, (*map)[it]); 259 } 260 249 261 250 262 class Pointer { 251 263 friend class const_iterator; 252 264 private: 253 typedef extended_pair<const Key&, const Key&, const Value&, const Value&> Pair; 254 Pair data; 265 Reference data; 255 266 Pointer(const Key& key, const Value& val) : data(key, val) {} 256 267 public: 257 Pair* operator->() {return &data;}268 Reference* operator->() {return &data;} 258 269 }; 270 259 271 /** Arrow operator for map. 260 272 */ 261 Pointer operator->() const{262 return Pointer(it, ( *map)[it]);273 Pointer operator->() { 274 return Pointer(it, ((*map)[it])); 263 275 } 264 276
Note: See TracChangeset
for help on using the changeset viewer.