deba@1810: /* -*- C++ -*- deba@1810: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@1956: * Copyright (C) 2003-2006 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1956: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@1810: * deba@1810: * Permission to use, modify and distribute this software is granted deba@1810: * provided that this copyright notice appears in all copies. For deba@1810: * precise terms see the accompanying LICENSE file. deba@1810: * deba@1810: * This software is provided "AS IS" with no warranty of any kind, deba@1810: * express or implied, and with no claim as to its suitability for any deba@1810: * purpose. deba@1810: * deba@1810: */ deba@1810: deba@1810: #ifndef LEMON_BITS_MAP_EXTENDER_H deba@1810: #define LEMON_BITS_MAP_EXTENDER_H deba@1810: deba@1810: #include deba@1810: deba@1993: #include deba@1810: deba@1810: ///\file deba@1810: ///\brief Extenders for iterable maps. deba@1810: deba@1810: namespace lemon { deba@1810: deba@1996: /// \ingroup graphbits deba@1999: /// deba@1999: /// \brief Extender for maps deba@1810: template deba@1999: class MapExtender : public _Map { deba@1810: public: deba@1810: deba@1810: typedef _Map Parent; deba@1999: typedef MapExtender Map; deba@1810: deba@1810: alpar@1854: typedef typename Parent::Graph Graph; alpar@1854: typedef typename Parent::Key Item; deba@1810: alpar@1854: typedef typename Parent::Key Key; alpar@1854: typedef typename Parent::Value Value; deba@1810: deba@1810: class MapIt; deba@1810: class ConstMapIt; deba@1810: deba@1810: friend class MapIt; deba@1810: friend class ConstMapIt; deba@1810: deba@1810: public: deba@1810: deba@1999: MapExtender(const Graph& graph) deba@1999: : Parent(graph) {} deba@1810: deba@1999: MapExtender(const Graph& graph, const Value& value) deba@1810: : Parent(graph, value) {} deba@1810: deba@1810: deba@1999: class MapIt : public Item { deba@1810: public: deba@1810: deba@1999: typedef Item Parent; deba@1810: typedef typename Map::Value Value; deba@1810: deba@1999: MapIt() {} deba@1999: deba@1999: MapIt(Invalid i) : Parent(i) { } deba@1999: deba@1999: explicit MapIt(Map& _map) : map(_map) { deba@1999: map.getNotifier()->first(*this); deba@1999: } deba@1999: deba@1999: MapIt(const Map& _map, const Item& item) deba@1999: : Parent(item), map(_map) {} deba@1999: deba@1999: MapIt& operator++() { deba@1999: map.getNotifier()->next(*this); deba@1999: return *this; deba@1999: } deba@1810: deba@1810: typename MapTraits::ConstReturnValue operator*() const { deba@1810: return map[*this]; deba@1810: } deba@1810: deba@1810: typename MapTraits::ReturnValue operator*() { deba@1810: return map[*this]; deba@1810: } deba@1810: deba@1810: void set(const Value& value) { deba@1810: map.set(*this, value); deba@1810: } deba@1810: deba@1810: protected: deba@1810: Map& map; deba@1810: deba@1810: }; deba@1810: deba@1999: class ConstMapIt : public Item { deba@1810: public: deba@1810: deba@1999: typedef Item Parent; deba@1810: deba@1810: typedef typename Map::Value Value; deba@1999: deba@1999: ConstMapIt() {} deba@1810: deba@1999: ConstMapIt(Invalid i) : Parent(i) { } deba@1999: deba@1999: explicit ConstMapIt(Map& _map) : map(_map) { deba@1999: map.getNotifier()->first(*this); deba@1999: } deba@1999: deba@1999: ConstMapIt(const Map& _map, const Item& item) deba@1999: : Parent(item), map(_map) {} deba@1999: deba@1999: ConstMapIt& operator++() { deba@1999: map.getNotifier()->next(*this); deba@1999: return *this; deba@1999: } deba@1810: deba@1810: typename MapTraits::ConstReturnValue operator*() const { deba@1810: return map[*this]; deba@1810: } deba@1999: deba@1810: protected: deba@1810: const Map& map; deba@1810: }; deba@1810: deba@1999: class ItemIt : Item { deba@1810: public: deba@1810: deba@1999: typedef Item Parent; deba@1999: deba@1999: ItemIt() {} deba@1810: deba@1999: ItemIt(Invalid i) : Parent(i) { } deba@1999: deba@1999: explicit ItemIt(Map& _map) : map(_map) { deba@1999: map->getNotifier()->first(*this); deba@1999: } deba@1999: deba@1999: ItemIt(const Map& _map, const Item& item) deba@1999: : Parent(item), map(_map) {} deba@1999: deba@1999: ItemIt& operator++() { deba@1999: map.getNotifier()->next(*this); deba@1999: return *this; deba@1999: } deba@1999: deba@1999: protected: deba@1999: const Map& map; deba@1810: deba@1810: }; deba@1810: }; deba@1810: deba@1810: } deba@1810: deba@1810: #endif