12 * Registry class to register edge or node maps into the graph. The
13 * registry helps you to implement an observer pattern. If you add
14 * or erase an edge or node you must notify all the maps about the
17 template <typename G, typename K, typename KIt>
27 * MapBase is the base class of the registered maps.
28 * It defines the core modification operations on the maps and
29 * implements some helper functions.
37 typedef MapRegistry<G, K, KIt> Registry;
39 friend class MapRegistry<G, K, KIt>;
42 * Default constructor for MapBase.
45 MapBase() : graph(0), registry(0) {}
48 * Simple constructor to register into a graph registry.
51 MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
56 * Copy constructor to register into the registry.
59 MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
61 copy.registry->attach(*this);
69 const MapBase& operator=(const MapBase& copy) {
71 registry->detach(*this);
75 copy.registry->attach(*this);
87 registry->detach(*this);
92 * Returns the graph that the map belongs to.
95 const Graph* getGraph() const { return graph; }
107 Helper function to implement constructors in the subclasses.
110 virtual void init() {
111 for (KeyIt it(*graph); it != INVALID; ++it) {
117 Helper function to implement the destructor in the subclasses.
120 virtual void destroy() {
121 for (KeyIt it(*getGraph()); it != INVALID; ++it) {
127 The add member function should be overloaded in the subclasses.
128 \e Add extends the map with the new node.
131 virtual void add(const Key&) = 0;
133 The erase member function should be overloaded in the subclasses.
134 \e Erase removes the node from the map.
137 virtual void erase(const Key&) = 0;
140 * The clear member function should be overloaded in the subclasses.
141 * \e Clear makes empty the data structure.
144 virtual void clear() = 0;
147 Exception class to throw at unsupported operation.
150 class NotSupportedOperationException {};
157 * The container type of the maps.
159 typedef std::vector<MapBase*> Container;
162 * The container of the registered maps.
170 * Default Constructor of the MapRegistry. It creates an empty registry.
175 * Copy Constructor of the MapRegistry. The new registry does not steal
176 * the maps from the right value. The new registry will be an empty.
178 MapRegistry(const MapRegistry&) {}
181 * Assign operator. The left value does not steal the maps
182 * from the right value. The left value will be an empty registry.
184 MapRegistry& operator=(const MapRegistry&) {
185 typename Container::iterator it;
186 for (it = container.begin(); it != container.end(); ++it) {
194 * Destructor of the MapRegistry.
197 typename Container::iterator it;
198 for (it = container.begin(); it != container.end(); ++it) {
209 * Attach a map into thr registry. If the map has been attached
210 * into an other registry it is detached from that automaticly.
212 void attach(MapBase& map) {
214 map.registry->detach(map);
216 container.push_back(&map);
218 map.registry_index = container.size()-1;
222 * Detach the map from the registry.
224 void detach(MapBase& map) {
225 container.back()->registry_index = map.registry_index;
226 container[map.registry_index] = container.back();
227 container.pop_back();
234 * Notify all the registered maps about a Key added.
237 typename Container::iterator it;
238 for (it = container.begin(); it != container.end(); ++it) {
244 * Notify all the registered maps about a Key erased.
246 void erase(Key& key) {
247 typename Container::iterator it;
248 for (it = container.begin(); it != container.end(); ++it) {
254 * Notify all the registered maps about the map should be cleared.
257 typename Container::iterator it;
258 for (it = container.begin(); it != container.end(); ++it) {