src/work/alpar/mapskeleton.h
author marci
Sat, 20 Mar 2004 11:19:00 +0000
changeset 212 c07e4dd32438
parent 186 47cd1716870e
child 242 b255f25ad394
permissions -rw-r--r--
.
alpar@186
     1
// -*- c++ -*-
alpar@186
     2
#ifndef HUGO_MAPSKELETON_H
alpar@186
     3
#define HUGO_MAPSKELETON_H
alpar@186
     4
alpar@186
     5
namespace hugo {
alpar@186
     6
  
alpar@186
     7
  ///Readable map skeleton
alpar@186
     8
  template<typename K, typename T>
alpar@186
     9
  class ReadMapSkeleton
alpar@186
    10
  {
alpar@186
    11
  public:
alpar@186
    12
    /// Map value type.
alpar@186
    13
    typedef T ValueType;
alpar@186
    14
    /// Map key type.
alpar@186
    15
    typedef K KeyType;
alpar@186
    16
alpar@186
    17
    ///Default constructor.
alpar@186
    18
    ReadMapSkeleton() {}
alpar@186
    19
    
alpar@186
    20
    ///Reads an element of the map.
alpar@209
    21
    ValueType operator[](const KeyType &i) const {return ValueType();}
alpar@186
    22
  };
alpar@186
    23
alpar@186
    24
alpar@186
    25
  ///Writeable map skeleton
alpar@186
    26
  template<typename K, typename T>
alpar@186
    27
  class WriteMapSkeleton 
alpar@186
    28
  {
alpar@186
    29
  public:
alpar@186
    30
    /// Map value type.
alpar@186
    31
    typedef T ValueType;
alpar@186
    32
    /// Map key type.
alpar@186
    33
    typedef K KeyType;
alpar@186
    34
alpar@186
    35
    ///Default constructor.
alpar@186
    36
    WriteMapSkeleton() {}
alpar@186
    37
    ///'Fill with' constructor.
alpar@186
    38
    WriteMapSkeleton(const ValueType &t) {}
alpar@186
    39
    
alpar@186
    40
    ///Write an element of a map.
alpar@186
    41
    void set(const KeyType &i,const ValueType &t) {}
alpar@186
    42
  };
alpar@186
    43
alpar@186
    44
  ///Read/Write map skeleton.
alpar@186
    45
  template<typename K, typename T>
alpar@186
    46
  class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>,
alpar@186
    47
			       public WriteMapSkeleton<K,T>
alpar@186
    48
  {
alpar@186
    49
  public:
alpar@186
    50
    ///Default constructor.
alpar@186
    51
    ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {}
alpar@186
    52
    ///'Fill with' constructor.
alpar@186
    53
    ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {}
alpar@186
    54
  };
alpar@186
    55
  
alpar@186
    56
  
alpar@186
    57
  ///Dereferable map skeleton
alpar@186
    58
  template<typename K, typename T>
alpar@186
    59
  class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T>
alpar@186
    60
  {
alpar@186
    61
  public:
alpar@186
    62
    /// Map value type.
alpar@186
    63
    typedef T ValueType;
alpar@186
    64
    /// Map key type.
alpar@186
    65
    typedef K KeyType;
alpar@186
    66
alpar@186
    67
    ///Default constructor.
alpar@186
    68
    ReferenceMapSkeleton() : ReadWriteMapSkeleton() {}
alpar@186
    69
    ///'Fill with' constructor.
alpar@186
    70
    ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {}    
alpar@186
    71
alpar@186
    72
    ///Give a reference to the value belonging to a key.
alpar@209
    73
    ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} 
alpar@209
    74
    ///Give a const reference to the value belonging to a key.
alpar@209
    75
    const ValueType &operator[](const KeyType &i) const {return *(T*)0;}
alpar@186
    76
  };
alpar@186
    77
alpar@186
    78
alpar@186
    79
alpar@186
    80
}
alpar@186
    81
#endif // HUGO_MAPSKELETON_H