lemon/vmap.h
author alpar
Tue, 18 Jul 2006 15:14:56 +0000
changeset 2152 ba87d27667cd
child 2260 4274224f8a7d
permissions -rw-r--r--
Bugfix
alpar@1978
     1
/* -*- C++ -*-
alpar@1978
     2
 *
alpar@1978
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1978
     4
 *
alpar@1978
     5
 * Copyright (C) 2003-2006
alpar@1978
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1978
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1978
     8
 *
alpar@1978
     9
 * Permission to use, modify and distribute this software is granted
alpar@1978
    10
 * provided that this copyright notice appears in all copies. For
alpar@1978
    11
 * precise terms see the accompanying LICENSE file.
alpar@1978
    12
 *
alpar@1978
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1978
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1978
    15
 * purpose.
alpar@1978
    16
 *
alpar@1978
    17
 */
alpar@1978
    18
alpar@1978
    19
#ifndef LEMON_LIST_GRAPH_H
alpar@1978
    20
#define LEMON_LIST_GRAPH_H
alpar@1978
    21
alpar@1978
    22
///\ingroup graphs
alpar@1978
    23
///\file
alpar@1978
    24
///\brief Virtual map support.
alpar@1978
    25
alpar@1978
    26
namespace lemon {
alpar@1978
    27
alpar@1978
    28
  ///Base class of the virtual maps.
alpar@1978
    29
  template<class K, class V>
alpar@1978
    30
  class VMapBase 
alpar@1978
    31
  {
alpar@1978
    32
  public:
alpar@1978
    33
    ///\e
alpar@1978
    34
    typedef K Key;
alpar@1978
    35
    ///\e
alpar@1978
    36
    typedef V Value;
alpar@1978
    37
    
alpar@1978
    38
    ///\e
alpar@1978
    39
    virtual Value operator[](const Key &) const { return Value();}
alpar@1978
    40
    ///\e
alpar@1978
    41
    virtual void set(const Key &,const Value &) {}
alpar@1978
    42
  };
alpar@1978
    43
  
alpar@1978
    44
  ///Base class of the virtual reference maps.
alpar@1978
    45
  template<class K, class V>
alpar@1978
    46
  class VRefMapBase 
alpar@1978
    47
  {
alpar@1978
    48
  public:
alpar@1978
    49
    ///\e
alpar@1978
    50
    typedef K Key;
alpar@1978
    51
    ///\e
alpar@1978
    52
    typedef V Value;
alpar@1978
    53
    
alpar@1978
    54
    ///\e
alpar@1978
    55
    virtual Value& operator[](Key &) = 0;
alpar@1978
    56
    ///\e
alpar@1978
    57
    virtual Value& operator[](const Key &) const = 0;
alpar@1978
    58
    ///\e
alpar@1978
    59
    virtual void set(const Key &,const Value &) = 0;
alpar@1978
    60
  };
alpar@1978
    61
  
alpar@1978
    62
  ///Makes a virtual map from a \ref concept::ReadMap "ReadMap"
alpar@1978
    63
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
    64
  class VReadMap : public VMapBase<K,V> 
alpar@1978
    65
  {
alpar@1978
    66
    const M &map;
alpar@1978
    67
  public:
alpar@1978
    68
  ///\e
alpar@1978
    69
    VReadMap(const M &m) : map(m) {}
alpar@1978
    70
    virtual Value operator[](const Key &k) const { return map[k];}
alpar@1978
    71
  };
alpar@1978
    72
alpar@1978
    73
  ///Function interface for \ref VReadMap.
alpar@1978
    74
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
    75
  vReadMap(const M& m) {return VReadMap<M,K,V>(m);}
alpar@1978
    76
alpar@1978
    77
  ///Makes a virtual map from a \ref concept::WriteMap "WriteMap"
alpar@1978
    78
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
    79
  class VWriteMap :public VMapBase<K,V> 
alpar@1978
    80
  {
alpar@1978
    81
    M &map;
alpar@1978
    82
  public:
alpar@1978
    83
    ///\e
alpar@1978
    84
    VWriteMap(M &m) : map(m) {}
alpar@1978
    85
    virtual void set(const Key &k,const Value &v) { map.set(k,v);}
alpar@1978
    86
  };
alpar@1978
    87
alpar@1978
    88
  ///Function interface for \ref VWriteMap.
alpar@1978
    89
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
    90
  vWriteMap(const M& m) {return VReadMap<M,K,V>(m);}
alpar@1978
    91
alpar@1978
    92
  ///Makes a virtual map from a \ref concept::ReadWriteMap "ReadWriteMap"
alpar@1978
    93
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
    94
  class VReadWriteMap :public VMapBase<K,V>
alpar@1978
    95
  {
alpar@1978
    96
    M &map;
alpar@1978
    97
  public:
alpar@1978
    98
    ///\e
alpar@1978
    99
    VReadWriteMap(M &m) : map(m) {}
alpar@1978
   100
    virtual Value operator[](const Key &k) const { return map[k];}
alpar@1978
   101
    virtual void set(const Key &k,const Value &v) { map.set(k,v);}
alpar@1978
   102
  };
alpar@1978
   103
    
alpar@1978
   104
  ///Function interface for \ref VReadWriteMap.
alpar@1978
   105
  template<class M, class K=typename M::Key,class V=typename M::Value>
alpar@1978
   106
  vReadWriteMap(const M& m) {return VReadMap<M,K,V>(m);}
alpar@1978
   107
  
alpar@1978
   108
  /// @}  
alpar@1978
   109
} //namespace lemon
alpar@1978
   110
  
alpar@1978
   111
alpar@1978
   112
#endif