#include <graph.h>
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 | |
GraphTransaction & | operator= (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 |
|
default |
|
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.
|
private |
GraphTransaction& operator= | ( | GraphTransaction && | src | ) |
maxon::Result<void> CopyFrom | ( | const GraphTransaction & | src | ) |
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.
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.
[in] | userData | User data to pass to the observers of GraphModelInterface::ObservableTransactionCommitted. This will be merged with all given user data of nested commits. |
[in] | validate | If 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. |
const GraphModelRef& GetGraph | ( | ) | const |
Returns the graph of this transaction, or a null reference when this transaction is inactive.
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().
Int GetNesting | ( | ) | const |
Returns the nesting level of the transaction. The nesting level of an outmost transaction is 0.
|
friend |
|
private |
|
private |