src/include/skeletons/maps.h
author klao
Sat, 03 Apr 2004 18:21:25 +0000
changeset 282 7f85e99502db
parent 254 483ba4ffe90a
child 284 2d4684f76aac
permissions -rw-r--r--
Bit more elaborated map concepts
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
    /// Null map concept
klao@282
    14
    template<typename K, typename T>
klao@282
    15
    class NullMap
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
      /// Facility to define a map with an other value type
klao@282
    24
      template<typename T1>
klao@282
    25
      struct rebind {
klao@282
    26
	/// The type of a map with the given value type
klao@282
    27
	typedef NullMap<K,T1> other;
klao@282
    28
      };
klao@282
    29
klao@282
    30
      NullMap() {}
klao@282
    31
    };
alpar@186
    32
    
klao@282
    33
    /// Readable map concept
klao@282
    34
    template<typename K, typename T>
klao@282
    35
    class ReadableMap : public NullMap<K,T>
klao@282
    36
    {
klao@282
    37
    public:
klao@282
    38
      /// Map's key type.
klao@282
    39
      typedef K KeyType;    
klao@282
    40
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    41
      typedef T ValueType;
alpar@186
    42
klao@282
    43
      /// Returns the value associated with a key.
klao@282
    44
      ValueType operator[](const KeyType &k) const {return ValueType();}
alpar@186
    45
klao@282
    46
      /// Copy contsructor. (optional)
klao@282
    47
      ReadableMap(const ReadableMap&) {}
klao@282
    48
      /// Assignment operator. (optional)
klao@282
    49
      ReadableMap& operator=(const ReadableMap&) {return *this;}
alpar@186
    50
klao@282
    51
      /// Facility to define a map with an other value type (optional)
klao@282
    52
      template<typename T1>
klao@282
    53
      struct rebind {
klao@282
    54
	/// The type of a map with the given value type
klao@282
    55
	typedef ReadableMap<K,T1> other;
klao@282
    56
      };
klao@282
    57
      /// @brief Constructor that copies all keys from the other map and
klao@282
    58
      /// assigns to them a default value (optional)
klao@282
    59
      template<typename T1>
klao@282
    60
      ReadableMap(const ReadableMap<K,T1> &map, const T1 &v) {}
alpar@186
    61
klao@282
    62
      ReadableMap() {}
klao@282
    63
    };
klao@282
    64
klao@282
    65
klao@282
    66
    /// Writable map concept
klao@282
    67
    template<typename K, typename T>
klao@282
    68
    class WritableMap : public NullMap<K,T>
klao@282
    69
    {
klao@282
    70
    public:
klao@282
    71
      /// Map's key type.
klao@282
    72
      typedef K KeyType;    
klao@282
    73
      /// Map's value type. (The type of objects associated with the keys).
klao@282
    74
      typedef T ValueType;
klao@282
    75
klao@282
    76
      /// Sets the value associated with a key.
klao@282
    77
      void set(const KeyType &k,const ValueType &t) {}
klao@282
    78
klao@282
    79
      /// Copy contsructor. (optional)
klao@282
    80
      WritableMap(const WritableMap&) {}
klao@282
    81
      /// Assignment operator. (optional)
klao@282
    82
      WritableMap& operator=(const WritableMap&) {return *this;}
klao@282
    83
klao@282
    84
      /// Facility to define a map with an other value type (optional)
klao@282
    85
      template<typename T1>
klao@282
    86
      struct rebind {
klao@282
    87
	/// The type of a map with the given value type
klao@282
    88
	typedef WritableMap<K,T1> other;
klao@282
    89
      };
klao@282
    90
      /// @brief Constructor that copies all keys from the other map and
klao@282
    91
      /// assigns to them a default value (optional)
klao@282
    92
      template<typename T1>
klao@282
    93
      WritableMap(const WritableMap<K,T1> &map, const T1 &v) {}
klao@282
    94
klao@282
    95
      WritableMap() {}
klao@282
    96
    };
klao@282
    97
klao@282
    98
    ///Read/Writeable map concept
klao@282
    99
    template<typename K, typename T>
klao@282
   100
    class ReadWritableMap : public ReadableMap<K,T>,
klao@282
   101
			    public WritableMap<K,T>
klao@282
   102
    {
klao@282
   103
    public:
klao@282
   104
      /// Map's key type.
klao@282
   105
      typedef K KeyType;    
klao@282
   106
      /// Map's value type. (The type of objects associated with the keys).
klao@282
   107
      typedef T ValueType;
klao@282
   108
klao@282
   109
      /// Returns the value associated with a key.
klao@282
   110
      ValueType operator[](const KeyType &k) const {return ValueType();}
klao@282
   111
      /// Sets the value associated with a key.
klao@282
   112
      void set(const KeyType &k,const ValueType &t) {}
klao@282
   113
klao@282
   114
      /// Copy contsructor. (optional)
klao@282
   115
      ReadWritableMap(const ReadWritableMap&) {}
klao@282
   116
      /// Assignment operator. (optional)
klao@282
   117
      ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
klao@282
   118
klao@282
   119
      /// Facility to define a map with an other value type (optional)
klao@282
   120
      template<typename T1>
klao@282
   121
      struct rebind {
klao@282
   122
	/// The type of a map with the given value type
klao@282
   123
	typedef ReadWritableMap<K,T1> other;
klao@282
   124
      };
klao@282
   125
      /// @brief Constructor that copies all keys from the other map and
klao@282
   126
      /// assigns to them a default value (optional)
klao@282
   127
      template<typename T1>
klao@282
   128
      ReadWritableMap(const ReadWritableMap<K,T1> &map, const T1 &v) {}
klao@282
   129
klao@282
   130
      ReadWritableMap() {}
klao@282
   131
    };
alpar@186
   132
  
alpar@186
   133
  
klao@282
   134
    ///Dereferable map concept
klao@282
   135
    template<typename K, typename T>
klao@282
   136
    class DereferableMap : public ReadWritableMap<K,T>
klao@282
   137
    {
klao@282
   138
    public:
klao@282
   139
      /// Map's key type.
klao@282
   140
      typedef K KeyType;    
klao@282
   141
      /// Map's value type. (The type of objects associated with the keys).
klao@282
   142
      typedef T ValueType;
klao@282
   143
      /// Map's reference type. (Reference to an object associated with a key)
klao@282
   144
      typedef ValueType& ReferenceType;
klao@282
   145
      /// Map's const reference type.
klao@282
   146
      typedef const ValueType& ConstReferenceType;
alpar@186
   147
klao@282
   148
      ///Returns a reference to the value associated to a key.
klao@282
   149
      ReferenceType operator[](const KeyType &i);
klao@282
   150
      ///Returns a const reference to the value associated to a key.
klao@282
   151
      ConstReferenceType operator[](const KeyType &i) const;
klao@282
   152
      /// Sets the value associated with a key.
klao@282
   153
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
   154
klao@282
   155
      /// Copy contsructor. (optional)
klao@282
   156
      DereferableMap(const DereferableMap&) {}
klao@282
   157
      /// Assignment operator. (optional)
klao@282
   158
      DereferableMap& operator=(const DereferableMap&) {return *this;}
alpar@186
   159
klao@282
   160
      /// Facility to define a map with an other value type (optional)
klao@282
   161
      template<typename T1>
klao@282
   162
      struct rebind {
klao@282
   163
	/// The type of a map with the given value type
klao@282
   164
	typedef DereferableMap<K,T1> other;
klao@282
   165
      };
klao@282
   166
      /// @brief Constructor that copies all keys from the other map and
klao@282
   167
      /// assigns to them a default value (optional)
klao@282
   168
      template<typename T1>
klao@282
   169
      DereferableMap(const DereferableMap<K,T1> &map, const T1 &v) {}
alpar@186
   170
klao@282
   171
      DereferableMap() {}
klao@282
   172
    };
alpar@186
   173
klao@282
   174
klao@282
   175
  }
alpar@186
   176
}
alpar@186
   177
#endif // HUGO_MAPSKELETON_H