map_iterator.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_MAP_ITERATOR_H
00020 #define LEMON_MAP_ITERATOR_H
00021 
00022 #include <lemon/traits.h>
00023 #include <lemon/utility.h>
00024 
00028 
00029 namespace lemon {
00030 
00036   template <typename Graph, typename Item, typename Map>
00037   class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
00038   public:
00039       
00040     typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
00041     
00042     typedef typename Map::Value Value;
00043     
00048     MapIt(const Graph& _graph, Map& _map) : Parent(_graph), map(_map) {}
00049 
00053     typename MapTraits<Map>::ConstReturnValue operator*() const {
00054       return map[*this];
00055     }
00056 
00060     typename MapTraits<Map>::ReturnValue operator*() {
00061       return map[*this];
00062     }
00063     
00067     void set(const Value& value) {
00068       map.set(*this, value);
00069     }
00070     
00071   protected:
00072     Map& map;
00073       
00074   };
00075 
00081   template <typename Graph, typename Item, typename Map>
00082   class ConstMapIt : public ItemSetTraits<Graph, Item>::ItemIt {
00083   public:
00084     
00085     typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
00086 
00087     typedef typename Map::Value Value;
00088     
00093     ConstMapIt(const Graph& _graph, const Map& _map) 
00094       : Parent(_graph), map(_map) {}
00095     
00099     typename MapTraits<Map>::ConstReturnValue operator*() const {
00100       return map[*this];
00101     }
00102     
00103   protected:
00104     const Map& map;
00105   };
00106 
00107 
00114   template <typename Graph, typename Item, typename Map>
00115   class FilterMapIt 
00116     : public ItemSetTraits<Graph, Item>::ItemIt {
00117   public:
00118     
00119     typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
00120 
00121     typedef typename Map::Value Value;
00122     
00128     FilterMapIt(const Graph& _graph, const Map& _map, const Value& _value) 
00129       : Parent(_graph), map(_map), value(_value) {}
00130     
00134     FilterMapIt& operator++() {
00135       Parent::operator++();
00136       while (*this != INVALID && map[*this] != value) Parent::operator++();
00137     }
00138     
00139   protected:
00140     const Map& map;
00141     Value value;
00142   };
00143 
00144   
00145 }
00146 
00147 #endif

Generated on Fri Feb 3 18:38:43 2006 for LEMON by  doxygen 1.4.6