src/hugo/skeletons/maps.h
author alpar
Wed, 22 Sep 2004 07:32:57 +0000
changeset 896 3a98a1aa5a8f
parent 809 ea5ae5266285
child 906 17f31d280385
permissions -rw-r--r--
- mincostflows.h renamed to min_cost_flows.h
- minlengthpaths.h renamed to min_length_paths.h
- src/test/old_path_test.cc removed
alpar@186
     1
// -*- c++ -*-
alpar@186
     2
#ifndef HUGO_MAPSKELETON_H
alpar@186
     3
#define HUGO_MAPSKELETON_H
alpar@186
     4
alpar@794
     5
///\ingroup skeletons
alpar@242
     6
///\file
alpar@242
     7
///\brief Map concepts checking classes for testing and documenting.
alpar@242
     8
alpar@186
     9
namespace hugo {
klao@282
    10
klao@282
    11
  namespace skeleton {
alpar@186
    12
  
alpar@794
    13
    /// \addtogroup skeletons
alpar@794
    14
    /// @{
alpar@794
    15
klao@282
    16
    /// Readable map concept
klao@282
    17
    template<typename K, typename T>
alpar@732
    18
    class ReadMap
klao@282
    19
    {
klao@282
    20
    public:
klao@282
    21
      /// Map's key type.
klao@282
    22
      typedef K KeyType;    
klao@282
    23
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    24
      typedef T ValueType;
alpar@186
    25
klao@282
    26
      /// Returns the value associated with a key.
klao@282
    27
      ValueType operator[](const KeyType &k) const {return ValueType();}
alpar@186
    28
alpar@732
    29
      ///Default constructor
alpar@732
    30
      ReadMap() {}
klao@282
    31
    };
klao@282
    32
klao@282
    33
klao@282
    34
    /// Writable map concept
klao@282
    35
    template<typename K, typename T>
alpar@732
    36
    class WriteMap
klao@282
    37
    {
klao@282
    38
    public:
klao@282
    39
      /// Map's key type.
klao@282
    40
      typedef K KeyType;    
klao@282
    41
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    42
      typedef T ValueType;
klao@282
    43
klao@282
    44
      /// Sets the value associated with a key.
klao@282
    45
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    46
alpar@732
    47
      ///Default constructor
alpar@732
    48
      WriteMap() {}
klao@282
    49
    };
klao@282
    50
alpar@809
    51
    ///Read/Writable map concept
klao@282
    52
    template<typename K, typename T>
alpar@732
    53
    class ReadWriteMap : public ReadMap<K,T>,
alpar@732
    54
			    public WriteMap<K,T>
klao@282
    55
    {
klao@282
    56
    public:
klao@282
    57
      /// Map's key type.
klao@282
    58
      typedef K KeyType;    
klao@282
    59
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    60
      typedef T ValueType;
klao@282
    61
klao@282
    62
      /// Returns the value associated with a key.
klao@282
    63
      ValueType operator[](const KeyType &k) const {return ValueType();}
klao@282
    64
      /// Sets the value associated with a key.
klao@282
    65
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    66
alpar@732
    67
      ///Default constructor
alpar@732
    68
      ReadWriteMap() {}
klao@282
    69
    };
alpar@186
    70
  
alpar@186
    71
  
klao@282
    72
    ///Dereferable map concept
klao@282
    73
    template<typename K, typename T>
alpar@732
    74
    class ReferenceMap : public ReadWriteMap<K,T>
klao@282
    75
    {
klao@282
    76
    public:
klao@282
    77
      /// Map's key type.
klao@282
    78
      typedef K KeyType;    
klao@282
    79
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    80
      typedef T ValueType;
alpar@732
    81
alpar@732
    82
    protected:
alpar@732
    83
      ValueType tmp;
alpar@732
    84
    public:
klao@282
    85
      typedef ValueType& ReferenceType;
klao@282
    86
      /// Map's const reference type.
klao@282
    87
      typedef const ValueType& ConstReferenceType;
alpar@186
    88
klao@282
    89
      ///Returns a reference to the value associated to a key.
alpar@732
    90
      ReferenceType operator[](const KeyType &i) { return tmp; }
klao@282
    91
      ///Returns a const reference to the value associated to a key.
alpar@732
    92
      ConstReferenceType operator[](const KeyType &i) const
alpar@732
    93
      { return tmp; }
klao@282
    94
      /// Sets the value associated with a key.
klao@282
    95
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
    96
alpar@732
    97
      ///Default constructor
alpar@732
    98
      ReferenceMap() {}
klao@282
    99
    };
alpar@794
   100
alpar@794
   101
    // @}
alpar@794
   102
alpar@732
   103
  } //namespace skeleton
alpar@732
   104
} //namespace hugo
alpar@186
   105
#endif // HUGO_MAPSKELETON_H