lemon/bits/map_extender.h
author deba
Wed, 25 Jan 2006 16:44:19 +0000
changeset 1906 7fa90b66ca9e
parent 1854 a68d4f93b1fb
child 1910 f95eea8c34b0
permissions -rw-r--r--
Omitting warnings
     1 /* -*- C++ -*-
     2  * lemon/map_extender.h - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 #ifndef LEMON_BITS_MAP_EXTENDER_H
    18 #define LEMON_BITS_MAP_EXTENDER_H
    19 
    20 #include <iterator>
    21 
    22 #include <lemon/traits.h>
    23 
    24 ///\file
    25 ///\brief Extenders for iterable maps.
    26 
    27 namespace lemon {
    28 
    29   template <typename _Map>
    30   class IterableMapExtender : public _Map {
    31   public:
    32 
    33     typedef _Map Parent;
    34     typedef IterableMapExtender Map;
    35 
    36 
    37     typedef typename Parent::Graph Graph;
    38     typedef typename Parent::Key Item;
    39 
    40     typedef typename Parent::Key Key;
    41     typedef typename Parent::Value Value;
    42 
    43     class MapIt;
    44     class ConstMapIt;
    45 
    46     friend class MapIt;
    47     friend class ConstMapIt;
    48 
    49   protected:
    50 
    51     using Parent::getGraph;
    52 
    53   public:
    54 
    55     IterableMapExtender(const Graph& graph) : Parent(graph) {}
    56 
    57     IterableMapExtender(const Graph& graph, const Value& value) 
    58       : Parent(graph, value) {}
    59 
    60 
    61     class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
    62     public:
    63       
    64       typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
    65 
    66       typedef typename Map::Value Value;
    67       
    68       MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {}
    69       
    70       typename MapTraits<Map>::ConstReturnValue operator*() const {
    71 	return map[*this];
    72       }
    73 
    74       typename MapTraits<Map>::ReturnValue operator*() {
    75 	return map[*this];
    76       }
    77       
    78       void set(const Value& value) {
    79 	map.set(*this, value);
    80       }
    81       
    82     protected:
    83       Map& map;
    84       
    85     };
    86 
    87     class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt {
    88     public:
    89 
    90       typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
    91 
    92       typedef typename Map::Value Value;
    93 
    94       ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {}
    95 
    96       typename MapTraits<Map>::ConstReturnValue operator*() const {
    97 	return map[*this];
    98       }
    99     protected:
   100       const Map& map;
   101     };
   102 
   103     class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt {
   104     public:
   105       
   106       typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent;
   107 
   108       ItemIt(Map& _map) : Parent(*_map.getGraph()) {}
   109       
   110     };
   111   };
   112 
   113 }
   114 
   115 #endif