src/hugo/skeletons/maps.h
author alpar
Wed, 04 Aug 2004 18:51:51 +0000
changeset 751 e742d383fffc
parent 539 fb261e3a9a0f
child 794 d9ec436d11fe
permissions -rw-r--r--
- Trimmed in order to work with gcc-3.4
- The number of executions of the tests can be controlled by command arg.
alpar@186
     1
// -*- c++ -*-
alpar@186
     2
#ifndef HUGO_MAPSKELETON_H
alpar@186
     3
#define HUGO_MAPSKELETON_H
alpar@186
     4
alpar@242
     5
///\file
alpar@242
     6
///\brief Map concepts checking classes for testing and documenting.
alpar@242
     7
alpar@186
     8
namespace hugo {
klao@282
     9
klao@282
    10
  /// The namespace of HUGOlib concepts and concept checking classes
klao@282
    11
  namespace skeleton {
alpar@186
    12
  
klao@282
    13
    /// Readable map concept
klao@282
    14
    template<typename K, typename T>
alpar@732
    15
    class ReadMap
klao@282
    16
    {
klao@282
    17
    public:
klao@282
    18
      /// Map's key type.
klao@282
    19
      typedef K KeyType;    
klao@282
    20
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    21
      typedef T ValueType;
alpar@186
    22
klao@282
    23
      /// Returns the value associated with a key.
klao@282
    24
      ValueType operator[](const KeyType &k) const {return ValueType();}
alpar@186
    25
alpar@732
    26
      ///Default constructor
alpar@732
    27
      ReadMap() {}
klao@282
    28
    };
klao@282
    29
klao@282
    30
klao@282
    31
    /// Writable map concept
klao@282
    32
    template<typename K, typename T>
alpar@732
    33
    class WriteMap
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;
klao@282
    40
klao@282
    41
      /// Sets the value associated with a key.
klao@282
    42
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    43
alpar@732
    44
      ///Default constructor
alpar@732
    45
      WriteMap() {}
klao@282
    46
    };
klao@282
    47
klao@282
    48
    ///Read/Writeable map concept
klao@282
    49
    template<typename K, typename T>
alpar@732
    50
    class ReadWriteMap : public ReadMap<K,T>,
alpar@732
    51
			    public WriteMap<K,T>
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
      /// Returns the value associated with a key.
klao@282
    60
      ValueType operator[](const KeyType &k) const {return ValueType();}
klao@282
    61
      /// Sets the value associated with a key.
klao@282
    62
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    63
alpar@732
    64
      ///Default constructor
alpar@732
    65
      ReadWriteMap() {}
klao@282
    66
    };
alpar@186
    67
  
alpar@186
    68
  
klao@282
    69
    ///Dereferable map concept
klao@282
    70
    template<typename K, typename T>
alpar@732
    71
    class ReferenceMap : public ReadWriteMap<K,T>
klao@282
    72
    {
klao@282
    73
    public:
klao@282
    74
      /// Map's key type.
klao@282
    75
      typedef K KeyType;    
klao@282
    76
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    77
      typedef T ValueType;
alpar@732
    78
alpar@732
    79
    protected:
alpar@732
    80
      ValueType tmp;
alpar@732
    81
    public:
klao@282
    82
      typedef ValueType& ReferenceType;
klao@282
    83
      /// Map's const reference type.
klao@282
    84
      typedef const ValueType& ConstReferenceType;
alpar@186
    85
klao@282
    86
      ///Returns a reference to the value associated to a key.
alpar@732
    87
      ReferenceType operator[](const KeyType &i) { return tmp; }
klao@282
    88
      ///Returns a const reference to the value associated to a key.
alpar@732
    89
      ConstReferenceType operator[](const KeyType &i) const
alpar@732
    90
      { return tmp; }
klao@282
    91
      /// Sets the value associated with a key.
klao@282
    92
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
    93
alpar@732
    94
      ///Default constructor
alpar@732
    95
      ReferenceMap() {}
klao@282
    96
    };
alpar@732
    97
  } //namespace skeleton
alpar@732
    98
} //namespace hugo
alpar@186
    99
#endif // HUGO_MAPSKELETON_H