src/work/deba/map_base.h
changeset 607 327f7cf13843
parent 571 9632ea8be6ca
equal deleted inserted replaced
1:56f8a9e403ad 2:84290d362a00
     1 #ifndef MAP_BASE_H
     1 #ifndef MAP_BASE_H
     2 #define MAP_BASE_H
     2 #define MAP_BASE_H
     3 
     3 
       
     4 using namespace std;
       
     5 
     4 /**
     6 /**
     5 	Template base class for implementing mapping on nodes.
     7 	Template base class for implementing mapping on nodes and edges.
     6 	\param The first template parameter is the Graph class. The Graph
     8 	\param The first template parameter is the Graph class.
     7 		must have an \emp node_maps member with \emp MapRegistry class.
     9 	\param The second template parameter is the key type.
     8 	\param The second template parameter is the  type of the class.
    10 	\param The third template parameter is an iterator on
     9 	
    11 		the keys.
    10 */
    12 */
    11 
    13 
    12 
    14 
    13 namespace hugo {
    15 namespace hugo {
    14 	template <typename G, typename K, typename KIt>
    16 	template <typename G, typename K, typename KIt>
    22 	template <typename G, typename K, typename KIt>
    24 	template <typename G, typename K, typename KIt>
    23 	class MapBase {
    25 	class MapBase {
    24 	public:
    26 	public:
    25 		typedef G Graph;
    27 		typedef G Graph;
    26 		typedef MapRegistry<G, K, KIt> Registry;
    28 		typedef MapRegistry<G, K, KIt> Registry;
    27 		typedef K KeyType;
    29 		typedef K Key;
    28 		typedef KIt KeyIt;
    30 		typedef KIt KeyIt;
    29 	
    31 	
    30 		friend class Registry;
    32 		friend class Registry;
    31 		
    33 		
    32 		/** 
    34 		/** 
    33 			Default constructor.
    35 			Default constructor.
    34 		*/	
    36 		*/	
    35 		
    37 		
    36 		MapBase() : registry(0) {}
    38 		MapBase() : graph(0), registry(0) {}
    37 
    39 
    38 		/** 
    40 		/** 
    39 			Simple constructor to register into a graph registry.
    41 			Simple constructor to register into a graph registry.
    40 		*/
    42 		*/
    41 	
    43 	
    42 		MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
    44 		MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
    43 			registry->attach(*this);
    45 			r.attach(*this);
    44 		}
    46 		}
    45 
    47 
    46 		/** 
    48 		/** 
    47 			Copy constructor with registering into the map.
    49 			Copy constructor with registering into the map.
    48 		*/	
    50 		*/	
    78 			}
    80 			}
    79 		}
    81 		}
    80 	
    82 	
    81 	protected:
    83 	protected:
    82 		
    84 		
       
    85 		Graph* graph;
    83 		Registry* registry;
    86 		Registry* registry;
    84 		Graph* graph;
       
    85 
    87 
    86 		int registry_index;
    88 		int registry_index;
    87 	
    89 	
    88 		/**
    90 		/**
    89 			Helper function to implement the default constructor in the subclasses.
    91 			Helper function to implement constructors in the subclasses.
    90 		*/
    92 		*/
    91 	
    93 	
    92 		virtual void init() {
    94 		virtual void init() {
    93 
       
    94 			for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
    95 			for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
    95 				add(it);
    96 				add(it);
    96 			}
    97 			}
    97 		}
    98 		}
    98 	
    99 	
   109 		/** 
   110 		/** 
   110 			The add member function should be overloaded in the subclasses.
   111 			The add member function should be overloaded in the subclasses.
   111 			\e Add extends the map with the new node.
   112 			\e Add extends the map with the new node.
   112 		*/
   113 		*/
   113 	
   114 	
   114 		virtual void add(const KeyType&) = 0;
   115 		virtual void add(const Key&) = 0;	
   115 	
       
   116 		/** 
   116 		/** 
   117 			The erase member function should be overloaded in the subclasses.
   117 			The erase member function should be overloaded in the subclasses.
   118 			\e Erase removes the node from the map.
   118 			\e Erase removes the node from the map.
   119 		*/
   119 		*/
   120 	
   120 	
   121 		virtual void erase(const KeyType&) = 0;
   121 		virtual void erase(const Key&) = 0;
   122 	
   122 	
   123 		/**
   123 		/**
   124 			Exception class to throw at unsupported operation.
   124 			Exception class to throw at unsupported operation.
   125 		*/
   125 		*/
   126 	
   126