Changeset 571:9632ea8be6ca in lemon-0.x for src/work
- Timestamp:
- 05/07/04 10:18:30 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@746
- Location:
- src/work/deba
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/main.cpp
r378 r571 8 8 int main() { 9 9 ListGraph g; 10 ListGraph::NodeMap <int> map(g);10 ListGraph::NodeMapFactory::VectorMap<int> map(g, g.node_maps); 11 11 ListGraph::Node node = g.addNode(); 12 12 map[node] = 12; -
src/work/deba/map_base.h
r378 r571 40 40 */ 41 41 42 MapBase( Registry& r) :registry(0) {43 registry->a dd(*this);42 MapBase(Graph& g, Registry& r) : graph(&g), registry(0) { 43 registry->attach(*this); 44 44 } 45 45 … … 48 48 */ 49 49 50 MapBase(const MapBase& copy) : registry(0) {51 if ( registry) {52 registry->add(*this);50 MapBase(const MapBase& copy) : registry(0), graph(copy.graph) { 51 if (copy.registry) { 52 copy.registry->attach(*this); 53 53 } 54 54 } … … 60 60 const MapBase& operator=(const MapBase& copy) { 61 61 if (registry) { 62 registry-> erase(*this);62 registry->detach(*this); 63 63 } 64 registry = copy.registry;65 if ( registry) {66 registry->add(*this);64 graph = copy.graph; 65 if (copy.registry) { 66 copy.registry->attach(*this); 67 67 } 68 68 } … … 75 75 virtual ~MapBase() { 76 76 if (registry) { 77 registry-> erase(*this);77 registry->detach(*this); 78 78 } 79 79 } … … 82 82 83 83 Registry* registry; 84 Graph* graph; 84 85 85 86 int registry_index; … … 89 90 */ 90 91 91 virtual void init( Graph& g) {92 virtual void init() { 92 93 93 for (KeyIt it( g); g.valid(it); g.next(it)) {94 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) { 94 95 add(it); 95 96 } … … 100 101 */ 101 102 102 virtual void destroy( Graph& g) {103 for (KeyIt it( g); g.valid(it); g.next(it)) {103 virtual void destroy() { 104 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) { 104 105 erase(it); 105 106 } -
src/work/deba/map_registry.h
r378 r571 29 29 Container container; 30 30 31 Graph* graph;32 33 31 34 32 public: 35 33 36 MapRegistry(Graph& g) : container(0), graph(&g) {} 34 MapRegistry() {} 35 36 MapRegistry(const MapRegistry&) {} 37 38 MapRegistry& operator=(const MapRegistry&) { 39 for (it = container.begin(); it != container.end(); ++it) { 40 (*it)->destroy(); 41 (*it)->graph = 0; 42 (*it)->registry = 0; 43 } 44 } 37 45 38 46 ~MapRegistry() { 39 47 typename Container::iterator it; 40 48 for (it = container.begin(); it != container.end(); ++it) { 41 (*it)->destroy( *graph);49 (*it)->destroy(); 42 50 (*it)->registry = 0; 51 (*it)->graph = 0; 43 52 } 44 53 } 45 54 46 private:47 MapRegistry(const MapRegistry& ) {}48 MapRegistry& operator=(const MapRegistry& ) {}49 55 50 56 public: 51 57 52 void a dd(Map& map) {58 void attach(Map& map) { 53 59 if (map.registry) { 54 map.registry-> erase(map);60 map.registry->detach(map); 55 61 } 56 62 container.push_back(&map); 57 63 map.registry = this; 58 64 map.registry_index = container.size()-1; 59 map.init( *graph);65 map.init(); 60 66 } 61 67 62 void erase(Map& map_base) {63 map_base.destroy( *graph);68 void detach(Map& map_base) { 69 map_base.destroy(); 64 70 container.back()->registry_index = map_base.registry_index; 65 71 container[map_base.registry_index] = container.back(); 66 72 container.pop_back(); 67 73 map_base.registry = 0; 74 map_base.graph = 0; 68 75 } 69 76 … … 83 90 } 84 91 85 Graph& getGraph() {86 return *graph;87 }88 89 90 92 }; 91 93 -
src/work/deba/test_graph.h
r378 r571 8 8 #include "invalid.h" 9 9 10 #include "vector_map .h"10 #include "vector_map_factory.h" 11 11 12 12 namespace hugo { … … 39 39 private: 40 40 41 42 public: 43 41 44 typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry; 42 45 NodeMapRegistry node_maps; 43 46 47 44 48 typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry; 45 49 EdgeMapRegistry edge_maps; 50 51 typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory; 52 typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory; 46 53 47 public:48 49 50 template <typename T>51 class NodeMap : public VectorMap<ListGraph, Node, NodeIt, T> {52 public:53 NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, NodeIt, T>(g.node_maps) {}54 };55 56 template <typename T>57 class EdgeMap : public VectorMap<ListGraph, Edge, EdgeIt, T> {58 public:59 EdgeMap(ListGraph& g) : VectorMap<ListGraph, Edge, EdgeIt, T>(g.edge_maps) {}60 };61 62 54 63 55 int node_id; … … 216 208 /* default constructor */ 217 209 218 ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0), 219 edge_maps(*this), node_maps(*this) { } 210 ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0){ } 220 211 221 212 ~ListGraph() {
Note: See TracChangeset
for help on using the changeset viewer.