COIN-OR::LEMON - Graph Library

Changeset 1999:2ff283124dfc in lemon-0.x for lemon/matrix_maps.h


Ignore:
Timestamp:
03/06/06 11:28:37 (18 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2609
Message:

Clarifing alteration observing system
It is directly connected now to a container

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/matrix_maps.h

    r1993 r1999  
    210210  template <typename _Graph, typename _Item, typename _Value>
    211211  class DynamicMatrixMap
    212     : protected AlterationNotifier<_Item>::ObserverBase {
    213   public:
    214     typedef typename AlterationNotifier<_Item>::ObserverBase Parent;
     212    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
     213  public:
     214    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
     215    Parent;
    215216
    216217    typedef _Graph Graph;
     
    236237    /// Creates an item matrix for the given graph.
    237238    DynamicMatrixMap(const Graph& _graph)
    238       : graph(_graph), values(size(_graph.maxId(Key()) + 1)) {
    239       Parent::attach(graph.getNotifier(Key()));
     239      : values(size(_graph.maxId(Key()) + 1)) {
     240      Parent::attach(_graph.getNotifier(Key()));
    240241    }
    241242
     
    245246    /// pairs of keys the given parameter.
    246247    DynamicMatrixMap(const Graph& _graph, const Value& _val)
    247       : graph(_graph), values(size(_graph.maxId(Key()) + 1), _val) {
    248       Parent::attach(graph.getNotifier(Key()));
    249     }
    250 
    251     ~DynamicMatrixMap() {
    252       if (Parent::attached()) {
    253         Parent::detach();
    254       }
     248      : values(size(_graph.maxId(Key()) + 1), _val) {
     249      Parent::attach(_graph.getNotifier(Key()));
    255250    }
    256251
     
    260255    /// Gives back the value assigned to the \c first - \c second ordered pair.
    261256    ConstReference operator()(const Key& first, const Key& second) const {
    262       return values[index(graph.id(first), graph.id(second))];
     257      return values[index(Parent::getNotifier()->id(first),
     258                          Parent::getNotifier()->id(second))];
    263259    }
    264260   
     
    268264    /// Gives back the value assigned to the \c first - \c second ordered pair.
    269265    Reference operator()(const Key& first, const Key& second) {
    270       return values[index(graph.id(first), graph.id(second))];
     266      return values[index(Parent::getNotifier()->id(first),
     267                          Parent::getNotifier()->id(second))];
    271268    }
    272269
     
    275272    /// Setter function for the matrix map.
    276273    void set(const Key& first, const Key& second, const Value& val) {
    277       values[index(graph.id(first), graph.id(second))] = val;
     274      values[index(Parent::getNotifier()->id(first),
     275                   Parent::getNotifier()->id(second))] = val;
    278276    }
    279277
     
    293291
    294292    virtual void add(const Key& key) {
    295       if (size(graph.id(key) + 1) >= (int)values.size()) {
    296         values.resize(size(graph.id(key) + 1));
     293      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
     294        values.resize(size(Parent::getNotifier()->id(key) + 1));       
    297295      }
    298296    }
     
    301299
    302300    virtual void build() {
    303       values.resize(size(graph.maxId(Key()) + 1));
     301      values.resize(size(Parent::getNotifier()->maxId() + 1));
    304302    }
    305303
     
    309307   
    310308  private:
    311     const Graph& graph;
    312309    std::vector<Value> values;
    313310  };
     
    321318  template <typename _Graph, typename _Item, typename _Value>
    322319  class DynamicSymMatrixMap
    323     : protected AlterationNotifier<_Item>::ObserverBase {
    324   public:
    325     typedef typename AlterationNotifier<_Item>::ObserverBase Parent;
     320    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
     321  public:
     322    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
     323    Parent;
    326324
    327325    typedef _Graph Graph;
     
    347345    /// Creates an item matrix for the given graph.
    348346    DynamicSymMatrixMap(const Graph& _graph)
    349       : graph(_graph), values(size(_graph.maxId(Key()) + 1)) {
    350       Parent::attach(graph.getNotifier(Key()));
     347      : values(size(_graph.maxId(Key()) + 1)) {
     348      Parent::attach(_graph.getNotifier(Key()));
    351349    }
    352350
     
    356354    /// pairs of keys the given parameter.
    357355    DynamicSymMatrixMap(const Graph& _graph, const Value& _val)
    358       : graph(_graph), values(size(_graph.maxId(Key()) + 1), _val) {
    359       Parent::attach(graph.getNotifier(Key()));
    360     }
    361 
    362     ~DynamicSymMatrixMap() {
    363       if (Parent::attached()) {
    364         Parent::detach();
    365       }
     356      : values(size(_graph.maxId(Key()) + 1), _val) {
     357      Parent::attach(_graph.getNotifier(Key()));
    366358    }
    367359
     
    372364    /// pair.
    373365    ConstReference operator()(const Key& first, const Key& second) const {
    374       return values[index(graph.id(first), graph.id(second))];
     366      return values[index(Parent::getNotifier()->id(first),
     367                          Parent::getNotifier()->id(second))];
    375368    }
    376369   
     
    381374    /// pair.
    382375    Reference operator()(const Key& first, const Key& second) {
    383       return values[index(graph.id(first), graph.id(second))];
     376      return values[index(Parent::getNotifier()->id(first),
     377                          Parent::getNotifier()->id(second))];
    384378    }
    385379
     
    388382    /// Setter function for the matrix map.
    389383    void set(const Key& first, const Key& second, const Value& val) {
    390       values[index(graph.id(first), graph.id(second))] = val;
     384      values[index(Parent::getNotifier()->id(first),
     385                   Parent::getNotifier()->id(second))] = val;
    391386    }
    392387
     
    406401
    407402    virtual void add(const Key& key) {
    408       if (size(graph.id(key) + 1) >= (int)values.size()) {
    409         values.resize(size(graph.id(key) + 1));
     403      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
     404        values.resize(size(Parent::getNotifier()->id(key) + 1));       
    410405      }
    411406    }
     
    414409
    415410    virtual void build() {
    416       values.resize(size(graph.maxId(Key()) + 1));
     411      values.resize(size(Parent::getNotifier()->maxId() + 1));
    417412    }
    418413
     
    422417   
    423418  private:
    424     const Graph& graph;
    425419    std::vector<Value> values;
    426420  };
Note: See TracChangeset for help on using the changeset viewer.