9 Registry class to register edge or node maps in the graph. The
10 registry helps you to implement an observer pattern. If you add
11 or erase an edge or node you must notify all the maps about the
17 template <typename G, typename K, typename KIt>
29 typedef MapRegistry<G, K, KIt> Registry;
33 friend class Registry;
39 MapBase() : graph(0), registry(0) {}
42 Simple constructor to register into a graph registry.
45 MapBase(Graph& g, Registry& r) : graph(&g), registry(0) {
50 Copy constructor with registering into the map.
53 MapBase(const MapBase& copy) : registry(0), graph(copy.graph) {
55 copy.registry->attach(*this);
63 const MapBase& operator=(const MapBase& copy) {
65 registry->detach(*this);
69 copy.registry->attach(*this);
80 registry->detach(*this);
92 Helper function to implement constructors in the subclasses.
96 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
102 Helper function to implement the destructor in the subclasses.
105 virtual void destroy() {
106 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
112 The add member function should be overloaded in the subclasses.
113 \e Add extends the map with the new node.
116 virtual void add(const Key&) = 0;
118 The erase member function should be overloaded in the subclasses.
119 \e Erase removes the node from the map.
122 virtual void erase(const Key&) = 0;
125 Exception class to throw at unsupported operation.
128 class NotSupportedOperationException {};
134 typedef std::vector<MapBase*> Container;
142 MapRegistry(const MapRegistry&) {}
144 MapRegistry& operator=(const MapRegistry&) {
145 for (it = container.begin(); it != container.end(); ++it) {
153 typename Container::iterator it;
154 for (it = container.begin(); it != container.end(); ++it) {
164 void attach(MapBase& map) {
166 map.registry->detach(map);
168 container.push_back(&map);
170 map.registry_index = container.size()-1;
173 void detach(MapBase& map) {
174 container.back()->registry_index = map.registry_index;
175 container[map.registry_index] = container.back();
176 container.pop_back();
182 virtual void add(Key& key) {
183 typename Container::iterator it;
184 for (it = container.begin(); it != container.end(); ++it) {
189 virtual void erase(Key& key) {
190 typename Container::iterator it;
191 for (it = container.begin(); it != container.end(); ++it) {