[Lemon-commits] [lemon_svn] deba: r2185 - in hugo/trunk/lemon: . bits concept
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:46 CET 2006
Author: deba
Date: Wed Aug 31 15:29:32 2005
New Revision: 2185
Modified:
hugo/trunk/lemon/bits/array_map.h
hugo/trunk/lemon/bits/default_map.h
hugo/trunk/lemon/bits/vector_map.h
hugo/trunk/lemon/concept/graph_component.h
hugo/trunk/lemon/concept/undir_graph.h
hugo/trunk/lemon/full_graph.h
hugo/trunk/lemon/graph_adaptor.h
hugo/trunk/lemon/list_graph.h
hugo/trunk/lemon/maps.h
hugo/trunk/lemon/smart_graph.h
Log:
Template assign operator for graph maps.
Some naming and coding conventions.
Modified: hugo/trunk/lemon/bits/array_map.h
==============================================================================
--- hugo/trunk/lemon/bits/array_map.h (original)
+++ hugo/trunk/lemon/bits/array_map.h Wed Aug 31 15:29:32 2005
@@ -19,26 +19,27 @@
#include <memory>
#include <lemon/bits/map_iterator.h>
+#include <lemon/concept_check.h>
+#include <lemon/concept/maps.h>
-///\ingroup graphmapfactory
-///\file
-///\brief Graph maps that construates and destruates
-///their elements dynamically.
+/// \ingroup graphmapfactory
+/// \file
+/// \brief Graph maps that construct and destruct
+/// their elements dynamically.
namespace lemon {
-
- /// \addtogroup graphmapfactory
- /// @{
-
+ /// \ingroup graphmapfactory
+ ///
+ /// \brief Graph map based on the array storage.
+ ///
/// The ArrayMap template class is graph map structure what
/// automatically updates the map when a key is added to or erased from
- /// the map. This map factory uses the allocators to implement
+ /// the map. This map uses the allocators to implement
/// the container functionality.
///
/// The template parameter is the AlterationNotifier that the maps
/// will belong to and the Value.
-
template <typename _Graph,
typename _Item,
@@ -69,7 +70,6 @@
public:
/// Graph and Registry initialized map constructor.
-
ArrayMap(const Graph& _g) : graph(&_g) {
Item it;
attach(_g.getNotifier(Item()));
@@ -110,47 +110,33 @@
}
}
- using Parent::attach;
- using Parent::detach;
- using Parent::attached;
-
- /// Assign operator to copy a map of the same map type.
-
- ArrayMap& operator=(const ArrayMap& copy) {
- if (© == this) return *this;
-
- if (graph != copy.graph) {
- if (attached()) {
- clear();
- detach();
- }
- if (copy.attached()) {
- attach(*copy.getRegistry());
- }
- capacity = copy.capacity;
- if (capacity == 0) return *this;
- values = allocator.allocate(capacity);
- }
-
- Item it;
- for (graph->first(it); it != INVALID; graph->next(it)) {
- int id = graph->id(it);;
- allocator.construct(&(values[id]), copy.values[id]);
- }
-
- return *this;
- }
-
+ /// \brief The destructor of the map.
+ ///
/// The destructor of the map.
-
virtual ~ArrayMap() {
if (attached()) {
clear();
detach();
}
}
-
-
+
+ private:
+
+ ArrayMap& operator=(const ArrayMap&);
+
+ protected:
+
+ using Parent::attach;
+ using Parent::detach;
+ using Parent::attached;
+
+ const Graph* getGraph() {
+ return graph;
+ }
+
+
+ public:
+
///The subscript operator. The map can be subscripted by the
///actual keys of the graph.
@@ -174,7 +160,9 @@
void set(const Key& key, const Value& val) {
(*this)[key] = val;
}
-
+
+ protected:
+
/// Add a new key to the map. It called by the map registry.
void add(const Key& key) {
@@ -274,10 +262,6 @@
}
}
- const Graph* getGraph() {
- return graph;
- }
-
private:
void allocate_memory() {
@@ -301,69 +285,6 @@
};
- template <typename _Base>
- class ArrayMappableGraphExtender : public _Base {
- public:
-
- typedef ArrayMappableGraphExtender<_Base> Graph;
- typedef _Base Parent;
-
- typedef typename Parent::Node Node;
- typedef typename Parent::NodeIt NodeIt;
- typedef typename Parent::NodeNotifier NodeObserverRegistry;
-
- typedef typename Parent::Edge Edge;
- typedef typename Parent::EdgeIt EdgeIt;
- typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
-
-
-
- template <typename _Value>
- class NodeMap
- : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
- public:
- typedef ArrayMappableGraphExtender<_Base> Graph;
-
- typedef typename Graph::Node Node;
- typedef typename Graph::NodeIt NodeIt;
-
- typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
-
- //typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
-
- NodeMap(const Graph& g)
- : Parent(g) {}
- NodeMap(const Graph& g, const Value& v)
- : Parent(g, v) {}
-
- };
-
- template <typename _Value>
- class EdgeMap
- : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
- public:
- typedef ArrayMappableGraphExtender<_Base> Graph;
-
- typedef typename Graph::Edge Edge;
- typedef typename Graph::EdgeIt EdgeIt;
-
- typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
-
- //typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
-
- EdgeMap(const Graph& g)
- : Parent(g) {}
- EdgeMap(const Graph& g, const Value& v)
- : Parent(g, v) {}
-
- };
-
- };
-
-/// @}
-
}
#endif //LEMON_ARRAY_MAP_H
Modified: hugo/trunk/lemon/bits/default_map.h
==============================================================================
--- hugo/trunk/lemon/bits/default_map.h (original)
+++ hugo/trunk/lemon/bits/default_map.h Wed Aug 31 15:29:32 2005
@@ -28,19 +28,8 @@
namespace lemon {
-/// \addtogroup graphmapfactory
-/// @{
-
- /** The ArrayMap template class is graph map structure what
- * automatically updates the map when a key is added to or erased from
- * the map. This map uses the VectorMap if the Value is a primitive
- * type and the ArrayMap for the other cases.
- *
- * The template parameter is the MapRegistry that the maps
- * will belong to and the Value.
- */
-
-
+ /// \addtogroup graphmapfactory
+ /// @{
template <typename _Graph, typename _Item, typename _Value>
struct DefaultMapSelector {
@@ -135,8 +124,7 @@
typedef VectorMap<_Graph, _Item, _Ptr*> Map;
};
-
-
+ /// \e
template <
typename _Graph,
typename _Item,
@@ -152,15 +140,16 @@
DefaultMap(const Graph& _g) : Parent(_g) {}
DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
- };
+ };
+ /// \e
template <typename _Base>
- class DefaultMappableGraphExtender : public _Base {
+ class MappableGraphExtender : public _Base {
public:
- typedef DefaultMappableGraphExtender<_Base> Graph;
+ typedef MappableGraphExtender<_Base> Graph;
typedef _Base Parent;
typedef typename Parent::Node Node;
@@ -174,37 +163,67 @@
class NodeMap
: public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
public:
- typedef DefaultMappableGraphExtender Graph;
+ typedef MappableGraphExtender Graph;
typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
NodeMap(const Graph& _g)
: Parent(_g) {}
NodeMap(const Graph& _g, const _Value& _v)
: Parent(_g, _v) {}
+
+ /// \brief Template assign operator.
+ ///
+ /// The given parameter should be conform to the ReadMap
+ /// concecpt and could be indiced by the current item set of
+ /// the NodeMap. In this case the value for each item
+ /// is assigned by the value of the given ReadMap.
+ template <typename CMap>
+ NodeMap& operator=(const CMap& cmap) {
+ checkConcept<concept::ReadMap<Node, _Value>, CMap>();
+ const typename Parent::Graph* graph = Parent::getGraph();
+ Node it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
+ Parent::set(it, cmap[it]);
+ }
+ return *this;
+ }
+
};
template <typename _Value>
class EdgeMap
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
public:
- typedef DefaultMappableGraphExtender Graph;
+ typedef MappableGraphExtender Graph;
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
EdgeMap(const Graph& _g)
: Parent(_g) {}
EdgeMap(const Graph& _g, const _Value& _v)
: Parent(_g, _v) {}
+
+ template <typename CMap>
+ EdgeMap& operator=(const CMap& cmap) {
+ checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
+ const typename Parent::Graph* graph = Parent::getGraph();
+ Edge it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
+ Parent::set(it, cmap[it]);
+ }
+ return *this;
+ }
};
};
+ /// \e
template <typename _Base>
class MappableUndirGraphExtender :
- public DefaultMappableGraphExtender<_Base> {
+ public MappableGraphExtender<_Base> {
public:
typedef MappableUndirGraphExtender Graph;
- typedef DefaultMappableGraphExtender<_Base> Parent;
+ typedef MappableGraphExtender<_Base> Parent;
typedef typename Parent::UndirEdge UndirEdge;
@@ -220,11 +239,23 @@
: Parent(_g) {}
UndirEdgeMap(const Graph& _g, const _Value& _v)
: Parent(_g, _v) {}
+
+ template <typename CMap>
+ UndirEdgeMap& operator=(const CMap& cmap) {
+ checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
+ const typename Parent::Graph* graph = Parent::getGraph();
+ UndirEdge it;
+ for (graph->first(it); it != INVALID; graph->next(it)) {
+ Parent::set(it, cmap[it]);
+ }
+ return *this;
+ }
};
};
+ /// @}
}
#endif
Modified: hugo/trunk/lemon/bits/vector_map.h
==============================================================================
--- hugo/trunk/lemon/bits/vector_map.h (original)
+++ hugo/trunk/lemon/bits/vector_map.h Wed Aug 31 15:29:32 2005
@@ -23,16 +23,20 @@
#include <lemon/utility.h>
#include <lemon/bits/map_iterator.h>
#include <lemon/bits/alteration_notifier.h>
+#include <lemon/concept_check.h>
+#include <lemon/concept/maps.h>
-///\ingroup graphmapfactory
+/// \ingroup graphmapfactory
+///
///\file
///\brief Vector based graph maps.
namespace lemon {
-
- /// \addtogroup graphmapfactory
- /// @{
-
+
+ /// \ingroup graphmapfactory
+ ///
+ /// \brief Graph map based on the std::vector storage.
+ ///
/// The VectorMap template class is graph map structure what
/// automatically updates the map when a key is added to or erased from
/// the map. This map factory uses the allocators to implement
@@ -117,39 +121,29 @@
}
}
- using Parent::attach;
- using Parent::detach;
- using Parent::attached;
-
- /** 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();
}
}
+
+ private:
+
+ VectorMap& operator=(const VectorMap&);
+
+ protected:
+
+ using Parent::attach;
+ using Parent::detach;
+ using Parent::attached;
+
const Graph* getGraph() const {
return graph;
}
+ public:
+
/// The subcript operator.
/// The subscript operator. The map can be subscripted by the
@@ -173,13 +167,14 @@
/// It the same as operator[](key) = value expression.
///
-
void set(const Key& key, const Value& value) {
(*this)[key] = value;
}
- /// Adds a new key to the map.
-
+ protected:
+
+ /// \brief Adds a new key to the map.
+ ///
/// It adds a new key to the map. It called by the observer registry
/// and it overrides the add() member function of the observer base.
@@ -220,69 +215,6 @@
};
-
- template <typename _Base>
- class VectorMappableGraphExtender : public _Base {
- public:
-
- typedef VectorMappableGraphExtender<_Base> Graph;
- typedef _Base Parent;
-
- typedef typename Parent::Node Node;
- typedef typename Parent::NodeIt NodeIt;
- typedef typename Parent::NodeIdMap NodeIdMap;
- typedef typename Parent::NodeNotifier NodeObserverRegistry;
-
- typedef typename Parent::Edge Edge;
- typedef typename Parent::EdgeIt EdgeIt;
- typedef typename Parent::EdgeIdMap EdgeIdMap;
- typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
-
-
- template <typename _Value>
- class NodeMap :
- public IterableMapExtender<VectorMap<Graph, Node, _Value> > {
- public:
- typedef VectorMappableGraphExtender<_Base> Graph;
-
- typedef typename Graph::Node Node;
-
- typedef IterableMapExtender<VectorMap<Graph, Node, _Value> > Parent;
-
- //typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
-
- NodeMap(const Graph& g)
- : Parent(g) {}
- NodeMap(const Graph& g, const Value& v)
- : Parent(g, v) {}
-
- };
-
- template <typename _Value>
- class EdgeMap
- : public IterableMapExtender<VectorMap<Graph, Edge, _Value> > {
- public:
- typedef VectorMappableGraphExtender<_Base> Graph;
-
- typedef typename Graph::Edge Edge;
-
- typedef IterableMapExtender<VectorMap<Graph, Edge, _Value> > Parent;
-
- //typedef typename Parent::Graph Graph;
- typedef typename Parent::Value Value;
-
- EdgeMap(const Graph& g)
- : Parent(g) {}
- EdgeMap(const Graph& g, const Value& v)
- : Parent(g, v) {}
-
- };
-
- };
-
- /// @}
-
}
#endif
Modified: hugo/trunk/lemon/concept/graph_component.h
==============================================================================
--- hugo/trunk/lemon/concept/graph_component.h (original)
+++ hugo/trunk/lemon/concept/graph_component.h Wed Aug 31 15:29:32 2005
@@ -798,8 +798,6 @@
_Map a2(g,t);
// Copy constructor. Do we need it?
_Map b=c;
- // Copy operator. Do we need it?
- a=b;
ignore_unused_variable_warning(a2);
}
Modified: hugo/trunk/lemon/concept/undir_graph.h
==============================================================================
--- hugo/trunk/lemon/concept/undir_graph.h (original)
+++ hugo/trunk/lemon/concept/undir_graph.h Wed Aug 31 15:29:32 2005
@@ -248,9 +248,9 @@
///
typedef True UndirTag;
- /// The base type of node iterators,
+ /// \brief The base type of node iterators,
/// or in other words, the trivial node iterator.
-
+ ///
/// This is the base type of each node iterator,
/// thus each kind of node iterator converts to this.
/// More precisely each kind of node iterator should be inherited
Modified: hugo/trunk/lemon/full_graph.h
==============================================================================
--- hugo/trunk/lemon/full_graph.h (original)
+++ hugo/trunk/lemon/full_graph.h Wed Aug 31 15:29:32 2005
@@ -195,8 +195,9 @@
AlterableFullGraphBase;
typedef IterableGraphExtender<AlterableFullGraphBase>
IterableFullGraphBase;
- typedef DefaultMappableGraphExtender<IterableFullGraphBase>
- MappableFullGraphBase;
+ typedef MappableGraphExtender<
+ IterableGraphExtender<
+ AlterableGraphExtender<FullGraphBase> > > ExtendedFullGraphBase;
/// \ingroup graphs
///
@@ -210,7 +211,7 @@
/// \sa concept::StaticGraph.
///
/// \author Alpar Juttner
- class FullGraph : public MappableFullGraphBase {
+ class FullGraph : public ExtendedFullGraphBase {
public:
FullGraph(int n) { construct(n); }
@@ -378,14 +379,10 @@
};
- typedef UndirGraphExtender<UndirFullGraphBase>
- UndirUndirFullGraphBase;
- typedef AlterableUndirGraphExtender<UndirUndirFullGraphBase>
- AlterableUndirFullGraphBase;
- typedef IterableUndirGraphExtender<AlterableUndirFullGraphBase>
- IterableUndirFullGraphBase;
- typedef MappableUndirGraphExtender<IterableUndirFullGraphBase>
- MappableUndirFullGraphBase;
+ typedef MappableUndirGraphExtender<
+ IterableUndirGraphExtender<
+ AlterableUndirGraphExtender<
+ UndirGraphExtender<UndirFullGraphBase> > > > ExtendedUndirFullGraphBase;
/// \ingroup graphs
///
@@ -402,7 +399,7 @@
/// \sa FullGraph
///
/// \author Balazs Dezso
- class UndirFullGraph : public MappableUndirFullGraphBase {
+ class UndirFullGraph : public ExtendedUndirFullGraphBase {
public:
UndirFullGraph(int n) { construct(n); }
};
Modified: hugo/trunk/lemon/graph_adaptor.h
==============================================================================
--- hugo/trunk/lemon/graph_adaptor.h (original)
+++ hugo/trunk/lemon/graph_adaptor.h Wed Aug 31 15:29:32 2005
@@ -1430,7 +1430,7 @@
public ErasableGraphExtender<
ClearableGraphExtender<
ExtendableGraphExtender<
- DefaultMappableGraphExtender<
+ MappableGraphExtender<
IterableGraphExtender<
AlterableGraphExtender<
NewEdgeSetAdaptorBase<_Graph> > > > > > > {
@@ -1440,7 +1440,7 @@
typedef ErasableGraphExtender<
ClearableGraphExtender<
ExtendableGraphExtender<
- DefaultMappableGraphExtender<
+ MappableGraphExtender<
IterableGraphExtender<
AlterableGraphExtender<
NewEdgeSetAdaptorBase<_Graph> > > > > > > Parent;
Modified: hugo/trunk/lemon/list_graph.h
==============================================================================
--- hugo/trunk/lemon/list_graph.h (original)
+++ hugo/trunk/lemon/list_graph.h Wed Aug 31 15:29:32 2005
@@ -304,10 +304,15 @@
typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
- typedef DefaultMappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
+ typedef MappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
- typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
+ typedef ErasableGraphExtender<
+ ClearableGraphExtender<
+ ExtendableGraphExtender<
+ MappableGraphExtender<
+ IterableGraphExtender<
+ AlterableGraphExtender<ListGraphBase> > > > > > ExtendedListGraphBase;
/// \addtogroup graphs
/// @{
@@ -321,7 +326,7 @@
///it also provides several additional useful extra functionalities.
///\sa concept::ErasableGraph.
- class ListGraph : public ErasableListGraphBase
+ class ListGraph : public ExtendedListGraphBase
{
public:
/// Changes the target of \c e to \c n
@@ -549,7 +554,7 @@
MappableUndirGraphExtender<
IterableUndirGraphExtender<
AlterableUndirGraphExtender<
- UndirGraphExtender<ListGraphBase> > > > > > > ErasableUndirListGraphBase;
+ UndirGraphExtender<ListGraphBase> > > > > > > ExtendedUndirListGraphBase;
/// \addtogroup graphs
/// @{
@@ -566,7 +571,7 @@
///\todo SnapShot, reverseEdge(), changeTarget(), changeSource(), contract()
///haven't been implemented yet.
///
- class UndirListGraph : public ErasableUndirListGraphBase {
+ class UndirListGraph : public ExtendedUndirListGraphBase {
};
Modified: hugo/trunk/lemon/maps.h
==============================================================================
--- hugo/trunk/lemon/maps.h (original)
+++ hugo/trunk/lemon/maps.h Wed Aug 31 15:29:32 2005
@@ -113,10 +113,10 @@
///This function just returns a \ref ConstMap class.
///\relates ConstMap
- template<class V,class K>
- inline ConstMap<V,K> constMap(const K &k)
+ template<class K,class V>
+ inline ConstMap<K,V> constMap(const V &v)
{
- return ConstMap<V,K>(k);
+ return ConstMap<K,V>(v);
}
Modified: hugo/trunk/lemon/smart_graph.h
==============================================================================
--- hugo/trunk/lemon/smart_graph.h (original)
+++ hugo/trunk/lemon/smart_graph.h Wed Aug 31 15:29:32 2005
@@ -233,11 +233,11 @@
};
- typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
- typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
- typedef DefaultMappableGraphExtender<IterableSmartGraphBase> MappableSmartGraphBase;
- typedef ExtendableGraphExtender<MappableSmartGraphBase> ExtendableSmartGraphBase;
- typedef ClearableGraphExtender<ExtendableSmartGraphBase> ClearableSmartGraphBase;
+ typedef ClearableGraphExtender<
+ ExtendableGraphExtender<
+ MappableGraphExtender<
+ IterableGraphExtender<
+ AlterableGraphExtender<SmartGraphBase> > > > > ExtendedSmartGraphBase;
/// \addtogroup graphs
/// @{
@@ -253,7 +253,7 @@
///\sa concept::ExtendableGraph.
///
///\author Alpar Juttner
- class SmartGraph : public ClearableSmartGraphBase {
+ class SmartGraph : public ExtendedSmartGraphBase {
public:
/// Finds an edge between two nodes.
@@ -390,7 +390,7 @@
MappableUndirGraphExtender<
IterableUndirGraphExtender<
AlterableUndirGraphExtender<
- UndirGraphExtender<SmartGraphBase> > > > > > UndirSmartGraphBase;
+ UndirGraphExtender<SmartGraphBase> > > > > > ExtendedUndirSmartGraphBase;
///A smart undirected graph class.
@@ -404,7 +404,7 @@
///
///\todo SnapShot hasn't been implemented yet.
///
- class UndirSmartGraph : public UndirSmartGraphBase {
+ class UndirSmartGraph : public ExtendedUndirSmartGraphBase {
};
More information about the Lemon-commits
mailing list