Changeset 377:33fe0ee01dc5 in lemon0.x for src
 Timestamp:
 04/22/04 18:36:57 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@507
 Location:
 src/work/deba
 Files:

 4 deleted
 6 edited
Legend:
 Unmodified
 Added
 Removed

src/work/deba/edge_map_base.h
r340 r377 12 12 template <typename G, typename K> 13 13 class EdgeMapBase { 14 15 #include "edge_map_registry.h" 16 14 17 public: 15 18 typedef G Graph; 19 friend class EdgeMapRegistry<G, K>; 16 20 17 21 typedef K KeyType; … … 78 82 79 83 void init() { 80 for ( Graph::EdgeIt it(g); g.valid(it); g.next(it)) {84 for (typename Graph::EdgeIt it(g); g.valid(it); g.next(it)) { 81 85 add(it); 82 86 } … … 88 92 89 93 void destroy() { 90 for ( Graph::EdgeIt it(g); g.valid(it); g.next(it)) {94 for (typename Graph::EdgeIt it(g); g.valid(it); g.next(it)) { 91 95 erase(it); 92 96 } … … 113 117 class NotSupportedOperationException {}; 114 118 115 friend class Graph;116 119 }; 117 120 
src/work/deba/edge_map_registry.h
r340 r377 4 4 #include <vector> 5 5 6 template <typename G, typename K> 7 class EdgeMapRegistry; 8 6 9 #include "edge_map_base.h" 7 10 8 template <typename G, typename E>11 template <typename G, typename K> 9 12 class EdgeMapRegistry { 10 13 public: 11 14 typedef G Graph; 12 typedef E Edge15 typedef K Edge; 13 16 14 17 typedef EdgeMapBase<Graph, Edge> MapBase; 18 friend class MapBase; 15 19 16 20 protected: 17 typedef std::vector<EdgeMapBase*> Container; 21 22 Graph* graph; 23 24 typedef std::vector<MapBase*> Container; 18 25 19 26 Container container; 20 27 28 public: 29 30 EdgeMapRegistry(Graph g) : graph(&g) {} 31 21 32 void add(MapBase& map_base) { 22 33 if (map_base.graph) { … … 24 35 } 25 36 container.push_back(&map_base); 26 map_base.graph = this;37 map_base.graph = graph; 27 38 map_base.graph_index = container.size()1; 28 39 } 29 40 30 41 void erase(MapBase& map_base) { 31 if (map_base.graph != this) return;32 42 container.back()>graph_index = map_base.graph_index; 33 43 container[map_base.graph_index] = container.back(); … … 35 45 map_base.graph = 0; 36 46 } 47 37 48 38 49 void add(Edge& edge) { … … 50 61 } 51 62 52 friend class MapBase;53 63 }; 54 64 
src/work/deba/node_map_base.h
r340 r377 12 12 template <typename G, typename K> 13 13 class NodeMapBase { 14 15 #include "node_map_registry.h" 16 14 17 public: 15 18 typedef G Graph; 19 friend class NodeMapRegistry<G, K>; 16 20 17 21 typedef K KeyType; … … 63 67 virtual ~NodeMapBase() { 64 68 if (graph) { 65 graph .node_maps.erase(*this);69 graph>node_maps.erase(*this); 66 70 } 67 71 } … … 78 82 79 83 void init() { 80 for ( Graph::NodeIt it(g); g.valid(it); g.next(it)) {84 for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) { 81 85 add(it); 82 86 } … … 88 92 89 93 void destroy() { 90 for ( Graph::NodeIt it(g); g.valid(it); g.next(it)) {94 for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) { 91 95 erase(it); 92 96 } … … 113 117 class NotSupportedOperationException {}; 114 118 115 friend class Graph;116 119 }; 117 120 
src/work/deba/node_map_registry.h
r340 r377 4 4 #include <vector> 5 5 6 template <typename G, typename K> 7 class NodeMapRegistry; 8 6 9 #include "node_map_base.h" 7 10 8 template <typename G, typename E>11 template <typename G, typename K> 9 12 class NodeMapRegistry { 10 13 public: 11 14 typedef G Graph; 12 typedef E Node15 typedef K Node; 13 16 14 typedef NodeMapBase<Graph, Node> NodeMapBase; 17 typedef NodeMapBase<Graph, Node> MapBase; 18 friend class MapBase; 15 19 16 20 protected: 17 typedef std::vector<NodeMapBase*> Container; 21 22 Graph* graph; 23 24 typedef std::vector<MapBase*> Container; 18 25 19 26 Container container; 20 21 void add(NodeMapBase& map_base) { 27 28 public: 29 30 NodeMapRegistry(Graph g) : graph(&g) {} 31 32 void add(MapBase& map_base) { 22 33 if (map_base.graph) { 23 34 map_base.graph>node_maps.erase(map_base); 24 35 } 25 36 container.push_back(&map_base); 26 map_base.graph = this;37 map_base.graph = graph; 27 38 map_base.graph_index = container.size()1; 28 39 } 29 40 30 void erase(NodeMapBase& map_base) { 31 if (map_base.graph != this) return; 41 void erase(MapBase& map_base) { 32 42 container.back()>graph_index = map_base.graph_index; 33 43 container[map_base.graph_index] = container.back(); … … 35 45 map_base.graph = 0; 36 46 } 47 37 48 38 49 void add(Node& node) { … … 50 61 } 51 62 52 friend class NodeMapBase;53 63 }; 54 64 
src/work/deba/test_graph.h
r340 r377 6 6 #include <vector> 7 7 8 #include <invalid.h> 9 10 #include "vector_map.h" 8 #include "invalid.h" 9 11 10 #include "edge_map_registry.h" 12 11 #include "node_map_registry.h" 13 12 #include "edge_map_base.h" 14 13 #include "node_map_base.h" 14 #include "vector_map.h" 15 15 16 16 namespace hugo { … … 41 41 // template <typename T> friend class EdgeMap; 42 42 43 NodeMapRegistry<ListGraph, Node> node_maps; 43 private: 44 45 NodeMapRegistry<ListGraph, Node> node_maps(*this); 46 EdgeMapRegistry<ListGraph, Edge> edge_maps(*this); 47 48 public: 49 44 50 45 51 template <typename T> 46 class NodeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {}; 52 class NodeMap : public VectorMap<ListGraph, Node, T, NodeMapBase> { 53 public: 54 NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, T, NodeMapBase>(g) {} 55 }; 47 56 48 57 EdgeMapRegistry<ListGraph, Edge> edge_maps; 49 58 50 59 template <typename T> 51 class EdgeMap : public VectorMap< Graph, Node, T, NodeMapBase> {};60 class EdgeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {}; 52 61 53 62 … … 311 320 312 321 void erase(Node i) { 313 node_map .erase(i);322 node_maps.erase(i); 314 323 while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i)); 315 324 while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i)); 
src/work/deba/vector_map.h
r340 r377 35 35 36 36 void add(const K& key) { 37 container.resize(key>id); 37 if (key>id() >= container.size()) { 38 container.resize(key>id() + 1); 39 } 38 40 } 39 41 … … 44 46 45 47 Container container; 46 } 48 }; 47 49 48 50 #endif
Note: See TracChangeset
for help on using the changeset viewer.