Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ITransaction.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Internationalization/Text.h"
7#include "Misc/Guid.h"
8#include "Internationalization/Text.h"
9#include "UObject/UObjectHierarchyFwd.h"
10#include "Change.h"
11
12// Class for handling undo/redo transactions among objects.
13typedef void(*STRUCT_DC)( void* TPtr ); // default construct
14typedef void(*STRUCT_AR)( class FArchive& Ar, void* TPtr ); // serialize
15typedef void(*STRUCT_DTOR)( void* TPtr ); // destruct
16
17
18/** Different kinds of actions that can trigger a transaction state change */
20{
21 /** A transaction has been started. This will be followed by a TransactionCanceled or TransactionFinalized event. */
23 /** A transaction was canceled. */
25 /** A transaction is about to be finalized. It is still safe to temporarily open new transactions within the scope of this event. */
27 /** A transaction was finalized. */
29 /** A transaction has been finalized and the internal transaction state has been updated */
31
32 /** A transaction will be used used in an undo/redo operation. This will be followed by a UndoRedoFinalized event. */
34 /** A transaction has been used in an undo/redo operation. */
36};
37
38
39/**
40 * Convenience struct for passing around transaction context.
41 */
43{
47 , Title()
48 , Context()
49 , PrimaryObject(nullptr)
50 {
51 }
52
53 FTransactionContext(const FGuid& InTransactionId, const FGuid& InOperationId, const FText& InSessionTitle, const TCHAR* InContext, UObject* InPrimaryObject)
54 : TransactionId(InTransactionId)
55 , OperationId(InOperationId)
58 , PrimaryObject(InPrimaryObject)
59 {
60 }
61
62 bool IsValid() const
63 {
65 }
66
67 /** Unique identifier for the transaction, used to track it during its lifetime */
69 /** Unique identifier for the active operation on the transaction (if any) */
71 /** Descriptive title of the transaction */
73 /** The context that generated the transaction */
75 /** The primary UObject for the transaction (if any). */
77};
78
79
80/**
81 * Interface for transactions.
82 *
83 * Transactions are created each time an UObject is modified, for example in the Editor.
84 * The data stored inside a transaction object can then be used to provide undo/redo functionality.
85 */
87{
88public:
89
90 /** BeginOperation should be called when a transaction or undo/redo starts */
91 virtual void BeginOperation() = 0;
92
93 /** EndOperation should be called when a transaction is finalized or canceled or undo/redo ends */
94 virtual void EndOperation() = 0;
95
96 /** Called when this transaction is completed to finalize the transaction */
97 virtual void Finalize() = 0;
98
99 /** Applies the transaction. */
100 virtual void Apply() = 0;
101
102 /** Gets the full context for the transaction */
103 virtual FTransactionContext GetContext() const = 0;
104
105 /**
106 * Report if a transaction should be put in the undo buffer.
107 * A transaction will be transient if it contains PIE objects or result in a no-op.
108 * If this returns true the transaction won't be put in the transaction buffer.
109 * @returns true if the transaction is transient.
110 */
111 virtual bool IsTransient() const = 0;
112
113 /** @returns if this transaction tracks PIE objects */
114 virtual bool ContainsPieObjects() const = 0;
115
116 /**
117 * Saves an array to the transaction.
118 *
119 * @param Object The object that owns the array.
120 * @param Array The array to save.
121 * @param Index
122 * @param Count
123 * @param Oper
124 * @param ElementSize
125 * @param ElementAlignment
126 * @param Serializer
127 * @param Destructor
128 * @see SaveObject
129 */
130 virtual void SaveArray( UObject* Object, class FScriptArray* Array, int32 Index, int32 Count, int32 Oper, int32 ElementSize, uint32 ElementAlignment, STRUCT_DC DefaultConstructor, STRUCT_AR Serializer, STRUCT_DTOR Destructor ) = 0;
131
132 /**
133 * Saves an UObject to the transaction.
134 *
135 * @param Object The object to save.
136 *
137 * @see SaveArray
138 */
139 virtual void SaveObject( UObject* Object ) = 0;
140
141 /**
142 * Stores a command that can be used to undo a change to the specified object. This may be called multiple times in the
143 * same transaction to stack up changes that will be rolled back in reverse order. No copy of the object itself is stored.
144 *
145 * @param Object The object the undo change will apply to
146 * @param CustomChange The change that can be used to undo the changes to this object.
147 */
148 virtual void StoreUndo( UObject* Object, TUniquePtr<FChange> CustomChange ) = 0;
149
150 /**
151 * Sets the transaction's primary object.
152 *
153 * @param Object The primary object to set.
154 */
155 virtual void SetPrimaryObject( UObject* Object ) = 0;
156
157 /**
158 * Snapshots a UObject within the transaction.
159 *
160 * @param Object The object to snapshot.
161 * @param Property The optional list of properties that have potentially changed on the object (to avoid snapshotting the entire object).
162 */
163 virtual void SnapshotObject( UObject* Object, TArrayView<const FProperty*> Properties ) = 0;
164
165 /**
166 * Does the transaction know that the object is being modified.
167 */
168 virtual bool ContainsObject(const UObject* Object) const = 0;
169};
ETransactionStateEventType
Definition Enums.h:22798
void(* STRUCT_DC)(void *TPtr)
void(* STRUCT_AR)(class FArchive &Ar, void *TPtr)
void(* STRUCT_DTOR)(void *TPtr)
Definition Text.h:357
virtual void SetPrimaryObject(UObject *Object)=0
virtual void SaveObject(UObject *Object)=0
virtual void SnapshotObject(UObject *Object, TArrayView< const FProperty * > Properties)=0
virtual void Finalize()=0
virtual void EndOperation()=0
virtual bool IsTransient() const =0
virtual void Apply()=0
virtual void BeginOperation()=0
virtual bool ContainsPieObjects() const =0
virtual void StoreUndo(UObject *Object, TUniquePtr< FChange > CustomChange)=0
virtual bool ContainsObject(const UObject *Object) const =0
virtual FTransactionContext GetContext() const =0
virtual void SaveArray(UObject *Object, class FScriptArray *Array, int32 Index, int32 Count, int32 Oper, int32 ElementSize, uint32 ElementAlignment, STRUCT_DC DefaultConstructor, STRUCT_AR Serializer, STRUCT_DTOR Destructor)=0
Definition Guid.h:108
FGuid()
Definition Guid.h:112
bool IsValid() const
Definition Guid.h:310
bool IsValid() const
FTransactionContext(const FGuid &InTransactionId, const FGuid &InOperationId, const FText &InSessionTitle, const TCHAR *InContext, UObject *InPrimaryObject)
UObject * PrimaryObject
Definition UE.h:432