Skeleton for paths.
7 ///\ingroup graphmapfactory
9 ///\brief Map registry for graph maps.
15 /// \addtogroup graphmapfactory
19 * Registry class to register edge or node maps into the graph. The
20 * registry helps you to implement an observer pattern. If you add
21 * or erase an edge or node you must notify all the maps about the
24 template <typename G, typename K, typename KIt>
34 * MapBase is the base class of the registered maps.
35 * It defines the core modification operations on the maps and
36 * implements some helper functions.
44 typedef MapRegistry<G, K, KIt> Registry;
46 friend class MapRegistry<G, K, KIt>;
49 * Default constructor for MapBase.
52 MapBase() : graph(0), registry(0) {}
55 * Simple constructor to register into a graph registry.
58 MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
63 * Copy constructor to register into the registry.
66 MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
68 copy.registry->attach(*this);
76 const MapBase& operator=(const MapBase& copy) {
78 registry->detach(*this);
82 copy.registry->attach(*this);
94 registry->detach(*this);
99 * Returns the graph that the map belongs to.
102 const Graph* getGraph() const { return graph; }
114 Helper function to implement constructors in the subclasses.
117 virtual void init() {
118 for (KeyIt it(*graph); it != INVALID; ++it) {
124 Helper function to implement the destructor in the subclasses.
127 virtual void destroy() {
128 for (KeyIt it(*getGraph()); it != INVALID; ++it) {
134 The add member function should be overloaded in the subclasses.
135 \e Add extends the map with the new node.
138 virtual void add(const KeyType&) = 0;
140 The erase member function should be overloaded in the subclasses.
141 \e Erase removes the node from the map.
144 virtual void erase(const KeyType&) = 0;
147 * The clear member function should be overloaded in the subclasses.
148 * \e Clear makes empty the data structure.
151 virtual void clear() = 0;
154 Exception class to throw at unsupported operation.
157 class NotSupportedOperationException {};
164 * The container type of the maps.
166 typedef std::vector<MapBase*> Container;
169 * The container of the registered maps.
177 * Default Constructor of the MapRegistry. It creates an empty registry.
182 * Copy Constructor of the MapRegistry. The new registry does not steal
183 * the maps from the right value. The new registry will be an empty.
185 MapRegistry(const MapRegistry&) {}
188 * Assign operator. The left value does not steal the maps
189 * from the right value. The left value will be an empty registry.
191 MapRegistry& operator=(const MapRegistry&) {
192 typename Container::iterator it;
193 for (it = container.begin(); it != container.end(); ++it) {
201 * Destructor of the MapRegistry.
204 typename Container::iterator it;
205 for (it = container.begin(); it != container.end(); ++it) {
216 * Attach a map into thr registry. If the map has been attached
217 * into an other registry it is detached from that automaticly.
219 void attach(MapBase& map) {
221 map.registry->detach(map);
223 container.push_back(&map);
225 map.registry_index = container.size()-1;
229 * Detach the map from the registry.
231 void detach(MapBase& map) {
232 container.back()->registry_index = map.registry_index;
233 container[map.registry_index] = container.back();
234 container.pop_back();
241 * Notify all the registered maps about a Key added.
243 void add(KeyType& key) {
244 typename Container::iterator it;
245 for (it = container.begin(); it != container.end(); ++it) {
251 * Notify all the registered maps about a Key erased.
253 void erase(KeyType& key) {
254 typename Container::iterator it;
255 for (it = container.begin(); it != container.end(); ++it) {
261 * Notify all the registered maps about the map should be cleared.
264 typename Container::iterator it;
265 for (it = container.begin(); it != container.end(); ++it) {