src/work/deba/map_base.h
changeset 571 9632ea8be6ca
parent 378 c3f93631cd24
child 595 e10b5e9419ef
equal deleted inserted replaced
0:90ce23ea824c 1:56f8a9e403ad
    37 
    37 
    38 		/** 
    38 		/** 
    39 			Simple constructor to register into a graph registry.
    39 			Simple constructor to register into a graph registry.
    40 		*/
    40 		*/
    41 	
    41 	
    42 		MapBase(Registry& r) : registry(0) {
    42 		MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
    43 			registry->add(*this);
    43 			registry->attach(*this);
    44 		}
    44 		}
    45 
    45 
    46 		/** 
    46 		/** 
    47 			Copy constructor with registering into the map.
    47 			Copy constructor with registering into the map.
    48 		*/	
    48 		*/	
    49 	
    49 	
    50 		MapBase(const MapBase& copy) : registry(0) {
    50 		MapBase(const MapBase& copy) : registry(0), graph(copy.graph) {
    51 			if (registry) {
    51 			if (copy.registry) {
    52 				registry->add(*this);
    52 				copy.registry->attach(*this);
    53 			}
    53 			}
    54 		} 
    54 		} 
    55 	
    55 	
    56 		/** 
    56 		/** 
    57 			Assign operator.
    57 			Assign operator.
    58 		*/	
    58 		*/	
    59 
    59 
    60 		const MapBase& operator=(const MapBase& copy) {
    60 		const MapBase& operator=(const MapBase& copy) {
    61 			if (registry) {
    61 			if (registry) {
    62 				registry->erase(*this);
    62 				registry->detach(*this);
    63 			}
    63 			}
    64 			registry = copy.registry;
    64 			graph = copy.graph;
    65 			if (registry) {
    65 			if (copy.registry) {
    66 				registry->add(*this);
    66 				copy.registry->attach(*this);
    67 			}
    67 			}
    68 		}
    68 		}
    69 	
    69 	
    70 
    70 
    71 		/** 
    71 		/** 
    72 			Destructor.
    72 			Destructor.
    73 		*/		
    73 		*/		
    74 
    74 
    75 		virtual ~MapBase() {
    75 		virtual ~MapBase() {
    76 			if (registry) {
    76 			if (registry) {
    77 				registry->erase(*this);
    77 				registry->detach(*this);
    78 			}
    78 			}
    79 		}
    79 		}
    80 	
    80 	
    81 	protected:
    81 	protected:
    82 		
    82 		
    83 		Registry* registry;
    83 		Registry* registry;
       
    84 		Graph* graph;
    84 
    85 
    85 		int registry_index;
    86 		int registry_index;
    86 	
    87 	
    87 		/**
    88 		/**
    88 			Helper function to implement the default constructor in the subclasses.
    89 			Helper function to implement the default constructor in the subclasses.
    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 				add(it);
    95 				add(it);
    95 			}
    96 			}
    96 		}
    97 		}
    97 	
    98 	
    98 		/**
    99 		/**
    99 			Helper function to implement the destructor in the subclasses.
   100 			Helper function to implement the destructor in the subclasses.
   100 		*/
   101 		*/
   101 	
   102 	
   102 		virtual void destroy(Graph& g) {
   103 		virtual void destroy() {
   103 			for (KeyIt it(g); g.valid(it); g.next(it)) {
   104 			for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
   104 				erase(it);
   105 				erase(it);
   105 			}
   106 			}
   106 		}
   107 		}
   107 	
   108 	
   108 		/** 
   109 		/**