src/hugo/skeletons/maps.h
author deba
Tue, 07 Sep 2004 15:17:15 +0000
changeset 817 3e30caeb9c00
parent 794 d9ec436d11fe
child 881 a9f19f38970b
permissions -rw-r--r--
Some warining fix in maps.
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
  /// The namespace of HUGOlib concepts and concept checking classes
klao@282
    12
  namespace skeleton {
alpar@186
    13
  
alpar@794
    14
    /// \addtogroup skeletons
alpar@794
    15
    /// @{
alpar@794
    16
klao@282
    17
    /// Readable map concept
klao@282
    18
    template<typename K, typename T>
alpar@732
    19
    class ReadMap
klao@282
    20
    {
klao@282
    21
    public:
klao@282
    22
      /// Map's key type.
klao@282
    23
      typedef K KeyType;    
klao@282
    24
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    25
      typedef T ValueType;
alpar@186
    26
klao@282
    27
      /// Returns the value associated with a key.
klao@282
    28
      ValueType operator[](const KeyType &k) const {return ValueType();}
alpar@186
    29
alpar@732
    30
      ///Default constructor
alpar@732
    31
      ReadMap() {}
klao@282
    32
    };
klao@282
    33
klao@282
    34
klao@282
    35
    /// Writable map concept
klao@282
    36
    template<typename K, typename T>
alpar@732
    37
    class WriteMap
klao@282
    38
    {
klao@282
    39
    public:
klao@282
    40
      /// Map's key type.
klao@282
    41
      typedef K KeyType;    
klao@282
    42
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    43
      typedef T ValueType;
klao@282
    44
klao@282
    45
      /// Sets the value associated with a key.
klao@282
    46
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    47
alpar@732
    48
      ///Default constructor
alpar@732
    49
      WriteMap() {}
klao@282
    50
    };
klao@282
    51
alpar@809
    52
    ///Read/Writable map concept
klao@282
    53
    template<typename K, typename T>
alpar@732
    54
    class ReadWriteMap : public ReadMap<K,T>,
alpar@732
    55
			    public WriteMap<K,T>
klao@282
    56
    {
klao@282
    57
    public:
klao@282
    58
      /// Map's key type.
klao@282
    59
      typedef K KeyType;    
klao@282
    60
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    61
      typedef T ValueType;
klao@282
    62
klao@282
    63
      /// Returns the value associated with a key.
klao@282
    64
      ValueType operator[](const KeyType &k) const {return ValueType();}
klao@282
    65
      /// Sets the value associated with a key.
klao@282
    66
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    67
alpar@732
    68
      ///Default constructor
alpar@732
    69
      ReadWriteMap() {}
klao@282
    70
    };
alpar@186
    71
  
alpar@186
    72
  
klao@282
    73
    ///Dereferable map concept
klao@282
    74
    template<typename K, typename T>
alpar@732
    75
    class ReferenceMap : public ReadWriteMap<K,T>
klao@282
    76
    {
klao@282
    77
    public:
klao@282
    78
      /// Map's key type.
klao@282
    79
      typedef K KeyType;    
klao@282
    80
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    81
      typedef T ValueType;
alpar@732
    82
alpar@732
    83
    protected:
alpar@732
    84
      ValueType tmp;
alpar@732
    85
    public:
klao@282
    86
      typedef ValueType& ReferenceType;
klao@282
    87
      /// Map's const reference type.
klao@282
    88
      typedef const ValueType& ConstReferenceType;
alpar@186
    89
klao@282
    90
      ///Returns a reference to the value associated to a key.
alpar@732
    91
      ReferenceType operator[](const KeyType &i) { return tmp; }
klao@282
    92
      ///Returns a const reference to the value associated to a key.
alpar@732
    93
      ConstReferenceType operator[](const KeyType &i) const
alpar@732
    94
      { return tmp; }
klao@282
    95
      /// Sets the value associated with a key.
klao@282
    96
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
    97
alpar@732
    98
      ///Default constructor
alpar@732
    99
      ReferenceMap() {}
klao@282
   100
    };
alpar@794
   101
alpar@794
   102
    // @}
alpar@794
   103
alpar@732
   104
  } //namespace skeleton
alpar@732
   105
} //namespace hugo
alpar@186
   106
#endif // HUGO_MAPSKELETON_H