src/lemon/skeletons/maps.h
author marci
Wed, 29 Sep 2004 19:02:26 +0000
changeset 923 acbef5dd0e65
parent 906 17f31d280385
child 946 c94ef40a22ce
permissions -rw-r--r--
more docs
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/skeletons/maps.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@921
    17
#ifndef LEMON_MAPSKELETON_H
alpar@921
    18
#define LEMON_MAPSKELETON_H
alpar@186
    19
alpar@794
    20
///\ingroup skeletons
alpar@242
    21
///\file
alpar@242
    22
///\brief Map concepts checking classes for testing and documenting.
alpar@242
    23
alpar@921
    24
namespace lemon {
klao@282
    25
klao@282
    26
  namespace skeleton {
alpar@186
    27
  
alpar@794
    28
    /// \addtogroup skeletons
alpar@794
    29
    /// @{
alpar@794
    30
klao@282
    31
    /// Readable map concept
klao@282
    32
    template<typename K, typename T>
alpar@732
    33
    class ReadMap
klao@282
    34
    {
klao@282
    35
    public:
klao@282
    36
      /// Map's key type.
klao@282
    37
      typedef K KeyType;    
klao@282
    38
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    39
      typedef T ValueType;
alpar@186
    40
klao@282
    41
      /// Returns the value associated with a key.
klao@282
    42
      ValueType operator[](const KeyType &k) const {return ValueType();}
alpar@186
    43
alpar@732
    44
      ///Default constructor
alpar@732
    45
      ReadMap() {}
klao@282
    46
    };
klao@282
    47
klao@282
    48
klao@282
    49
    /// Writable map concept
klao@282
    50
    template<typename K, typename T>
alpar@732
    51
    class WriteMap
klao@282
    52
    {
klao@282
    53
    public:
klao@282
    54
      /// Map's key type.
klao@282
    55
      typedef K KeyType;    
klao@282
    56
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    57
      typedef T ValueType;
klao@282
    58
klao@282
    59
      /// Sets the value associated with a key.
klao@282
    60
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    61
alpar@732
    62
      ///Default constructor
alpar@732
    63
      WriteMap() {}
klao@282
    64
    };
klao@282
    65
alpar@809
    66
    ///Read/Writable map concept
klao@282
    67
    template<typename K, typename T>
alpar@732
    68
    class ReadWriteMap : public ReadMap<K,T>,
alpar@732
    69
			    public WriteMap<K,T>
klao@282
    70
    {
klao@282
    71
    public:
klao@282
    72
      /// Map's key type.
klao@282
    73
      typedef K KeyType;    
klao@282
    74
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    75
      typedef T ValueType;
klao@282
    76
klao@282
    77
      /// Returns the value associated with a key.
klao@282
    78
      ValueType operator[](const KeyType &k) const {return ValueType();}
klao@282
    79
      /// Sets the value associated with a key.
klao@282
    80
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    81
alpar@732
    82
      ///Default constructor
alpar@732
    83
      ReadWriteMap() {}
klao@282
    84
    };
alpar@186
    85
  
alpar@186
    86
  
klao@282
    87
    ///Dereferable map concept
klao@282
    88
    template<typename K, typename T>
alpar@732
    89
    class ReferenceMap : public ReadWriteMap<K,T>
klao@282
    90
    {
klao@282
    91
    public:
klao@282
    92
      /// Map's key type.
klao@282
    93
      typedef K KeyType;    
klao@282
    94
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    95
      typedef T ValueType;
alpar@732
    96
alpar@732
    97
    protected:
alpar@732
    98
      ValueType tmp;
alpar@732
    99
    public:
klao@282
   100
      typedef ValueType& ReferenceType;
klao@282
   101
      /// Map's const reference type.
klao@282
   102
      typedef const ValueType& ConstReferenceType;
alpar@186
   103
klao@282
   104
      ///Returns a reference to the value associated to a key.
alpar@732
   105
      ReferenceType operator[](const KeyType &i) { return tmp; }
klao@282
   106
      ///Returns a const reference to the value associated to a key.
alpar@732
   107
      ConstReferenceType operator[](const KeyType &i) const
alpar@732
   108
      { return tmp; }
klao@282
   109
      /// Sets the value associated with a key.
klao@282
   110
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
   111
alpar@732
   112
      ///Default constructor
alpar@732
   113
      ReferenceMap() {}
klao@282
   114
    };
alpar@794
   115
alpar@794
   116
    // @}
alpar@794
   117
alpar@732
   118
  } //namespace skeleton
alpar@921
   119
} //namespace lemon
alpar@921
   120
#endif // LEMON_MAPSKELETON_H