COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/concepts/maps.h

    r51 r94  
    3030
    3131  namespace concepts {
    32  
     32
    3333    /// \addtogroup concept
    3434    /// @{
     
    4343    public:
    4444      /// The key type of the map.
    45       typedef K Key;   
    46       /// The value type of the map. (The type of objects associated with the keys).
    47       typedef T Value;
    48 
    49       /// Returns the value associated with a key.
    50 
    51       /// Returns the value associated with a key.
    52       /// \bug Value shouldn't need to be default constructible.
    53       ///
    54       Value operator[](const Key &) const {return Value();}
     45      typedef K Key;
     46      /// The value type of the map. (The type of objects associated with the keys).
     47      typedef T Value;
     48
     49      /// Returns the value associated with the given key.
     50      Value operator[](const Key &) const {
     51        return *static_cast<Value *>(0);
     52      }
    5553
    5654      template<typename _ReadMap>
    5755      struct Constraints {
    58 
    5956        void constraints() {
    6057          Value val = m[key];
    6158          val = m[key];
    62           typename _ReadMap::Value own_val = m[own_key];
    63           own_val = m[own_key];
    64 
    65           ignore_unused_variable_warning(val);
    66           ignore_unused_variable_warning(own_val);
    67           ignore_unused_variable_warning(key);
    68         }
    69         Key& key;
    70         typename _ReadMap::Key& own_key;
    71         _ReadMap& m;
    72       };
    73      
    74     };
    75 
    76 
    77     /// Writable map concept
    78    
    79     /// Writable map concept.
    80     ///
    81     template<typename K, typename T>
    82     class WriteMap
    83     {
    84     public:
    85       /// The key type of the map.
    86       typedef K Key;   
    87       /// The value type of the map. (The type of objects associated with the keys).
    88       typedef T Value;
    89 
    90       /// Sets the value associated with a key.
    91       void set(const Key &,const Value &) {}
    92 
    93       ///Default constructor
    94       WriteMap() {}
    95 
    96       template <typename _WriteMap>
    97       struct Constraints {
    98         void constraints() {
    99           // No constraints for constructor.
    100           m.set(key, val);
    101           m.set(own_key, own_val);
     59          typename _ReadMap::Value own_val = m[own_key];
     60          own_val = m[own_key];
     61
    10262          ignore_unused_variable_warning(key);
    10363          ignore_unused_variable_warning(val);
     
    10565          ignore_unused_variable_warning(own_val);
    10666        }
    107 
    108         Value& val;
    109         typename _WriteMap::Value own_val;
    110         Key& key;
    111         typename _WriteMap::Key& own_key;
     67        const Key& key;
     68        const typename _ReadMap::Key& own_key;
     69        const _ReadMap& m;
     70      };
     71
     72    };
     73
     74
     75    /// Writable map concept
     76
     77    /// Writable map concept.
     78    ///
     79    template<typename K, typename T>
     80    class WriteMap
     81    {
     82    public:
     83      /// The key type of the map.
     84      typedef K Key;
     85      /// The value type of the map. (The type of objects associated with the keys).
     86      typedef T Value;
     87
     88      /// Sets the value associated with the given key.
     89      void set(const Key &, const Value &) {}
     90
     91      /// Default constructor.
     92      WriteMap() {}
     93
     94      template <typename _WriteMap>
     95      struct Constraints {
     96        void constraints() {
     97          m.set(key, val);
     98          m.set(own_key, own_val);
     99
     100          ignore_unused_variable_warning(key);
     101          ignore_unused_variable_warning(val);
     102          ignore_unused_variable_warning(own_key);
     103          ignore_unused_variable_warning(own_val);
     104        }
     105        const Key& key;
     106        const Value& val;
     107        const typename _WriteMap::Key& own_key;
     108        const typename _WriteMap::Value own_val;
    112109        _WriteMap& m;
    113 
    114110      };
    115111    };
    116112
    117113    /// Read/writable map concept
    118    
     114
    119115    /// Read/writable map concept.
    120116    ///
     
    125121    public:
    126122      /// The key type of the map.
    127       typedef K Key;   
    128       /// The value type of the map. (The type of objects associated with the keys).
    129       typedef T Value;
    130 
    131       /// Returns the value associated with a key.
    132       Value operator[](const Key &) const {return Value();}
    133       /// Sets the value associated with a key.
    134       void set(const Key & ,const Value &) {}
     123      typedef K Key;
     124      /// The value type of the map. (The type of objects associated with the keys).
     125      typedef T Value;
     126
     127      /// Returns the value associated with the given key.
     128      Value operator[](const Key &) const {
     129        return *static_cast<Value *>(0);
     130      }
     131
     132      /// Sets the value associated with the given key.
     133      void set(const Key &, const Value &) {}
    135134
    136135      template<typename _ReadWriteMap>
     
    142141      };
    143142    };
    144  
    145  
     143
     144
    146145    /// Dereferable map concept
    147    
     146
    148147    /// Dereferable map concept.
    149148    ///
    150     /// \todo Rethink this concept.
    151149    template<typename K, typename T, typename R, typename CR>
    152150    class ReferenceMap : public ReadWriteMap<K,T>
     
    156154      typedef True ReferenceMapTag;
    157155      /// The key type of the map.
    158       typedef K Key;   
     156      typedef K Key;
    159157      /// The value type of the map. (The type of objects associated with the keys).
    160158      typedef T Value;
     
    164162      typedef CR ConstReference;
    165163
    166     protected:
    167       Value tmp;
    168     public:
    169 
    170       ///Returns a reference to the value associated with a key.
    171       Reference operator[](const Key &) { return tmp; }
    172       ///Returns a const reference to the value associated with a key.
    173       ConstReference operator[](const Key &) const { return tmp; }
    174       /// Sets the value associated with a key.
     164    public:
     165
     166      /// Returns a reference to the value associated with the given key.
     167      Reference operator[](const Key &) {
     168        return *static_cast<Value *>(0);
     169      }
     170
     171      /// Returns a const reference to the value associated with the given key.
     172      ConstReference operator[](const Key &) const {
     173        return *static_cast<Value *>(0);
     174      }
     175
     176      /// Sets the value associated with the given key.
    175177      void set(const Key &k,const Value &t) { operator[](k)=t; }
    176178
    177179      template<typename _ReferenceMap>
    178       struct ReferenceMapConcept {
    179 
    180         void constraints() {
    181           checkConcept<ReadWriteMap, _ReferenceMap >();
     180      struct Constraints {
     181        void constraints() {
     182          checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
     183          ref = m[key];
    182184          m[key] = val;
    183           val  = m[key];
    184185          m[key] = ref;
    185           ref = m[key];
     186          m[key] = cref;
     187          own_ref = m[own_key];
    186188          m[own_key] = own_val;
    187           own_val  = m[own_key];
    188189          m[own_key] = own_ref;
    189           own_ref = m[own_key];           
    190         }
    191 
    192         typename _ReferenceMap::Key& own_key;
     190          m[own_key] = own_cref;
     191          m[key] = m[own_key];
     192          m[own_key] = m[key];
     193        }
     194        const Key& key;
     195        Value& val;
     196        Reference ref;
     197        ConstReference cref;
     198        const typename _ReferenceMap::Key& own_key;
    193199        typename _ReferenceMap::Value& own_val;
    194         typename _ReferenceMap::Reference& own_ref;
    195         Key& key;
    196         Value& val;
    197         Reference& ref;
     200        typename _ReferenceMap::Reference own_ref;
     201        typename _ReferenceMap::ConstReference own_cref;
    198202        _ReferenceMap& m;
    199203      };
Note: See TracChangeset for help on using the changeset viewer.