Bit more elaborated map concepts
authorklao
Sat, 03 Apr 2004 18:21:25 +0000
changeset 2827f85e99502db
parent 281 3fefabfd00b7
child 283 91e78d9b78f4
Bit more elaborated map concepts
doc/makefile
src/include/skeletons/maps.h
     1.1 --- a/doc/makefile	Sat Apr 03 17:26:46 2004 +0000
     1.2 +++ b/doc/makefile	Sat Apr 03 18:21:25 2004 +0000
     1.3 @@ -6,4 +6,7 @@
     1.4  	makeinfo etikol.texi&&makeinfo --html etikol.texi&&texi2pdf etikol.texi
     1.5  
     1.6  texi-html: etikol.texi flf-graph.texi
     1.7 -	makeinfo etikol.texi&&makeinfo --html etikol.texi
     1.8 \ No newline at end of file
     1.9 +	makeinfo etikol.texi&&makeinfo --html etikol.texi
    1.10 +
    1.11 +clean:
    1.12 +	rm -rf html latex
     2.1 --- a/src/include/skeletons/maps.h	Sat Apr 03 17:26:46 2004 +0000
     2.2 +++ b/src/include/skeletons/maps.h	Sat Apr 03 18:21:25 2004 +0000
     2.3 @@ -6,79 +6,172 @@
     2.4  ///\brief Map concepts checking classes for testing and documenting.
     2.5  
     2.6  namespace hugo {
     2.7 +
     2.8 +  /// The namespace of HUGOlib concepts and concept checking classes
     2.9 +  namespace skeleton {
    2.10    
    2.11 -  ///Readable map skeleton
    2.12 -  template<typename K, typename T>
    2.13 -  class ReadMapSkeleton
    2.14 -  {
    2.15 -  public:
    2.16 -    /// Map value type.
    2.17 -    typedef T ValueType;
    2.18 -    /// Map key type.
    2.19 -    typedef K KeyType;
    2.20 +    /// Null map concept
    2.21 +    template<typename K, typename T>
    2.22 +    class NullMap
    2.23 +    {
    2.24 +    public:
    2.25 +      /// Map's key type.
    2.26 +      typedef K KeyType;    
    2.27 +      /// Map's value type. (The type of objects associated with the keys).
    2.28 +      typedef T ValueType;
    2.29  
    2.30 -    ///Default constructor.
    2.31 -    ReadMapSkeleton() {}
    2.32 +      /// Facility to define a map with an other value type
    2.33 +      template<typename T1>
    2.34 +      struct rebind {
    2.35 +	/// The type of a map with the given value type
    2.36 +	typedef NullMap<K,T1> other;
    2.37 +      };
    2.38 +
    2.39 +      NullMap() {}
    2.40 +    };
    2.41      
    2.42 -    ///Reads an element of the map.
    2.43 -    ValueType operator[](const KeyType &i) const {return ValueType();}
    2.44 -  };
    2.45 +    /// Readable map concept
    2.46 +    template<typename K, typename T>
    2.47 +    class ReadableMap : public NullMap<K,T>
    2.48 +    {
    2.49 +    public:
    2.50 +      /// Map's key type.
    2.51 +      typedef K KeyType;    
    2.52 +      /// Map's value type. (The type of objects associated with the keys).
    2.53 +      typedef T ValueType;
    2.54  
    2.55 +      /// Returns the value associated with a key.
    2.56 +      ValueType operator[](const KeyType &k) const {return ValueType();}
    2.57  
    2.58 -  ///Writeable map skeleton
    2.59 -  template<typename K, typename T>
    2.60 -  class WriteMapSkeleton 
    2.61 -  {
    2.62 -  public:
    2.63 -    /// Map value type.
    2.64 -    typedef T ValueType;
    2.65 -    /// Map key type.
    2.66 -    typedef K KeyType;
    2.67 +      /// Copy contsructor. (optional)
    2.68 +      ReadableMap(const ReadableMap&) {}
    2.69 +      /// Assignment operator. (optional)
    2.70 +      ReadableMap& operator=(const ReadableMap&) {return *this;}
    2.71  
    2.72 -    ///Default constructor.
    2.73 -    WriteMapSkeleton() {}
    2.74 -    ///'Fill with' constructor.
    2.75 -    WriteMapSkeleton(const ValueType &t) {}
    2.76 -    
    2.77 -    ///Write an element of a map.
    2.78 -    void set(const KeyType &i,const ValueType &t) {}
    2.79 -  };
    2.80 +      /// Facility to define a map with an other value type (optional)
    2.81 +      template<typename T1>
    2.82 +      struct rebind {
    2.83 +	/// The type of a map with the given value type
    2.84 +	typedef ReadableMap<K,T1> other;
    2.85 +      };
    2.86 +      /// @brief Constructor that copies all keys from the other map and
    2.87 +      /// assigns to them a default value (optional)
    2.88 +      template<typename T1>
    2.89 +      ReadableMap(const ReadableMap<K,T1> &map, const T1 &v) {}
    2.90  
    2.91 -  ///Read/Write map skeleton.
    2.92 -  template<typename K, typename T>
    2.93 -  class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>,
    2.94 -			       public WriteMapSkeleton<K,T>
    2.95 -  {
    2.96 -  public:
    2.97 -    ///Default constructor.
    2.98 -    ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {}
    2.99 -    ///'Fill with' constructor.
   2.100 -    ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {}
   2.101 -  };
   2.102 +      ReadableMap() {}
   2.103 +    };
   2.104 +
   2.105 +
   2.106 +    /// Writable map concept
   2.107 +    template<typename K, typename T>
   2.108 +    class WritableMap : public NullMap<K,T>
   2.109 +    {
   2.110 +    public:
   2.111 +      /// Map's key type.
   2.112 +      typedef K KeyType;    
   2.113 +      /// Map's value type. (The type of objects associated with the keys).
   2.114 +      typedef T ValueType;
   2.115 +
   2.116 +      /// Sets the value associated with a key.
   2.117 +      void set(const KeyType &k,const ValueType &t) {}
   2.118 +
   2.119 +      /// Copy contsructor. (optional)
   2.120 +      WritableMap(const WritableMap&) {}
   2.121 +      /// Assignment operator. (optional)
   2.122 +      WritableMap& operator=(const WritableMap&) {return *this;}
   2.123 +
   2.124 +      /// Facility to define a map with an other value type (optional)
   2.125 +      template<typename T1>
   2.126 +      struct rebind {
   2.127 +	/// The type of a map with the given value type
   2.128 +	typedef WritableMap<K,T1> other;
   2.129 +      };
   2.130 +      /// @brief Constructor that copies all keys from the other map and
   2.131 +      /// assigns to them a default value (optional)
   2.132 +      template<typename T1>
   2.133 +      WritableMap(const WritableMap<K,T1> &map, const T1 &v) {}
   2.134 +
   2.135 +      WritableMap() {}
   2.136 +    };
   2.137 +
   2.138 +    ///Read/Writeable map concept
   2.139 +    template<typename K, typename T>
   2.140 +    class ReadWritableMap : public ReadableMap<K,T>,
   2.141 +			    public WritableMap<K,T>
   2.142 +    {
   2.143 +    public:
   2.144 +      /// Map's key type.
   2.145 +      typedef K KeyType;    
   2.146 +      /// Map's value type. (The type of objects associated with the keys).
   2.147 +      typedef T ValueType;
   2.148 +
   2.149 +      /// Returns the value associated with a key.
   2.150 +      ValueType operator[](const KeyType &k) const {return ValueType();}
   2.151 +      /// Sets the value associated with a key.
   2.152 +      void set(const KeyType &k,const ValueType &t) {}
   2.153 +
   2.154 +      /// Copy contsructor. (optional)
   2.155 +      ReadWritableMap(const ReadWritableMap&) {}
   2.156 +      /// Assignment operator. (optional)
   2.157 +      ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
   2.158 +
   2.159 +      /// Facility to define a map with an other value type (optional)
   2.160 +      template<typename T1>
   2.161 +      struct rebind {
   2.162 +	/// The type of a map with the given value type
   2.163 +	typedef ReadWritableMap<K,T1> other;
   2.164 +      };
   2.165 +      /// @brief Constructor that copies all keys from the other map and
   2.166 +      /// assigns to them a default value (optional)
   2.167 +      template<typename T1>
   2.168 +      ReadWritableMap(const ReadWritableMap<K,T1> &map, const T1 &v) {}
   2.169 +
   2.170 +      ReadWritableMap() {}
   2.171 +    };
   2.172    
   2.173    
   2.174 -  ///Dereferable map skeleton
   2.175 -  template<typename K, typename T>
   2.176 -  class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T>
   2.177 -  {
   2.178 -  public:
   2.179 -    /// Map value type.
   2.180 -    typedef T ValueType;
   2.181 -    /// Map key type.
   2.182 -    typedef K KeyType;
   2.183 +    ///Dereferable map concept
   2.184 +    template<typename K, typename T>
   2.185 +    class DereferableMap : public ReadWritableMap<K,T>
   2.186 +    {
   2.187 +    public:
   2.188 +      /// Map's key type.
   2.189 +      typedef K KeyType;    
   2.190 +      /// Map's value type. (The type of objects associated with the keys).
   2.191 +      typedef T ValueType;
   2.192 +      /// Map's reference type. (Reference to an object associated with a key)
   2.193 +      typedef ValueType& ReferenceType;
   2.194 +      /// Map's const reference type.
   2.195 +      typedef const ValueType& ConstReferenceType;
   2.196  
   2.197 -    ///Default constructor.
   2.198 -    ReferenceMapSkeleton() : ReadWriteMapSkeleton() {}
   2.199 -    ///'Fill with' constructor.
   2.200 -    ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {}    
   2.201 +      ///Returns a reference to the value associated to a key.
   2.202 +      ReferenceType operator[](const KeyType &i);
   2.203 +      ///Returns a const reference to the value associated to a key.
   2.204 +      ConstReferenceType operator[](const KeyType &i) const;
   2.205 +      /// Sets the value associated with a key.
   2.206 +      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
   2.207  
   2.208 -    ///Give a reference to the value belonging to a key.
   2.209 -    ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} 
   2.210 -    ///Give a const reference to the value belonging to a key.
   2.211 -    const ValueType &operator[](const KeyType &i) const {return *(T*)0;}
   2.212 -  };
   2.213 +      /// Copy contsructor. (optional)
   2.214 +      DereferableMap(const DereferableMap&) {}
   2.215 +      /// Assignment operator. (optional)
   2.216 +      DereferableMap& operator=(const DereferableMap&) {return *this;}
   2.217  
   2.218 +      /// Facility to define a map with an other value type (optional)
   2.219 +      template<typename T1>
   2.220 +      struct rebind {
   2.221 +	/// The type of a map with the given value type
   2.222 +	typedef DereferableMap<K,T1> other;
   2.223 +      };
   2.224 +      /// @brief Constructor that copies all keys from the other map and
   2.225 +      /// assigns to them a default value (optional)
   2.226 +      template<typename T1>
   2.227 +      DereferableMap(const DereferableMap<K,T1> &map, const T1 &v) {}
   2.228  
   2.229 +      DereferableMap() {}
   2.230 +    };
   2.231  
   2.232 +
   2.233 +  }
   2.234  }
   2.235  #endif // HUGO_MAPSKELETON_H