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