src/include/skeletons/maps.h
author marci
Thu, 29 Apr 2004 16:59:00 +0000
changeset 482 dce64ce044d6
parent 284 2d4684f76aac
permissions -rw-r--r--
corrections for leda matching files
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>
klao@284
    15
    class ReadableMap
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
klao@282
    26
      /// Copy contsructor. (optional)
klao@282
    27
      ReadableMap(const ReadableMap&) {}
klao@282
    28
      /// Assignment operator. (optional)
klao@282
    29
      ReadableMap& operator=(const ReadableMap&) {return *this;}
alpar@186
    30
klao@282
    31
      ReadableMap() {}
klao@282
    32
    };
klao@282
    33
klao@282
    34
klao@282
    35
    /// Writable map concept
klao@282
    36
    template<typename K, typename T>
klao@284
    37
    class WritableMap
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
klao@282
    48
      WritableMap() {}
klao@282
    49
    };
klao@282
    50
klao@282
    51
    ///Read/Writeable map concept
klao@282
    52
    template<typename K, typename T>
klao@282
    53
    class ReadWritableMap : public ReadableMap<K,T>,
klao@282
    54
			    public WritableMap<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
klao@282
    67
      /// Copy contsructor. (optional)
klao@282
    68
      ReadWritableMap(const ReadWritableMap&) {}
klao@282
    69
      /// Assignment operator. (optional)
klao@282
    70
      ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
klao@282
    71
klao@282
    72
      /// Facility to define a map with an other value type (optional)
klao@282
    73
      template<typename T1>
klao@282
    74
      struct rebind {
klao@282
    75
	/// The type of a map with the given value type
klao@282
    76
	typedef ReadWritableMap<K,T1> other;
klao@282
    77
      };
klao@282
    78
      /// @brief Constructor that copies all keys from the other map and
klao@282
    79
      /// assigns to them a default value (optional)
klao@282
    80
      template<typename T1>
klao@286
    81
      ReadWritableMap(const ReadWritableMap<K,T1> &map, const ValueType &v) {}
klao@282
    82
klao@282
    83
      ReadWritableMap() {}
klao@282
    84
    };
alpar@186
    85
  
alpar@186
    86
  
klao@282
    87
    ///Dereferable map concept
klao@282
    88
    template<typename K, typename T>
klao@282
    89
    class DereferableMap : public ReadWritableMap<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;
klao@282
    96
      /// Map's reference type. (Reference to an object associated with a key)
klao@282
    97
      typedef ValueType& ReferenceType;
klao@282
    98
      /// Map's const reference type.
klao@282
    99
      typedef const ValueType& ConstReferenceType;
alpar@186
   100
klao@282
   101
      ///Returns a reference to the value associated to a key.
klao@282
   102
      ReferenceType operator[](const KeyType &i);
klao@282
   103
      ///Returns a const reference to the value associated to a key.
klao@282
   104
      ConstReferenceType operator[](const KeyType &i) const;
klao@282
   105
      /// Sets the value associated with a key.
klao@282
   106
      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
alpar@186
   107
klao@282
   108
      /// Copy contsructor. (optional)
klao@282
   109
      DereferableMap(const DereferableMap&) {}
klao@282
   110
      /// Assignment operator. (optional)
klao@282
   111
      DereferableMap& operator=(const DereferableMap&) {return *this;}
alpar@186
   112
klao@282
   113
      /// Facility to define a map with an other value type (optional)
klao@282
   114
      template<typename T1>
klao@282
   115
      struct rebind {
klao@282
   116
	/// The type of a map with the given value type
klao@282
   117
	typedef DereferableMap<K,T1> other;
klao@282
   118
      };
klao@282
   119
      /// @brief Constructor that copies all keys from the other map and
klao@282
   120
      /// assigns to them a default value (optional)
klao@282
   121
      template<typename T1>
klao@286
   122
      DereferableMap(const DereferableMap<K,T1> &map, const ValueType &v) {}
alpar@186
   123
klao@282
   124
      DereferableMap() {}
klao@282
   125
    };
alpar@186
   126
klao@282
   127
klao@282
   128
  }
alpar@186
   129
}
alpar@186
   130
#endif // HUGO_MAPSKELETON_H