lemon/concepts/maps.h
changeset 28 e337bdf46777
parent 25 751cd8f9bb1c
child 35 f8ddf1b1541a
equal deleted inserted replaced
0:bc805819687a 1:cc4592f0a275
    32   
    32   
    33     /// \addtogroup concept
    33     /// \addtogroup concept
    34     /// @{
    34     /// @{
    35 
    35 
    36     /// Readable map concept
    36     /// Readable map concept
       
    37 
       
    38     /// Readable map concept.
       
    39     ///
    37     template<typename K, typename T>
    40     template<typename K, typename T>
    38     class ReadMap
    41     class ReadMap
    39     {
    42     {
    40     public:
    43     public:
    41       /// Map's key type.
    44       /// Map's key type.
    43       /// Map's value type. (The type of objects associated with the keys).
    46       /// Map's value type. (The type of objects associated with the keys).
    44       typedef T Value;
    47       typedef T Value;
    45 
    48 
    46       /// Returns the value associated with a key.
    49       /// Returns the value associated with a key.
    47 
    50 
    48       /// \bug Value should n't need to be default constructible.
    51       /// \bug Value shouldn't need to be default constructible.
    49       ///
    52       ///
    50       Value operator[](const Key &) const {return Value();}
    53       Value operator[](const Key &) const {return Value();}
    51 
    54 
    52       template<typename _ReadMap>
    55       template<typename _ReadMap>
    53       struct Constraints {
    56       struct Constraints {
    69       
    72       
    70     };
    73     };
    71 
    74 
    72 
    75 
    73     /// Writable map concept
    76     /// Writable map concept
       
    77     
       
    78     /// Writable map concept.
       
    79     ///
    74     template<typename K, typename T>
    80     template<typename K, typename T>
    75     class WriteMap
    81     class WriteMap
    76     {
    82     {
    77     public:
    83     public:
    78       /// Map's key type.
    84       /// Map's key type.
   105 	_WriteMap& m;
   111 	_WriteMap& m;
   106 
   112 
   107       };
   113       };
   108     };
   114     };
   109 
   115 
   110     ///Read/Writable map concept
   116     /// Read/Writable map concept
       
   117     
       
   118     /// Read/writable map concept.
       
   119     ///
   111     template<typename K, typename T>
   120     template<typename K, typename T>
   112     class ReadWriteMap : public ReadMap<K,T>,
   121     class ReadWriteMap : public ReadMap<K,T>,
   113 			    public WriteMap<K,T>
   122 			    public WriteMap<K,T>
   114     {
   123     {
   115     public:
   124     public:
   131 	}
   140 	}
   132       };
   141       };
   133     };
   142     };
   134   
   143   
   135   
   144   
   136     ///Dereferable map concept
   145     /// Dereferable map concept
       
   146     
       
   147     /// Dereferable map concept.
       
   148     ///
   137     template<typename K, typename T, typename R, typename CR>
   149     template<typename K, typename T, typename R, typename CR>
   138     class ReferenceMap : public ReadWriteMap<K,T>
   150     class ReferenceMap : public ReadWriteMap<K,T>
   139     {
   151     {
   140     public:
   152     public:
   141       /// Tag for reference maps.
   153       /// Tag for reference maps.
   154     public:
   166     public:
   155 
   167 
   156       ///Returns a reference to the value associated to a key.
   168       ///Returns a reference to the value associated to a key.
   157       Reference operator[](const Key &) { return tmp; }
   169       Reference operator[](const Key &) { return tmp; }
   158       ///Returns a const reference to the value associated to a key.
   170       ///Returns a const reference to the value associated to a key.
   159       ConstReference operator[](const Key &) const
   171       ConstReference operator[](const Key &) const { return tmp; }
   160       { return tmp; }
       
   161       /// Sets the value associated with a key.
   172       /// Sets the value associated with a key.
   162       void set(const Key &k,const Value &t) { operator[](k)=t; }
   173       void set(const Key &k,const Value &t) { operator[](k)=t; }
   163 
   174 
   164       // \todo rethink this concept
   175       /// \todo Rethink this concept. 
   165       template<typename _ReferenceMap>
   176       template<typename _ReferenceMap>
   166       struct ReferenceMapConcept {
   177       struct ReferenceMapConcept {
   167 
   178 
   168 	void constraints() {
   179 	void constraints() {
   169 	  checkConcept<ReadWriteMap, _ReferenceMap >();
   180 	  checkConcept<ReadWriteMap, _ReferenceMap >();
   188     };
   199     };
   189 
   200 
   190     // @}
   201     // @}
   191 
   202 
   192   } //namespace concepts
   203   } //namespace concepts
       
   204 
   193 } //namespace lemon
   205 } //namespace lemon
       
   206 
   194 #endif // LEMON_CONCEPT_MAPS_H
   207 #endif // LEMON_CONCEPT_MAPS_H