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