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