Changes in doc.
11 * Registry class to register edge or node maps into the graph. The
12 * registry helps you to implement an observer pattern. If you add
13 * or erase an edge or node you must notify all the maps about the
16 template <typename G, typename K, typename KIt>
26 * MapBase is the base class of the registered maps.
27 * It defines the core modification operations on the maps and
28 * implements some helper functions.
33 typedef MapRegistry<G, K, KIt> Registry;
37 friend class Registry;
40 * Default constructor for MapBase.
43 MapBase() : graph(0), registry(0) {}
46 * Simple constructor to register into a graph registry.
49 MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
54 * Copy constructor to register into the registry.
57 MapBase(const MapBase& copy) : registry(0), graph(copy.graph) {
59 copy.registry->attach(*this);
67 const MapBase& operator=(const MapBase& copy) {
69 registry->detach(*this);
73 copy.registry->attach(*this);
84 registry->detach(*this);
89 * Returns the graph that the map belongs to.
92 const Graph* getGraph() const { return graph; }
104 Helper function to implement constructors in the subclasses.
107 virtual void init() {
108 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) {
114 Helper function to implement the destructor in the subclasses.
117 virtual void destroy() {
118 for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
124 The add member function should be overloaded in the subclasses.
125 \e Add extends the map with the new node.
128 virtual void add(const Key&) = 0;
130 The erase member function should be overloaded in the subclasses.
131 \e Erase removes the node from the map.
134 virtual void erase(const Key&) = 0;
137 Exception class to throw at unsupported operation.
140 class NotSupportedOperationException {};
147 * The container type of the maps.
149 typedef std::vector<MapBase*> Container;
152 * The container of the registered maps.
160 * Default Constructor of the MapRegistry. It creates an empty registry.
165 * Copy Constructor of the MapRegistry. The new registry does not steal
166 * the maps from the right value. The new registry will be an empty.
168 MapRegistry(const MapRegistry&) {}
171 * Assign operator. The left value does not steal the maps
172 * from the right value. The left value will be an empty registry.
174 MapRegistry& operator=(const MapRegistry&) {
175 for (it = container.begin(); it != container.end(); ++it) {
183 * Destructor of the MapRegistry.
186 typename Container::iterator it;
187 for (it = container.begin(); it != container.end(); ++it) {
198 * Attach a map into thr registry. If the map has been attached
199 * into an other registry it is detached from that automaticly.
201 void attach(MapBase& map) {
203 map.registry->detach(map);
205 container.push_back(&map);
207 map.registry_index = container.size()-1;
211 * Detach the map from the registry.
213 void detach(MapBase& map) {
214 container.back()->registry_index = map.registry_index;
215 container[map.registry_index] = container.back();
216 container.pop_back();
223 * Notify all the registered maps about a Key added.
225 virtual void add(Key& key) {
226 typename Container::iterator it;
227 for (it = container.begin(); it != container.end(); ++it) {
233 * Notify all the registered maps about a Key erased.
235 virtual void erase(Key& key) {
236 typename Container::iterator it;
237 for (it = container.begin(); it != container.end(); ++it) {