src/hugo/skeletons/maps.h
changeset 732 33cbc0635e92
parent 539 fb261e3a9a0f
child 794 d9ec436d11fe
equal deleted inserted replaced
0:fd49b1776ef3 1:568e40caeb59
    10   /// The namespace of HUGOlib concepts and concept checking classes
    10   /// The namespace of HUGOlib concepts and concept checking classes
    11   namespace skeleton {
    11   namespace skeleton {
    12   
    12   
    13     /// Readable map concept
    13     /// Readable map concept
    14     template<typename K, typename T>
    14     template<typename K, typename T>
    15     class ReadableMap
    15     class ReadMap
    16     {
    16     {
    17     public:
    17     public:
    18       /// Map's key type.
    18       /// Map's key type.
    19       typedef K KeyType;    
    19       typedef K KeyType;    
    20       /// Map's value type. (The type of objects associated with the keys).
    20       /// Map's value type. (The type of objects associated with the keys).
    21       typedef T ValueType;
    21       typedef T ValueType;
    22 
    22 
    23       /// Returns the value associated with a key.
    23       /// Returns the value associated with a key.
    24       ValueType operator[](const KeyType &k) const {return ValueType();}
    24       ValueType operator[](const KeyType &k) const {return ValueType();}
    25 
    25 
    26       /// Copy contsructor. (optional)
    26       ///Default constructor
    27       ReadableMap(const ReadableMap&) {}
    27       ReadMap() {}
    28       /// Assignment operator. (optional)
       
    29       ReadableMap& operator=(const ReadableMap&) {return *this;}
       
    30 
       
    31       ReadableMap() {}
       
    32     };
    28     };
    33 
    29 
    34 
    30 
    35     /// Writable map concept
    31     /// Writable map concept
    36     template<typename K, typename T>
    32     template<typename K, typename T>
    37     class WritableMap
    33     class WriteMap
    38     {
    34     {
    39     public:
    35     public:
    40       /// Map's key type.
    36       /// Map's key type.
    41       typedef K KeyType;    
    37       typedef K KeyType;    
    42       /// Map's value type. (The type of objects associated with the keys).
    38       /// Map's value type. (The type of objects associated with the keys).
    43       typedef T ValueType;
    39       typedef T ValueType;
    44 
    40 
    45       /// Sets the value associated with a key.
    41       /// Sets the value associated with a key.
    46       void set(const KeyType &k,const ValueType &t) {}
    42       void set(const KeyType &k,const ValueType &t) {}
    47 
    43 
    48       WritableMap() {}
    44       ///Default constructor
       
    45       WriteMap() {}
    49     };
    46     };
    50 
    47 
    51     ///Read/Writeable map concept
    48     ///Read/Writeable map concept
    52     template<typename K, typename T>
    49     template<typename K, typename T>
    53     class ReadWritableMap : public ReadableMap<K,T>,
    50     class ReadWriteMap : public ReadMap<K,T>,
    54 			    public WritableMap<K,T>
    51 			    public WriteMap<K,T>
    55     {
    52     {
    56     public:
    53     public:
    57       /// Map's key type.
    54       /// Map's key type.
    58       typedef K KeyType;    
    55       typedef K KeyType;    
    59       /// Map's value type. (The type of objects associated with the keys).
    56       /// Map's value type. (The type of objects associated with the keys).
    62       /// Returns the value associated with a key.
    59       /// Returns the value associated with a key.
    63       ValueType operator[](const KeyType &k) const {return ValueType();}
    60       ValueType operator[](const KeyType &k) const {return ValueType();}
    64       /// Sets the value associated with a key.
    61       /// Sets the value associated with a key.
    65       void set(const KeyType &k,const ValueType &t) {}
    62       void set(const KeyType &k,const ValueType &t) {}
    66 
    63 
    67       /// Copy contsructor. (optional)
    64       ///Default constructor
    68       ReadWritableMap(const ReadWritableMap&) {}
    65       ReadWriteMap() {}
    69       /// Assignment operator. (optional)
       
    70       ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
       
    71 
       
    72       /// Facility to define a map with an other value type (optional)
       
    73       template<typename T1>
       
    74       struct rebind {
       
    75 	/// The type of a map with the given value type
       
    76 	typedef ReadWritableMap<K,T1> other;
       
    77       };
       
    78       /// @brief Constructor that copies all keys from the other map and
       
    79       /// assigns to them a default value (optional)
       
    80       template<typename T1>
       
    81       ReadWritableMap(const ReadWritableMap<K,T1> &map, const ValueType &v) {}
       
    82 
       
    83       ReadWritableMap() {}
       
    84     };
    66     };
    85   
    67   
    86   
    68   
    87     ///Dereferable map concept
    69     ///Dereferable map concept
    88     template<typename K, typename T>
    70     template<typename K, typename T>
    89     class DereferableMap : public ReadWritableMap<K,T>
    71     class ReferenceMap : public ReadWriteMap<K,T>
    90     {
    72     {
    91     public:
    73     public:
    92       /// Map's key type.
    74       /// Map's key type.
    93       typedef K KeyType;    
    75       typedef K KeyType;    
    94       /// Map's value type. (The type of objects associated with the keys).
    76       /// Map's value type. (The type of objects associated with the keys).
    95       typedef T ValueType;
    77       typedef T ValueType;
    96       /// Map's reference type. (Reference to an object associated with a key)
    78 
       
    79     protected:
       
    80       ValueType tmp;
       
    81     public:
    97       typedef ValueType& ReferenceType;
    82       typedef ValueType& ReferenceType;
    98       /// Map's const reference type.
    83       /// Map's const reference type.
    99       typedef const ValueType& ConstReferenceType;
    84       typedef const ValueType& ConstReferenceType;
   100 
    85 
   101       ///Returns a reference to the value associated to a key.
    86       ///Returns a reference to the value associated to a key.
   102       ReferenceType operator[](const KeyType &i);
    87       ReferenceType operator[](const KeyType &i) { return tmp; }
   103       ///Returns a const reference to the value associated to a key.
    88       ///Returns a const reference to the value associated to a key.
   104       ConstReferenceType operator[](const KeyType &i) const;
    89       ConstReferenceType operator[](const KeyType &i) const
       
    90       { return tmp; }
   105       /// Sets the value associated with a key.
    91       /// Sets the value associated with a key.
   106       void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
    92       void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
   107 
    93 
   108       /// Copy contsructor. (optional)
    94       ///Default constructor
   109       DereferableMap(const DereferableMap&) {}
    95       ReferenceMap() {}
   110       /// Assignment operator. (optional)
       
   111       DereferableMap& operator=(const DereferableMap&) {return *this;}
       
   112 
       
   113       /// Facility to define a map with an other value type (optional)
       
   114       template<typename T1>
       
   115       struct rebind {
       
   116 	/// The type of a map with the given value type
       
   117 	typedef DereferableMap<K,T1> other;
       
   118       };
       
   119       /// @brief Constructor that copies all keys from the other map and
       
   120       /// assigns to them a default value (optional)
       
   121       template<typename T1>
       
   122       DereferableMap(const DereferableMap<K,T1> &map, const ValueType &v) {}
       
   123 
       
   124       DereferableMap() {}
       
   125     };
    96     };
   126 
    97   } //namespace skeleton
   127 
    98 } //namespace hugo
   128   }
       
   129 }
       
   130 #endif // HUGO_MAPSKELETON_H
    99 #endif // HUGO_MAPSKELETON_H