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