map_extender.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  *
00003  * This file is a part of LEMON, a generic C++ optimization library
00004  *
00005  * Copyright (C) 2003-2006
00006  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00007  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00008  *
00009  * Permission to use, modify and distribute this software is granted
00010  * provided that this copyright notice appears in all copies. For
00011  * precise terms see the accompanying LICENSE file.
00012  *
00013  * This software is provided "AS IS" with no warranty of any kind,
00014  * express or implied, and with no claim as to its suitability for any
00015  * purpose.
00016  *
00017  */
00018 
00019 #ifndef LEMON_BITS_MAP_EXTENDER_H
00020 #define LEMON_BITS_MAP_EXTENDER_H
00021 
00022 #include <iterator>
00023 
00024 #include <lemon/traits.h>
00025 
00028 
00029 namespace lemon {
00030 
00031   template <typename _Map>
00032   class IterableMapExtender : public _Map {
00033   public:
00034 
00035     typedef _Map Parent;
00036     typedef IterableMapExtender Map;
00037 
00038 
00039     typedef typename Parent::Graph Graph;
00040     typedef typename Parent::Key Item;
00041 
00042     typedef typename Parent::Key Key;
00043     typedef typename Parent::Value Value;
00044 
00045     class MapIt;
00046     class ConstMapIt;
00047 
00048     friend class MapIt;
00049     friend class ConstMapIt;
00050 
00051   protected:
00052 
00053     using Parent::getGraph;
00054 
00055   public:
00056 
00057     IterableMapExtender(const Graph& graph) : Parent(graph) {}
00058 
00059     IterableMapExtender(const Graph& graph, const Value& value) 
00060       : Parent(graph, value) {}
00061 
00062 
00063     class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
00064     public:
00065       
00066       typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
00067 
00068       typedef typename Map::Value Value;
00069       
00070       MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {}
00071       
00072       typename MapTraits<Map>::ConstReturnValue operator*() const {
00073         return map[*this];
00074       }
00075 
00076       typename MapTraits<Map>::ReturnValue operator*() {
00077         return map[*this];
00078       }
00079       
00080       void set(const Value& value) {
00081         map.set(*this, value);
00082       }
00083       
00084     protected:
00085       Map& map;
00086       
00087     };
00088 
00089     class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt {
00090     public:
00091 
00092       typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
00093 
00094       typedef typename Map::Value Value;
00095 
00096       ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {}
00097 
00098       typename MapTraits<Map>::ConstReturnValue operator*() const {
00099         return map[*this];
00100       }
00101     protected:
00102       const Map& map;
00103     };
00104 
00105     class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt {
00106     public:
00107       
00108       typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
00109 
00110       ItemIt(Map& _map) : Parent(*_map.getGraph()) {}
00111       
00112     };
00113   };
00114 
00115 }
00116 
00117 #endif

Generated on Fri Feb 3 18:35:50 2006 for LEMON by  doxygen 1.4.6