# HG changeset patch # User deba # Date 1128530737 0 # Node ID a323456bf7c845b9e19cc3d845499585b40dd315 # Parent 8fea0e60f8555b544c88a94944e6c778818afa0f Template Named Parameter bugfix diff -r 8fea0e60f855 -r a323456bf7c8 doc/named-param.dox --- a/doc/named-param.dox Wed Oct 05 13:44:29 2005 +0000 +++ b/doc/named-param.dox Wed Oct 05 16:45:37 2005 +0000 @@ -82,14 +82,14 @@ be used like in the following cases. \code -Dijkstra<>::SetPredNodeMap > +Dijkstra<>::SetPredNodeMap >::Create \endcode It can also be used in conjunction with other named template parameters in arbitrary order. \code -Dijkstra<>::SetDistMap::SetPredMap > +Dijkstra<>::SetDistMap::SetPredMap >::Create \endcode The result will be an instantiated Dijkstra class, in which the diff -r 8fea0e60f855 -r a323456bf7c8 lemon/bfs.h --- a/lemon/bfs.h Wed Oct 05 13:44:29 2005 +0000 +++ b/lemon/bfs.h Wed Oct 05 16:45:37 2005 +0000 @@ -57,24 +57,6 @@ { return new PredMap(G); } -// ///\brief The type of the map that stores the last but one -// ///nodes of the shortest paths. -// /// -// ///The type of the map that stores the last but one -// ///nodes of the shortest paths. -// ///It must meet the \ref concept::WriteMap "WriteMap" concept. -// /// -// typedef NullMap PredNodeMap; -// ///Instantiates a PredNodeMap. - -// ///This function instantiates a \ref PredNodeMap. -// ///\param G is the graph, to which -// ///we would like to define the \ref PredNodeMap -// static PredNodeMap *createPredNodeMap(const GR &G) -// { -// return new PredNodeMap(); -// } - ///The type of the map that indicates which nodes are processed. ///The type of the map that indicates which nodes are processed. @@ -179,9 +161,6 @@ ///\brief The type of the map that stores the last ///edges of the shortest paths. typedef typename TR::PredMap PredMap; -// ///\brief The type of the map that stores the last but one -// ///nodes of the shortest paths. -// typedef typename TR::PredNodeMap PredNodeMap; ///The type of the map indicating which nodes are reached. typedef typename TR::ReachedMap ReachedMap; ///The type of the map indicating which nodes are processed. @@ -195,10 +174,6 @@ PredMap *_pred; ///Indicates if \ref _pred is locally allocated (\c true) or not. bool local_pred; -// ///Pointer to the map of predecessors nodes. -// PredNodeMap *_predNode; -// ///Indicates if \ref _predNode is locally allocated (\c true) or not. -// bool local_predNode; ///Pointer to the map of distances. DistMap *_dist; ///Indicates if \ref _dist is locally allocated (\c true) or not. @@ -215,8 +190,6 @@ std::vector _queue; int _queue_head,_queue_tail,_queue_next_dist; int _curr_dist; -// ///The source node of the last execution. -// Node source; ///Creates the maps if necessary. @@ -228,10 +201,6 @@ local_pred = true; _pred = Traits::createPredMap(*G); } -// if(!_predNode) { -// local_predNode = true; -// _predNode = Traits::createPredNodeMap(*G); -// } if(!_dist) { local_dist = true; _dist = Traits::createDistMap(*G); @@ -265,24 +234,9 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - class DefPredMap : public Bfs< Graph, DefPredMapTraits > { }; - -// template -// struct DefPredNodeMapTraits : public Traits { -// typedef T PredNodeMap; -// static PredNodeMap *createPredNodeMap(const Graph &G) -// { -// throw UninitializedParameter(); -// } -// }; -// ///\ref named-templ-param "Named parameter" for setting PredNodeMap type - -// ///\ref named-templ-param "Named parameter" for setting PredNodeMap type -// /// -// template -// class DefPredNodeMap : public Bfs< Graph, -// LengthMap, -// DefPredNodeMapTraits > { }; + struct DefPredMap : public Bfs< Graph, DefPredMapTraits > { + typedef Bfs< Graph, DefPredMapTraits > Create; + }; template struct DefDistMapTraits : public Traits { @@ -297,8 +251,9 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - class DefDistMap : public Bfs< Graph, - DefDistMapTraits > { }; + struct DefDistMap : public Bfs< Graph, DefDistMapTraits > { + typedef Bfs< Graph, DefDistMapTraits > Create; + }; template struct DefReachedMapTraits : public Traits { @@ -313,16 +268,10 @@ ///\ref named-templ-param "Named parameter" for setting ReachedMap type /// template - class DefReachedMap : public Bfs< Graph, - DefReachedMapTraits > { }; + struct DefReachedMap : public Bfs< Graph, DefReachedMapTraits > { + typedef Bfs< Graph, DefReachedMapTraits > Create; + }; - struct DefGraphReachedMapTraits : public Traits { - typedef typename Graph::template NodeMap ReachedMap; - static ReachedMap *createReachedMap(const Graph &G) - { - return new ReachedMap(G); - } - }; template struct DefProcessedMapTraits : public Traits { typedef T ProcessedMap; @@ -336,8 +285,9 @@ ///\ref named-templ-param "Named parameter" for setting ProcessedMap type /// template - class DefProcessedMap : public Bfs< Graph, - DefProcessedMapTraits > { }; + struct DefProcessedMap : public Bfs< Graph, DefProcessedMapTraits > { + typedef Bfs< Graph, DefProcessedMapTraits > Create; + }; struct DefGraphProcessedMapTraits : public Traits { typedef typename Graph::template NodeMap ProcessedMap; @@ -353,9 +303,10 @@ ///for setting the ProcessedMap type to be Graph::NodeMap. ///If you don't set it explicitly, it will be automatically allocated. template - class DefProcessedMapToBeDefaultMap : - public Bfs< Graph, - DefGraphProcessedMapTraits> { }; + struct DefProcessedMapToBeDefaultMap : + public Bfs< Graph, DefGraphProcessedMapTraits> { + typedef Bfs< Graph, DefGraphProcessedMapTraits> Create; + }; ///@} @@ -368,7 +319,6 @@ Bfs(const Graph& _G) : G(&_G), _pred(NULL), local_pred(false), -// _predNode(NULL), local_predNode(false), _dist(NULL), local_dist(false), _reached(NULL), local_reached(false), _processed(NULL), local_processed(false) @@ -378,7 +328,6 @@ ~Bfs() { if(local_pred) delete _pred; -// if(local_predNode) delete _predNode; if(local_dist) delete _dist; if(local_reached) delete _reached; if(local_processed) delete _processed; @@ -435,23 +384,6 @@ return *this; } -// ///Sets the map storing the predecessor nodes. - -// ///Sets the map storing the predecessor nodes. -// ///If you don't use this function before calling \ref run(), -// ///it will allocate one. The destructor deallocates this -// ///automatically allocated map, of course. -// ///\return (*this) -// Bfs &predNodeMap(PredNodeMap &m) -// { -// if(local_predNode) { -// delete _predNode; -// local_predNode=false; -// } -// _predNode = &m; -// return *this; -// } - ///Sets the map storing the distances calculated by the algorithm. ///Sets the map storing the distances calculated by the algorithm. @@ -494,7 +426,6 @@ _curr_dist=1; for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { _pred->set(u,INVALID); -// _predNode->set(u,INVALID); _reached->set(u,false); _processed->set(u,false); } @@ -537,7 +468,6 @@ _queue[_queue_head++]=m; _reached->set(m,true); _pred->set(m,e); -// _pred_node->set(m,n); _dist->set(m,_curr_dist); } return n; @@ -745,13 +675,6 @@ ///must be called before using this function. const PredMap &predMap() const { return *_pred;} -// ///Returns a reference to the map of nodes of shortest paths. - -// ///Returns a reference to the NodeMap of the last but one nodes of the -// ///shortest path tree. -// ///\pre \ref run() must be called before using this function. -// const PredNodeMap &predNodeMap() const { return *_predNode;} - ///Checks if a node is reachable from the root. ///Returns \c true if \c v is reachable from the root. @@ -794,23 +717,6 @@ { return new PredMap(); } -// ///\brief The type of the map that stores the last but one -// ///nodes of the shortest paths. -// /// -// ///The type of the map that stores the last but one -// ///nodes of the shortest paths. -// ///It must meet the \ref concept::WriteMap "WriteMap" concept. -// /// -// typedef NullMap PredNodeMap; -// ///Instantiates a PredNodeMap. - -// ///This function instantiates a \ref PredNodeMap. -// ///\param G is the graph, to which -// ///we would like to define the \ref PredNodeMap -// static PredNodeMap *createPredNodeMap(const GR &G) -// { -// return new PredNodeMap(); -// } ///The type of the map that indicates which nodes are processed. @@ -891,8 +797,6 @@ void *_processed; ///Pointer to the map of predecessors edges. void *_pred; -// ///Pointer to the map of predecessors nodes. -// void *_predNode; ///Pointer to the map of distances. void *_dist; ///Pointer to the source node. @@ -904,7 +808,6 @@ /// This constructor does not require parameters, therefore it initiates /// all of the attributes to default values (0, INVALID). BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), -// _predNode(0), _dist(0), _source(INVALID) {} /// Constructor. @@ -916,7 +819,6 @@ /// \param s is the initial value of \ref _source BfsWizardBase(const GR &g, Node s=INVALID) : _g((void *)&g), _reached(0), _processed(0), _pred(0), -// _predNode(0), _dist(0), _source(s) {} }; @@ -965,9 +867,6 @@ ///\brief The type of the map that stores the last ///edges of the shortest paths. typedef typename TR::PredMap PredMap; -// ///\brief The type of the map that stores the last but one -// ///nodes of the shortest paths. -// typedef typename TR::PredNodeMap PredNodeMap; ///The type of the map that stores the dists of the nodes. typedef typename TR::DistMap DistMap; @@ -999,7 +898,6 @@ alg.reachedMap(*(ReachedMap*)Base::_reached); if(Base::_processed) alg.processedMap(*(ProcessedMap*)Base::_processed); if(Base::_pred) alg.predMap(*(PredMap*)Base::_pred); -// if(Base::_predNode) alg.predNodeMap(*(PredNodeMap*)Base::_predNode); if(Base::_dist) alg.distMap(*(DistMap*)Base::_dist); alg.run(Base::_source); } @@ -1076,26 +974,6 @@ return BfsWizard >(*this); } - -// template -// struct DefPredNodeMapBase : public Base { -// typedef T PredNodeMap; -// static PredNodeMap *createPredNodeMap(const Graph &G) { return 0; }; -// DefPredNodeMapBase(const TR &b) : TR(b) {} -// }; - -// ///\brief \ref named-templ-param "Named parameter" -// ///function for setting PredNodeMap type -// /// -// /// \ref named-templ-param "Named parameter" -// ///function for setting PredNodeMap type -// /// -// template -// BfsWizard > predNodeMap(const T &t) -// { -// Base::_predNode=(void *)&t; -// return BfsWizard >(*this); -// } template struct DefDistMapBase : public Base { diff -r 8fea0e60f855 -r a323456bf7c8 lemon/dfs.h --- a/lemon/dfs.h Wed Oct 05 13:44:29 2005 +0000 +++ b/lemon/dfs.h Wed Oct 05 16:45:37 2005 +0000 @@ -57,23 +57,6 @@ { return new PredMap(G); } -// ///\brief The type of the map that stores the last but one -// ///nodes of the %DFS paths. -// /// -// ///The type of the map that stores the last but one -// ///nodes of the %DFS paths. -// ///It must meet the \ref concept::WriteMap "WriteMap" concept. -// /// -// typedef NullMap PredNodeMap; -// ///Instantiates a PredNodeMap. - -// ///This function instantiates a \ref PredNodeMap. -// ///\param G is the graph, to which -// ///we would like to define the \ref PredNodeMap -// static PredNodeMap *createPredNodeMap(const GR &G) -// { -// return new PredNodeMap(); -// } ///The type of the map that indicates which nodes are processed. @@ -179,9 +162,6 @@ ///\brief The type of the map that stores the last ///edges of the %DFS paths. typedef typename TR::PredMap PredMap; -// ///\brief The type of the map that stores the last but one -// ///nodes of the %DFS paths. -// typedef typename TR::PredNodeMap PredNodeMap; ///The type of the map indicating which nodes are reached. typedef typename TR::ReachedMap ReachedMap; ///The type of the map indicating which nodes are processed. @@ -195,10 +175,6 @@ PredMap *_pred; ///Indicates if \ref _pred is locally allocated (\c true) or not. bool local_pred; -// ///Pointer to the map of predecessors nodes. -// PredNodeMap *_predNode; -// ///Indicates if \ref _predNode is locally allocated (\c true) or not. -// bool local_predNode; ///Pointer to the map of distances. DistMap *_dist; ///Indicates if \ref _dist is locally allocated (\c true) or not. @@ -214,8 +190,6 @@ std::vector _stack; int _stack_head; -// ///The source node of the last execution. -// Node source; ///Creates the maps if necessary. @@ -227,10 +201,6 @@ local_pred = true; _pred = Traits::createPredMap(*G); } -// if(!_predNode) { -// local_predNode = true; -// _predNode = Traits::createPredNodeMap(*G); -// } if(!_dist) { local_dist = true; _dist = Traits::createDistMap(*G); @@ -246,7 +216,9 @@ } public : - + + typedef Dfs Create; + ///\name Named template parameters ///@{ @@ -264,25 +236,10 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - class DefPredMap : public Dfs< Graph, - DefPredMapTraits > { }; + struct DefPredMap : public Dfs > { + typedef Dfs > Create; + }; -// template -// struct DefPredNodeMapTraits : public Traits { -// typedef T PredNodeMap; -// static PredNodeMap *createPredNodeMap(const Graph &G) -// { -// throw UninitializedParameter(); -// } -// }; -// ///\ref named-templ-param "Named parameter" for setting PredNodeMap type - -// ///\ref named-templ-param "Named parameter" for setting PredNodeMap type -// /// -// template -// class DefPredNodeMap : public Dfs< Graph, -// LengthMap, -// DefPredNodeMapTraits > { }; template struct DefDistMapTraits : public Traits { @@ -297,8 +254,9 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - class DefDistMap : public Dfs< Graph, - DefDistMapTraits > { }; + struct DefDistMap { + typedef Dfs > Create; + }; template struct DefReachedMapTraits : public Traits { @@ -313,16 +271,10 @@ ///\ref named-templ-param "Named parameter" for setting ReachedMap type /// template - class DefReachedMap : public Dfs< Graph, - DefReachedMapTraits > { }; - - struct DefGraphReachedMapTraits : public Traits { - typedef typename Graph::template NodeMap ReachedMap; - static ReachedMap *createReachedMap(const Graph &G) - { - return new ReachedMap(G); - } + struct DefReachedMap { + typedef Dfs< Graph, DefReachedMapTraits > Create; }; + template struct DefProcessedMapTraits : public Traits { typedef T ProcessedMap; @@ -337,7 +289,7 @@ /// template struct DefProcessedMap : public Dfs< Graph, DefProcessedMapTraits > { - typedef Dfs< Graph, DefProcessedMapTraits > Dfs; + typedef Dfs< Graph, DefProcessedMapTraits > Create; }; struct DefGraphProcessedMapTraits : public Traits { @@ -355,8 +307,9 @@ ///If you don't set it explicitely, it will be automatically allocated. template class DefProcessedMapToBeDefaultMap : - public Dfs< Graph, - DefGraphProcessedMapTraits> { }; + public Dfs< Graph, DefGraphProcessedMapTraits> { + typedef Dfs< Graph, DefGraphProcessedMapTraits> Create; + }; ///@} diff -r 8fea0e60f855 -r a323456bf7c8 lemon/dijkstra.h --- a/lemon/dijkstra.h Wed Oct 05 13:44:29 2005 +0000 +++ b/lemon/dijkstra.h Wed Oct 05 16:45:37 2005 +0000 @@ -56,8 +56,7 @@ /// ///\sa BinHeap ///\sa Dijkstra - typedef BinHeap, std::less > Heap; @@ -255,9 +254,10 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - class DefPredMap : public Dijkstra< Graph, - LengthMap, - DefPredMapTraits > { }; + struct DefPredMap + : public Dijkstra< Graph, LengthMap, DefPredMapTraits > { + typedef Dijkstra< Graph, LengthMap, DefPredMapTraits > Create; + }; template struct DefDistMapTraits : public Traits { @@ -272,9 +272,10 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - class DefDistMap : public Dijkstra< Graph, - LengthMap, - DefDistMapTraits > { }; + struct DefDistMap + : public Dijkstra< Graph, LengthMap, DefDistMapTraits > { + typedef Dijkstra< Graph, LengthMap, DefDistMapTraits > Create; + }; template struct DefProcessedMapTraits : public Traits { @@ -289,9 +290,10 @@ ///\ref named-templ-param "Named parameter" for setting ProcessedMap type /// template - class DefProcessedMap : public Dijkstra< Graph, - LengthMap, - DefProcessedMapTraits > { }; + struct DefProcessedMap + : public Dijkstra< Graph, LengthMap, DefProcessedMapTraits > { + typedef Dijkstra< Graph, LengthMap, DefProcessedMapTraits > Create; + }; struct DefGraphProcessedMapTraits : public Traits { typedef typename Graph::template NodeMap ProcessedMap; @@ -307,10 +309,10 @@ ///for setting the ProcessedMap type to be Graph::NodeMap. ///If you don't set it explicitely, it will be automatically allocated. template - class DefProcessedMapToBeDefaultMap : - public Dijkstra< Graph, - LengthMap, - DefGraphProcessedMapTraits> { }; + struct DefProcessedMapToBeDefaultMap + : public Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> { + typedef Dijkstra< Graph, LengthMap, DefGraphProcessedMapTraits> Create; + }; ///@} diff -r 8fea0e60f855 -r a323456bf7c8 lemon/topology.h --- a/lemon/topology.h Wed Oct 05 13:44:29 2005 +0000 +++ b/lemon/topology.h Wed Oct 05 16:45:37 2005 +0000 @@ -73,7 +73,7 @@ typedef BackCounterMap ProcessedMap; typename Dfs::template DefProcessedMap:: - Dfs dfs(graph); + Create dfs(graph); ProcessedMap processed(nodeMap, countNodes(graph)); @@ -111,7 +111,7 @@ typedef typename Graph::template NodeMap ProcessedMap; typename Dfs::template DefProcessedMap:: - Dfs dfs(graph); + Create dfs(graph); ProcessedMap processed(graph); dfs.processedMap(processed);