Changeset 997:665ffade9aca in lemon0.x for src/lemon/graph_wrapper.h
 Timestamp:
 11/15/04 17:39:55 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1387
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/lemon/graph_wrapper.h
r992 r997 212 212 }; 213 213 214 template <typename _Graph> 215 class RevGraphWrapperBase : public GraphWrapperBase<_Graph> { 216 public: 217 typedef _Graph Graph; 218 typedef GraphWrapperBase<_Graph> Parent; 219 protected: 220 RevGraphWrapperBase() : Parent() { } 221 public: 222 typedef typename Parent::Node Node; 223 typedef typename Parent::Edge Edge; 224 225 using Parent::first; 226 void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); } 227 void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); } 228 229 using Parent::next; 230 void nextIn(Edge& i) const { Parent::nextOut(i); } 231 void nextOut(Edge& i) const { Parent::nextIn(i); } 232 233 Node source(const Edge& e) const { return Parent::target(e); } 234 Node target(const Edge& e) const { return Parent::source(e); } 235 }; 236 237 214 238 /// A graph wrapper which reverses the orientation of the edges. 215 239 … … 235 259 /// \endcode 236 260 ///\author Marton Makai 237 template<typename Graph> 238 class RevGraphWrapper : public GraphWrapper<Graph> { 239 public: 240 typedef GraphWrapper<Graph> Parent; 261 template<typename _Graph> 262 class RevGraphWrapper : 263 public IterableGraphExtender<RevGraphWrapperBase<_Graph> > { 264 public: 265 typedef _Graph Graph; 266 typedef IterableGraphExtender< 267 RevGraphWrapperBase<_Graph> > Parent; 241 268 protected: 242 RevGraphWrapper() : GraphWrapper<Graph>() { } 243 public: 244 RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } 245 RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { } 246 247 typedef typename GraphWrapper<Graph>::Node Node; 248 typedef typename GraphWrapper<Graph>::Edge Edge; 249 //remark: OutEdgeIt and InEdgeIt cannot be typedefed to each other 250 //because this does not work is some of them are not defined in the 251 //original graph. The problem with this is that typedefed stuff 252 //are instantiated in c++. 253 class OutEdgeIt : public Edge { 254 const RevGraphWrapper<Graph>* gw; 255 friend class GraphWrapper<Graph>; 256 public: 257 OutEdgeIt() { } 258 OutEdgeIt(Invalid i) : Edge(i) { } 259 OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 260 Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 261 OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 262 Edge(e), gw(&_gw) { } 263 OutEdgeIt& operator++() { 264 *(static_cast<Edge*>(this))= 265 ++(typename Graph::InEdgeIt(*(gw>graph), *this)); 266 return *this; 267 } 268 }; 269 class InEdgeIt : public Edge { 270 const RevGraphWrapper<Graph>* gw; 271 friend class GraphWrapper<Graph>; 272 public: 273 InEdgeIt() { } 274 InEdgeIt(Invalid i) : Edge(i) { } 275 InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 276 Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 277 InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 278 Edge(e), gw(&_gw) { } 279 InEdgeIt& operator++() { 280 *(static_cast<Edge*>(this))= 281 ++(typename Graph::OutEdgeIt(*(gw>graph), *this)); 282 return *this; 283 } 284 }; 285 286 using GraphWrapper<Graph>::first; 287 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 288 i=OutEdgeIt(*this, p); return i; 289 } 290 InEdgeIt& first(InEdgeIt& i, const Node& p) const { 291 i=InEdgeIt(*this, p); return i; 292 } 293 294 Node source(const Edge& e) const { 295 return GraphWrapper<Graph>::target(e); } 296 Node target(const Edge& e) const { 297 return GraphWrapper<Graph>::source(e); } 298 299 // KEEP_MAPS(Parent, RevGraphWrapper); 300 269 RevGraphWrapper() { } 270 public: 271 RevGraphWrapper(_Graph& _graph) { setGraph(_graph); } 301 272 }; 273 // template<typename Graph> 274 // class RevGraphWrapper : public GraphWrapper<Graph> { 275 // public: 276 // typedef GraphWrapper<Graph> Parent; 277 // protected: 278 // RevGraphWrapper() : GraphWrapper<Graph>() { } 279 // public: 280 // RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } 281 // RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { } 282 283 // typedef typename GraphWrapper<Graph>::Node Node; 284 // typedef typename GraphWrapper<Graph>::Edge Edge; 285 // //remark: OutEdgeIt and InEdgeIt cannot be typedefed to each other 286 // //because this does not work is some of them are not defined in the 287 // //original graph. The problem with this is that typedefed stuff 288 // //are instantiated in c++. 289 // class OutEdgeIt : public Edge { 290 // const RevGraphWrapper<Graph>* gw; 291 // friend class GraphWrapper<Graph>; 292 // public: 293 // OutEdgeIt() { } 294 // OutEdgeIt(Invalid i) : Edge(i) { } 295 // OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 296 // Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 297 // OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 298 // Edge(e), gw(&_gw) { } 299 // OutEdgeIt& operator++() { 300 // *(static_cast<Edge*>(this))= 301 // ++(typename Graph::InEdgeIt(*(gw>graph), *this)); 302 // return *this; 303 // } 304 // }; 305 // class InEdgeIt : public Edge { 306 // const RevGraphWrapper<Graph>* gw; 307 // friend class GraphWrapper<Graph>; 308 // public: 309 // InEdgeIt() { } 310 // InEdgeIt(Invalid i) : Edge(i) { } 311 // InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 312 // Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { } 313 // InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 314 // Edge(e), gw(&_gw) { } 315 // InEdgeIt& operator++() { 316 // *(static_cast<Edge*>(this))= 317 // ++(typename Graph::OutEdgeIt(*(gw>graph), *this)); 318 // return *this; 319 // } 320 // }; 321 322 // using GraphWrapper<Graph>::first; 323 // OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 324 // i=OutEdgeIt(*this, p); return i; 325 // } 326 // InEdgeIt& first(InEdgeIt& i, const Node& p) const { 327 // i=InEdgeIt(*this, p); return i; 328 // } 329 330 // Node source(const Edge& e) const { 331 // return GraphWrapper<Graph>::target(e); } 332 // Node target(const Edge& e) const { 333 // return GraphWrapper<Graph>::source(e); } 334 335 // // KEEP_MAPS(Parent, RevGraphWrapper); 336 337 // }; 302 338 303 339
Note: See TracChangeset
for help on using the changeset viewer.