COIN-OR::LEMON - Graph Library

Changeset 1718:6a958ab38386 in lemon-0.x


Ignore:
Timestamp:
10/14/05 12:44:49 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2245
Message:

Extending observer interface
It will be used in the indegmap, outdegmap types

Location:
lemon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/alteration_notifier.h

    r1701 r1718  
    140140
    141141      /// \brief The member function to notificate the observer about
    142       /// simulitem is added to the container.
    143       ///
    144       /// The add() member function notificates the observer about an item
     142      /// more item is added to the container.
     143      ///
     144      /// The add() member function notificates the observer about more item
    145145      /// is added to the container. It have to be overrided in the
    146146      /// subclasses.
     
    161161      virtual void erase(const Item&) = 0;
    162162
     163      /// \brief The member function to notificate the observer about
     164      /// more item is erased from the container.
     165      ///
     166      /// The erase() member function notificates the observer about more item
     167      /// is erased from the container. It have to be overrided in the
     168      /// subclasses.
    163169      virtual void erase(const std::vector<Item>& items) {
    164170        for (int i = 0; i < (int)items.size(); ++i) {
     
    166172        }
    167173      }
     174
     175      /// \brief Signal a property change on the given item.
     176      ///
     177      /// Signal a property change on the given item. It should
     178      /// be used always with the commitChange() function.
     179      /// This function is called always the property change.
     180      /// The commitChange() is called always after the change.
     181      virtual void signalChange(const Item&) {}
     182
     183      /// \brief Commit the property change on the given item.
     184      ///
     185      /// Commit the property change on the given item. It should
     186      /// be used always with the signalChange() function.
     187      /// This function is called always the property change.
     188      /// The commitChange() is called always after the change.
     189      virtual void commitChange(const Item&) {}
    168190
    169191      /// \brief The member function to notificate the observer about the
     
    304326    }
    305327   
     328    /// \brief Signal a property change on the given item.
     329    ///
     330    /// Signal a property change on the given item. It should
     331    /// be used always with the commitChange() function.
     332    /// This function is called always the property change.
     333    /// The commitChange() is called always after the change.
     334    void signalChange(const Item& item) {
     335      typename Container::iterator it;
     336      for (it = container.begin(); it != container.end(); ++it) {
     337        (*it)->signalChange(item);
     338      }
     339    }
     340   
     341    /// \brief Commit the property change on the given item.
     342    ///
     343    /// Commit the property change on the given item. It should
     344    /// be used always with the signalChange() function.
     345    /// This function is called always the property change.
     346    /// The commitChange() is called always after the change.
     347    void commitChange(const Item& item) {
     348      typename Container::iterator it;
     349      for (it = container.begin(); it != container.end(); ++it) {
     350        (*it)->commitChange(item);
     351      }
     352    }
    306353
    307354    /// \brief Notifies all the registered observers about the container is
  • lemon/list_graph.h

    r1702 r1718  
    309309  };
    310310
    311   typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
    312   typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
    313   typedef MappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
    314   typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
    315   typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
    316311  typedef ErasableGraphExtender<
    317312    ClearableGraphExtender<
     
    321316    AlterableGraphExtender<ListGraphBase> > > > > > ExtendedListGraphBase;
    322317
    323 /// \addtogroup graphs
    324 /// @{
     318  /// \addtogroup graphs
     319  /// @{
    325320
    326321  ///A list graph class.
     
    343338    ///referencing the changed edge remain
    344339    ///valid. However <tt>InEdge</tt>'s are invalidated.
    345     void changeTarget(Edge e, Node n) { _changeTarget(e,n); }
     340    void changeTarget(Edge e, Node n) {
     341      getNotifier(Edge()).signalChange(e);
     342      _changeTarget(e,n);
     343      getNotifier(Edge()).commitChange(e);
     344    }
    346345    /// Changes the source of \c e to \c n
    347346
     
    351350    ///referencing the changed edge remain
    352351    ///valid. However <tt>OutEdge</tt>'s are invalidated.
    353     void changeSource(Edge e, Node n) { _changeSource(e,n); }
     352    void changeSource(Edge e, Node n) {
     353      getNotifier(Edge()).signalChange(e);
     354      _changeSource(e,n);
     355      getNotifier(Edge()).commitChange(e);
     356    }
    354357
    355358    /// Invert the direction of an edge.
     
    360363    void reverseEdge(Edge e) {
    361364      Node t=target(e);
     365      getNotifier(Edge()).signalChange(e);
    362366      _changeTarget(e,source(e));
    363367      _changeSource(e,t);
     368      getNotifier(Edge()).commitChange(e);
    364369    }
    365370
     
    383388    ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
    384389    ///may be invalidated.
    385     void contract(Node a,Node b,bool r=true)
     390    void contract(Node a, Node b, bool r = true)
    386391    {
    387392      for(OutEdgeIt e(*this,b);e!=INVALID;) {
     
    563568    UndirGraphExtender<ListGraphBase> > > > > > > ExtendedUndirListGraphBase;
    564569
    565 /// \addtogroup graphs
    566 /// @{
     570  /// \addtogroup graphs
     571  /// @{
    567572
    568573  ///An undirected list graph class.
     
    579584  ///
    580585  class UndirListGraph : public ExtendedUndirListGraphBase {
     586  public:
     587    typedef ExtendedUndirListGraphBase Parent;
     588    /// \brief Changes the target of \c e to \c n
     589    ///
     590    /// Changes the target of \c e to \c n
     591    ///
     592    /// \note The <tt>Edge</tt>'s and <tt>OutEdge</tt>'s
     593    /// referencing the changed edge remain
     594    /// valid. However <tt>InEdge</tt>'s are invalidated.
     595    void changeTarget(UndirEdge e, Node n) {
     596      getNotifier(UndirEdge()).signalChange(e);
     597      getNotifier(Edge()).signalChange(direct(e, true));
     598      getNotifier(Edge()).signalChange(direct(e, false));
     599      _changeTarget(e,n);
     600      getNotifier(UndirEdge()).commitChange(e);
     601      getNotifier(Edge()).commitChange(direct(e, true));
     602      getNotifier(Edge()).commitChange(direct(e, false));
     603    }
     604    /// Changes the source of \c e to \c n
     605    ///
     606    /// Changes the source of \c e to \c n
     607    ///
     608    ///\note The <tt>Edge</tt>'s and <tt>InEdge</tt>'s
     609    ///referencing the changed edge remain
     610    ///valid. However <tt>OutEdge</tt>'s are invalidated.
     611    void changeSource(UndirEdge e, Node n) {
     612      getNotifier(UndirEdge()).signalChange(e);
     613      getNotifier(Edge()).signalChange(direct(e, true));
     614      getNotifier(Edge()).signalChange(direct(e, false));
     615      _changeSource(e,n);
     616      getNotifier(UndirEdge()).commitChange(e);
     617      getNotifier(Edge()).commitChange(direct(e, true));
     618      getNotifier(Edge()).commitChange(direct(e, false));
     619    }
     620    /// \brief Contract two nodes.
     621    ///
     622    /// This function contracts two nodes.
     623    ///
     624    /// Node \p b will be removed but instead of deleting
     625    /// its neighboring edges, they will be joined to \p a.
     626    /// The last parameter \p r controls whether to remove loops. \c true
     627    /// means that loops will be removed.
     628    ///
     629    /// \note The <tt>Edge</tt>s
     630    /// referencing a moved edge remain
     631    /// valid.
     632    void contract(Node a, Node b, bool r = true) {
     633      for(IncEdgeIt e(*this, b); e!=INVALID;) {
     634        IncEdgeIt f = e; ++f;
     635        if (r && runningNode(e) == a) {
     636          erase(e);
     637        } else if (source(e) == b) {
     638          changeSource(e, a);
     639        } else {
     640          changeTarget(e, a);
     641        }
     642        e = f;
     643      }
     644      erase(b);
     645    }
    581646  };
    582647
  • lemon/smart_graph.h

    r1692 r1718  
    7676
    7777    SmartGraphBase() : nodes(), edges() { }
    78     SmartGraphBase(const SmartGraphBase &_g) : nodes(_g.nodes), edges(_g.edges) { }
     78    SmartGraphBase(const SmartGraphBase &_g)
     79      : nodes(_g.nodes), edges(_g.edges) { }
    7980   
    8081    typedef True NodeNumTag;
     
    315316    Node split(Node n, bool connect = true)
    316317    {
    317       return _split(n,connect);
     318      for (OutEdgeIt it(*this, n); it != INVALID; ++it) {
     319        getNotifier(Edge()).signalChange(it);
     320      }
     321      Node b = _split(n,connect);
     322      for (OutEdgeIt it(*this, b); it != INVALID; ++it) {
     323        getNotifier(Edge()).commitChange(it);
     324      }
     325      return b;
    318326    }
    319327 
Note: See TracChangeset for help on using the changeset viewer.