COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/concepts/maps.h

    r51 r79  
    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
     51      /// Returns the value associated with the given key.
     52      /// \bug Value shouldn't need to be default constructible.
     53      Value operator[](const Key &) const { return Value(); }
    5554
    5655      template<typename _ReadMap>
    5756      struct Constraints {
    58 
    5957        void constraints() {
    6058          Value val = m[key];
    6159          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);
     60          typename _ReadMap::Value own_val = m[own_key];
     61          own_val = m[own_key];
     62
    10263          ignore_unused_variable_warning(key);
    10364          ignore_unused_variable_warning(val);
     
    10566          ignore_unused_variable_warning(own_val);
    10667        }
    107 
    108         Value& val;
    109         typename _WriteMap::Value own_val;
    110         Key& key;
    111         typename _WriteMap::Key& own_key;
     68        const Key& key;
     69        const typename _ReadMap::Key& own_key;
     70        const _ReadMap& m;
     71      };
     72
     73    };
     74
     75
     76    /// Writable map concept
     77
     78    /// Writable map concept.
     79    ///
     80    template<typename K, typename T>
     81    class WriteMap
     82    {
     83    public:
     84      /// The key type of the map.
     85      typedef K Key;
     86      /// The value type of the map. (The type of objects associated with the keys).
     87      typedef T Value;
     88
     89      /// Sets the value associated with the given key.
     90      void set(const Key &, const Value &) {}
     91
     92      /// Default constructor.
     93      WriteMap() {}
     94
     95      template <typename _WriteMap>
     96      struct Constraints {
     97        void constraints() {
     98          m.set(key, val);
     99          m.set(own_key, own_val);
     100
     101          ignore_unused_variable_warning(key);
     102          ignore_unused_variable_warning(val);
     103          ignore_unused_variable_warning(own_key);
     104          ignore_unused_variable_warning(own_val);
     105        }
     106        const Key& key;
     107        const Value& val;
     108        const typename _WriteMap::Key& own_key;
     109        const typename _WriteMap::Value own_val;
    112110        _WriteMap& m;
    113 
    114111      };
    115112    };
    116113
    117114    /// Read/writable map concept
    118    
     115
    119116    /// Read/writable map concept.
    120117    ///
     
    125122    public:
    126123      /// 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 &) {}
     124      typedef K Key;
     125      /// The value type of the map. (The type of objects associated with the keys).
     126      typedef T Value;
     127
     128      /// Returns the value associated with the given key.
     129      Value operator[](const Key &) const { return Value(); }
     130
     131      /// Sets the value associated with the given key.
     132      void set(const Key &, const Value &) {}
    135133
    136134      template<typename _ReadWriteMap>
     
    142140      };
    143141    };
    144  
    145  
     142
     143
    146144    /// Dereferable map concept
    147    
     145
    148146    /// Dereferable map concept.
    149147    ///
    150     /// \todo Rethink this concept.
    151148    template<typename K, typename T, typename R, typename CR>
    152149    class ReferenceMap : public ReadWriteMap<K,T>
     
    156153      typedef True ReferenceMapTag;
    157154      /// The key type of the map.
    158       typedef K Key;   
     155      typedef K Key;
    159156      /// The value type of the map. (The type of objects associated with the keys).
    160157      typedef T Value;
     
    168165    public:
    169166
    170       ///Returns a reference to the value associated with a key.
     167      /// Returns a reference to the value associated with the given key.
    171168      Reference operator[](const Key &) { return tmp; }
    172       ///Returns a const reference to the value associated with a key.
     169
     170      /// Returns a const reference to the value associated with the given key.
    173171      ConstReference operator[](const Key &) const { return tmp; }
    174       /// Sets the value associated with a key.
     172
     173      /// Sets the value associated with the given key.
    175174      void set(const Key &k,const Value &t) { operator[](k)=t; }
    176175
    177176      template<typename _ReferenceMap>
    178       struct ReferenceMapConcept {
    179 
    180         void constraints() {
    181           checkConcept<ReadWriteMap, _ReferenceMap >();
     177      struct Constraints {
     178        void constraints() {
     179          checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
     180          ref = m[key];
    182181          m[key] = val;
    183           val  = m[key];
    184182          m[key] = ref;
    185           ref = m[key];
     183          m[key] = cref;
     184          own_ref = m[own_key];
    186185          m[own_key] = own_val;
    187           own_val  = m[own_key];
    188186          m[own_key] = own_ref;
    189           own_ref = m[own_key];           
    190         }
    191 
    192         typename _ReferenceMap::Key& own_key;
     187          m[own_key] = own_cref;
     188          m[key] = m[own_key];
     189          m[own_key] = m[key];
     190        }
     191        const Key& key;
     192        Value& val;
     193        Reference ref;
     194        ConstReference cref;
     195        const typename _ReferenceMap::Key& own_key;
    193196        typename _ReferenceMap::Value& own_val;
    194         typename _ReferenceMap::Reference& own_ref;
    195         Key& key;
    196         Value& val;
    197         Reference& ref;
     197        typename _ReferenceMap::Reference own_ref;
     198        typename _ReferenceMap::ConstReference own_cref;
    198199        _ReferenceMap& m;
    199200      };
Note: See TracChangeset for help on using the changeset viewer.