COIN-OR::LEMON - Graph Library

Changeset 571:9632ea8be6ca in lemon-0.x for src/work/deba


Ignore:
Timestamp:
05/07/04 10:18:30 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@746
Message:
 
Location:
src/work/deba
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/main.cpp

    r378 r571  
    88int main() {
    99        ListGraph g;
    10         ListGraph::NodeMap<int> map(g);
     10        ListGraph::NodeMapFactory::VectorMap<int> map(g, g.node_maps);
    1111        ListGraph::Node node = g.addNode();
    1212        map[node] = 12;
  • src/work/deba/map_base.h

    r378 r571  
    4040                */
    4141       
    42                 MapBase(Registry& r) : registry(0) {
    43                         registry->add(*this);
     42                MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
     43                        registry->attach(*this);
    4444                }
    4545
     
    4848                */     
    4949       
    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);
    5353                        }
    5454                }
     
    6060                const MapBase& operator=(const MapBase& copy) {
    6161                        if (registry) {
    62                                 registry->erase(*this);
     62                                registry->detach(*this);
    6363                        }
    64                         registry = copy.registry;
    65                         if (registry) {
    66                                 registry->add(*this);
     64                        graph = copy.graph;
     65                        if (copy.registry) {
     66                                copy.registry->attach(*this);
    6767                        }
    6868                }
     
    7575                virtual ~MapBase() {
    7676                        if (registry) {
    77                                 registry->erase(*this);
     77                                registry->detach(*this);
    7878                        }
    7979                }
     
    8282               
    8383                Registry* registry;
     84                Graph* graph;
    8485
    8586                int registry_index;
     
    8990                */
    9091       
    91                 virtual void init(Graph& g) {
     92                virtual void init() {
    9293
    93                         for (KeyIt it(g); g.valid(it); g.next(it)) {
     94                        for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
    9495                                add(it);
    9596                        }
     
    100101                */
    101102       
    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)) {
    104105                                erase(it);
    105106                        }
  • src/work/deba/map_registry.h

    r378 r571  
    2929          Container container;
    3030
    31                 Graph* graph;           
    32                
    3331               
    3432        public:
    3533       
    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                }
    3745                               
    3846                ~MapRegistry() {
    3947                        typename Container::iterator it;
    4048                        for (it = container.begin(); it != container.end(); ++it) {
    41                                 (*it)->destroy(*graph);
     49                                (*it)->destroy();
    4250                                (*it)->registry = 0;
     51                                (*it)->graph = 0;
    4352                        }
    4453                }
    4554       
    46         private:
    47                 MapRegistry(const MapRegistry& ) {}
    48                 MapRegistry& operator=(const MapRegistry& ) {}
    4955       
    5056        public:
    5157       
    52                 void add(Map& map) {
     58                void attach(Map& map) {
    5359                        if (map.registry) {
    54                                 map.registry->erase(map);
     60                                map.registry->detach(map);
    5561                        }
    5662                        container.push_back(&map);
    5763                        map.registry = this;
    5864                        map.registry_index = container.size()-1;
    59                         map.init(*graph);
     65                        map.init();
    6066                }
    6167       
    62                 void erase(Map& map_base) {
    63                         map_base.destroy(*graph);
     68                void detach(Map& map_base) {
     69                        map_base.destroy();
    6470                        container.back()->registry_index = map_base.registry_index;
    6571                        container[map_base.registry_index] = container.back();
    6672                        container.pop_back();
    6773                        map_base.registry = 0;
     74                        map_base.graph = 0;
    6875                }
    6976       
     
    8390                }
    8491
    85                 Graph& getGraph() {
    86                         return *graph;
    87                 }
    88 
    89 
    9092        };
    9193
  • src/work/deba/test_graph.h

    r378 r571  
    88#include "invalid.h"
    99
    10 #include "vector_map.h"
     10#include "vector_map_factory.h"
    1111
    1212namespace hugo {
     
    3939  private:
    4040
     41 
     42        public:
     43       
    4144                typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry;
    4245                NodeMapRegistry node_maps;
    4346               
     47               
    4448                typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry;
    4549                EdgeMapRegistry edge_maps;
     50
     51                typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory;
     52                typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory;
    4653 
    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 
    6254
    6355    int node_id;
     
    216208    /* default constructor */
    217209
    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){ }
    220211   
    221212    ~ListGraph() {
Note: See TracChangeset for help on using the changeset viewer.