Open Search
    GraphTransaction Class Reference

    #include <graph.h>

    Detailed Description

    Modifications to a GraphModelInterface may only be done when there is an active GraphTransaction. You start a transaction by calling GraphModelInterface::BeginTransaction() on the graph to modify. When all modifications are done, you call Commit() to make them permanent, or Rollback() to return to the state of the graph when BeginTransaction() has been called.

    Transactions can be nested. A commit or rollback ends the current (innermost) transaction, but not enclosing transactions. However only the outmost transaction triggers the observables GraphModelInterface::ObservableTransactionStarted, GraphModelInterface::ObservableTransactionCommitted, GraphModelInterface::ObservableTransactionRolledBack.

    If a GraphTransaction goes out of scope but is still active (Commit() or Rollback() hasn't been called), a rollback is triggered implicitly by the destructor. This is important for error handling, as it implies that in case of an unhandled error an implicit rollback is made. This prevents inconsistent states of the graph.

    Public Member Functions

     GraphTransaction ()=default
     
     GraphTransaction (GraphTransaction &&src)=default
     
    GraphTransactionoperator= (GraphTransaction &&src)
     
    maxon::Result< void > CopyFrom (const GraphTransaction &src)
     
     ~GraphTransaction ()
     
    void Rollback ()
     
    Result< void > Commit (const DataDictionary &userData=GetPtrSizedZeroRef< DataDictionary >(), Bool validate=true)
     
    const GraphModelRef & GetGraph () const
     
    Bool IsActive () const
     
    Int GetNesting () const
     

    Private Member Functions

     GraphTransaction (const GraphModelRef &graph, Int nesting)
     

    Private Attributes

    GraphModelRef _graph
     
    Int _nesting
     

    Friends

    class GraphModelInterface
     

    Constructor & Destructor Documentation

    ◆ GraphTransaction() [1/3]

    GraphTransaction ( )
    default

    ◆ GraphTransaction() [2/3]

    GraphTransaction ( GraphTransaction &&  src)
    default

    ◆ ~GraphTransaction()

    Does a rollback when this transaction is still active. This enables an automatic rollback to the previous consistent state of the graph in case of an error.

    ◆ GraphTransaction() [3/3]

    GraphTransaction ( const GraphModelRef &  graph,
    Int  nesting 
    )
    private

    Member Function Documentation

    ◆ operator=()

    GraphTransaction& operator= ( GraphTransaction &&  src)

    ◆ CopyFrom()

    maxon::Result<void> CopyFrom ( const GraphTransaction src)

    ◆ Rollback()

    void Rollback ( )

    Rolls back the graph to its state at the time this transaction has been started, and ends this transaction. If this transaction isn't nested within an enclosing transaction, the observable GraphModelInterface::ObservableTransactionRolledBack informs its observers about the rollback.

    ◆ Commit()

    Result<void> Commit ( const DataDictionary &  userData = GetPtrSizedZeroRef< DataDictionary >(),
    Bool  validate = true 
    )

    Commits (ends) this transaction. The changes made within this transaction become permanent in the graph (unless this is a nested transaction and an enclosing transaction is rolled back later). If this transaction isn't nested within an enclosing transaction, the observable GraphModelInterface::ObservableTransactionCommitted informs its observers about the commit.

    If this transaction isn't active, nothing happens.

    Parameters
    [in]userDataUser data to pass to the observers of GraphModelInterface::ObservableTransactionCommitted. This will be merged with all given user data of nested commits.
    [in]validateIf false, no validation of the graph is made when this transaction is a nested one. This can be used to avoid unnecessary validations for nested transactions.

    ◆ GetGraph()

    const GraphModelRef& GetGraph ( ) const

    Returns the graph of this transaction, or a null reference when this transaction is inactive.

    Returns
    Graph of transaction, or null reference.

    ◆ IsActive()

    Bool IsActive ( ) const

    Checks if this transaction is active. A transaction is active between the initial call to GraphModelInterface::BeginTransaction() and the corresponding call to Commit() or Rollback().

    Returns
    true if this transaction is active, otherwise false.

    ◆ GetNesting()

    Int GetNesting ( ) const

    Returns the nesting level of the transaction. The nesting level of an outmost transaction is 0.

    Returns
    Nesting level of the transaction.

    Friends And Related Function Documentation

    ◆ GraphModelInterface

    friend class GraphModelInterface
    friend

    Member Data Documentation

    ◆ _graph

    GraphModelRef _graph
    private

    ◆ _nesting

    Int _nesting
    private