[Lemon-commits] [lemon_svn] klao: r1310 - in hugo/branches/graph_factory/src/lemon: . skeletons
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:32 CET 2006
Author: klao
Date: Mon Oct 25 12:31:49 2004
New Revision: 1310
Modified:
hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h
hugo/branches/graph_factory/src/lemon/array_map.h
hugo/branches/graph_factory/src/lemon/default_map.h
hugo/branches/graph_factory/src/lemon/skeletons/graph_component.h
hugo/branches/graph_factory/src/lemon/skeletons/maps.h
hugo/branches/graph_factory/src/lemon/vector_map.h
Log:
GraphMapConcept and related bugfixes.
Modified: hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h (original)
+++ hugo/branches/graph_factory/src/lemon/alteration_observer_registry.h Mon Oct 25 12:31:49 2004
@@ -33,18 +33,18 @@
/// Registry class to register objects observes alterations in the graph.
-
- /// This class is a registry for the objects which observe the alterations in
- /// a container. The alteration observers can be attached to and detached
- /// from the registry. The observers have to inherit from the /ref
- /// AlterationObserverRegistry::ObserverBase and override the virtual functions
- /// in that.
+ /// This class is a registry for the objects which observe the
+ /// alterations in a container. The alteration observers can be attached
+ /// to and detached from the registry. The observers have to inherit
+ /// from the \ref AlterationObserverRegistry::ObserverBase and override
+ /// the virtual functions in that.
///
- /// The most important application of the alteration observing is the dynamic
- /// map implementation when the observers are observing the alterations in the
- /// graph.
+ /// The most important application of the alteration observing is the
+ /// dynamic map implementation when the observers are observing the
+ /// alterations in the graph.
///
- /// \param _Item The item type what the observers are observing, usually edge or node.
+ /// \param _Item The item type what the observers are observing, usually
+ /// edge or node.
///
/// \author Balazs Dezso
@@ -53,27 +53,27 @@
public:
typedef _Item Item;
- /// ObserverBase is the base class of the observers.
+ /// ObserverBase is the base class for the observers.
- /// ObserverBase is the base class of the observers.
+ /// ObserverBase is the abstract base class for the observers.
/// It will be notified about an item was inserted into or
- /// erased from the graph.
+ /// erased from the graph.
///
- /// The observer interface contains some virtual function
- /// to override it. The add() and erase() functions are
- /// to notify the oberver about one item is added or
- /// erased.
+ /// The observer interface contains some pure virtual functions
+ /// to override. The add() and erase() functions are
+ /// to notify the oberver when one item is added or
+ /// erased.
///
/// The build() and clear() members are to notify the observer
/// about the container is builded from an empty container or
- /// the observer is cleared to an empty container.
+ /// is cleared to an empty container.
///
/// \author Balazs Dezso
class ObserverBase {
protected:
- typedef AlterationObserverRegistry<Item> Registry;
-
+ typedef AlterationObserverRegistry Registry;
+
friend class Registry;
/// Default constructor.
@@ -82,12 +82,6 @@
///
ObserverBase() : registry(0) {}
- /// Constructor to register observer into an observer registry.
-
- /// It constrates an observer and then registers it into an
- /// observer registry. This calls also the build() member
- /// to notify the observer about it is registered.
-
virtual ~ObserverBase() {}
/// Attaches the observer into an AlterationObserverRegistry.
@@ -101,7 +95,6 @@
/// Detaches the observer into an AlterationObserverRegistry.
-
/// This member detaches the observer from an AlterationObserverRegistry.
///
void detach() {
@@ -113,62 +106,63 @@
/// Gives back a pointer to the registry what the map attached into.
- /// This function gives back a pointer to the registry what the map attached into.
+ /// This function gives back a pointer to the registry what the map
+ /// attached into.
///
- Registry* getRegistry() const { return registry; }
+ Registry* getRegistry() const { return const_cast<Registry*>(registry); }
/// Gives back true when the observer is attached into a registry.
bool attached() const { return registry != 0; }
- protected:
+ private:
- ObserverBase(const ObserverBase& copy) {}
- const ObserverBase& operator=(const ObserverBase& copy) {}
+ ObserverBase(const ObserverBase& copy);
+ ObserverBase& operator=(const ObserverBase& copy);
protected:
- mutable Registry* registry;
+ Registry* registry;
int registry_index;
protected:
- /// The member function to notificate the observer about an item is added to the container.
-
- /// The add() member function notificates the observer about
- /// an item is added to the container. It have to be overrided in the subclasses.
+ /// \brief The member function to notificate the observer about an
+ /// item is added to the container.
+ ///
+ /// The add() member function notificates the observer about an item
+ /// is added to the container. It have to be overrided in the
+ /// subclasses.
virtual void add(const Item&) = 0;
- /// The member function to notificate the observer about an item is erased from the container.
-
- /// The erase() member function notificates the observer about
- /// an item is erased from the container. It have to be overrided in the subclasses.
+ /// \brief The member function to notificate the observer about an
+ /// item is erased from the container.
+ ///
+ /// The erase() member function notificates the observer about an
+ /// item is erased from the container. It have to be overrided in
+ /// the subclasses.
virtual void erase(const Item&) = 0;
- /// The member function to notificate the observer about the container is builded.
-
- /// The build() member function notificates the observer about
- /// the container is builded from an empty container. It have to be overrided in the subclasses.
+ /// \brief The member function to notificate the observer about the
+ /// container is builded.
+ ///
+ /// The build() member function notificates the observer about the
+ /// container is builded from an empty container. It have to be
+ /// overrided in the subclasses.
virtual void build() = 0;
- /// The member function to notificate the observer about all items are erased from the container.
-
- /// The clear() member function notificates the observer about
- /// all items are erased from the container. It have to be overrided in the subclasses.
+ /// \brief The member function to notificate the observer about all
+ /// items are erased from the container.
+ ///
+ /// The clear() member function notificates the observer about all
+ /// items are erased from the container. It have to be overrided in
+ /// the subclasses.
virtual void clear() = 0;
- /// Exception class to throw at unsupported operation.
-
- /// Exception class to throw at unsupported operation.
- /// If the observer does not support erasing or adding new
- /// item then this exception have to be throwed.
-
- class NotSupportedOperationException {};
-
};
protected:
Modified: hugo/branches/graph_factory/src/lemon/array_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/array_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/array_map.h Mon Oct 25 12:31:49 2004
@@ -55,6 +55,10 @@
typedef _Graph Graph;
/// The key type of the maps.
typedef _Item KeyType;
+
+ typedef AlterationObserverRegistry<_Item> Registry;
+
+ private:
/// The iterator to iterate on the keys.
typedef _ItemIt KeyIt;
@@ -62,8 +66,6 @@
typedef _Value Value;
- typedef AlterationObserverRegistry<_Item> Registry;
-
/// The MapBase of the Map which imlements the core regisitry function.
typedef typename Registry::ObserverBase Parent;
@@ -85,9 +87,12 @@
typedef const Value* ConstPointerType;
+ private:
typedef std::allocator<Value> Allocator;
-
+
+ public:
+
/** Graph and Registry initialized map constructor.
*/
ArrayMap(const Graph& _g, Registry& _r) : graph(&_g) {
@@ -116,7 +121,7 @@
*/
ArrayMap(const ArrayMap& copy) {
if (copy.attached()) {
- attach(copy.getRegistry());
+ attach(*copy.getRegistry());
}
capacity = copy.capacity;
if (capacity == 0) return;
@@ -138,7 +143,7 @@
detach();
}
if (copy.attached()) {
- attach(copy.getRegistry());
+ attach(*copy.getRegistry());
}
capacity = copy.capacity;
if (capacity == 0) return *this;
Modified: hugo/branches/graph_factory/src/lemon/default_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/default_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/default_map.h Mon Oct 25 12:31:49 2004
@@ -188,11 +188,11 @@
typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
+ typedef typename Parent::ValueType ValueType;
NodeMap(const Graph& g)
: Parent(g, g.getNodeObserverRegistry()) {}
- NodeMap(const Graph& g, const Value& v)
+ NodeMap(const Graph& g, const ValueType& v)
: Parent(g, g.getNodeObserverRegistry(), v) {}
};
@@ -209,11 +209,11 @@
typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
+ typedef typename Parent::ValueType ValueType;
EdgeMap(const Graph& g)
: Parent(g, g.getEdgeObserverRegistry()) {}
- EdgeMap(const Graph& g, const Value& v)
+ EdgeMap(const Graph& g, const ValueType& v)
: Parent(g, g.getEdgeObserverRegistry(), v) {}
};
Modified: hugo/branches/graph_factory/src/lemon/skeletons/graph_component.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/skeletons/graph_component.h (original)
+++ hugo/branches/graph_factory/src/lemon/skeletons/graph_component.h Mon Oct 25 12:31:49 2004
@@ -721,24 +721,24 @@
void constraints() {
{ // int map test
typedef typename Graph::template NodeMap<int> IntNodeMap;
- function_requires<GraphMapConcept<IntNodeMap> >();
+ function_requires<GraphMapConcept<IntNodeMap,Graph> >();
} { // bool map test
typedef typename Graph::template NodeMap<bool> BoolNodeMap;
- function_requires<GraphMapConcept<BoolNodeMap> >();
+ function_requires<GraphMapConcept<BoolNodeMap,Graph> >();
} { // Type map test
typedef typename Graph::template NodeMap<Type> TypeNodeMap;
- function_requires<GraphMapConcept<TypeNodeMap> >();
+ function_requires<GraphMapConcept<TypeNodeMap,Graph> >();
}
{ // int map test
typedef typename Graph::template EdgeMap<int> IntEdgeMap;
- function_requires<GraphMapConcept<IntEdgeMap> >();
+ function_requires<GraphMapConcept<IntEdgeMap,Graph> >();
} { // bool map test
typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;
- function_requires<GraphMapConcept<BoolEdgeMap> >();
+ function_requires<GraphMapConcept<BoolEdgeMap,Graph> >();
} { // Type map test
typedef typename Graph::template EdgeMap<Type> TypeEdgeMap;
- function_requires<GraphMapConcept<TypeEdgeMap> >();
+ function_requires<GraphMapConcept<TypeEdgeMap,Graph> >();
}
}
Modified: hugo/branches/graph_factory/src/lemon/skeletons/maps.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/skeletons/maps.h (original)
+++ hugo/branches/graph_factory/src/lemon/skeletons/maps.h Mon Oct 25 12:31:49 2004
@@ -218,11 +218,24 @@
/// \todo GraphMapConceptCheck
- template<typename GraphMap>
+ template<typename GraphMap, typename Graph>
struct GraphMapConcept {
void constraints() {
- function_requires< ReferenceMapConcept<GraphMap> >();
+ function_requires< ReadWriteMapConcept<GraphMap> >();
+ // Construction with a graph parameter
+ GraphMap a(g);
+ // Ctor with a graph and a default value parameter
+ GraphMap a2(g,t);
+ // Copy ctor. Do we need it?
+ GraphMap b=c;
+ // Copy operator. Do we need it?
+ a=b;
+
+ ignore_unused_variable_warning(a2);
}
+ const GraphMap &c;
+ const Graph &g;
+ const typename GraphMap::ValueType &t;
};
Modified: hugo/branches/graph_factory/src/lemon/vector_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/vector_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/vector_map.h Mon Oct 25 12:31:49 2004
@@ -111,11 +111,31 @@
VectorMap(const VectorMap& copy) : graph(copy.getGraph()) {
if (copy.attached()) {
attach(*copy.getRegistry());
- build();
+ container = copy.container;
}
}
- ~VectorMap() {
+
+ /** Assign operator to copy a map of the same map type.
+ */
+ VectorMap& operator=(const VectorMap& copy) {
+ if (© == this) return *this;
+
+ if (graph != copy.graph) {
+ if (attached()) {
+ detach();
+ }
+ if (copy.attached()) {
+ attach(*copy.getRegistry());
+ }
+ }
+ container = copy.container;
+
+ return *this;
+ }
+
+
+ virtual ~VectorMap() {
if (attached()) {
detach();
}
More information about the Lemon-commits
mailing list