Class UnionDataManager
Defined in File union-data-manager.h
Class Documentation
-
class UnionDataManager
A class that manages writable storage for struct editing, including deep-copy.
This class provides a convenient option for updating the members of a struct that is described by a Union metadata instance.
This class has two constructors; one takes only a pointer to the Union metadata instance, while the other also takes a pointer to immutable source data (the "copy" constructor). In both cases, this class will create enough space to contain all of the struct's data; in the case of the "copy" constructor, it will create enough space to contain a full "deep copy" of the source data (taking into account all existing struct and array references as well as any element counts therein). Note that the non-copy constructor will not anticipate any "nesting" requirements, and therefore only enough space is created for the "top-level" struct.
Regardless which constructor is called, the storage allocated for this struct data is owned by this class, and will be valid for the lifetime of this class. A pointer to this memory is available via the MutableBase() method, and if the caller has access to the original struct declaration, they can simply cast the pointer returned by this method as a pointer to the declared struct and edit the data "the easy way". In other words, there is nothing special about the storage managed by this class; this class exists merely to manage that memory as well as perform any deep copy necessary.
- Deprecated:
May be removed in future releases. Instead use the StructDataManager
Public Functions
-
UnionDataManager()
Default constructor, initializes all members to nullptr.
See also
UnionDataManager(void cosnt* base, Union const* structDef)
-
UnionDataManager(Union const *unionDef)
Allocate storage for the struct described by structDef.
See also
UnionDataManager(void cosnt* base, Union const* structDef)
- Parameters
structDef -- Pointer to metadata describing the struct, whose data this class will manage.
-
UnionDataManager(void const *base, Union const *unionDef)
"Copy" constructor that will allocate storage for this struct, and also for any "nested" data referenced by the struct data provided via base.
Call this constructor if you have a pointer to constant, non-modifiable data that you would like to update. This constructor will create enough storage to hold a "deep copy" (that is, a copy of the top-level struct as well as all "nested" data refernced by it), and then perform the deep copy of the source data to the modifiable space. All pointers in the modifiable copy are updated to reference the mutable data and therefore updates to this memory will not affect the original copy. If base is
nullptr
, then calling this constructor is identical to calling the non-"copy" constructor.See also
operator bool()
Note
If structDef is null, then this object is "invalid" and no deep-copy is performed on the source data (assuming that base is not null), and no space is allocated or managed.
- Parameters
base -- Pointer to memory containing an immutable copy of the data to be managed by this struct.
structDef -- Pointer to metadata describing the struct, whose data this class will manage.
-
UnionDataManager(void const *base, size_t count, Union const *unionDef)
"Copy" constructor that will allocate storage for the array of structs, and also for any "nested" data referenced by the structs data provided via base.
-
UnionDataManager(UnionDataManager const &other)
Standard copy constructor.
See also
- Parameters
other -- Source UnionDataManager to copy.
-
UnionDataManager(UnionDataManager &&other)
Standard move constructor.
After this operation, the source object is left in its default-constructed state.
- Parameters
other -- Source UnionDataManager to move.
-
~UnionDataManager()
Standard destructor.
-
UnionDataManager &operator=(UnionDataManager const &other)
Standard assignment operator.
After this assignment is complete, the destination ("this" object) will contain a full, proper deep copy of the source object; no dependencies will exist between the two objects.
- Parameters
other -- Source object (RHS) for the assignment operation.
- Returns
Reference to "this" (assignment destination)
-
UnionDataManager &operator=(UnionDataManager &&other)
Standard move-assingment operator.
After this assignment is complete, the destination ("this" object) has ownership of the full state of the source object as it existed prior to the operation. After this operation, the source object will be in its default-constructed state, and no dependencies will exist between the two objects.
- Parameters
other -- Source object (RHS) for the assignment operation.
- Returns
Reference to "this" (assignment destination)
-
operator bool() const
Returns "true" if "this" is a valid object, false otherwise.
Object validity is determined by the values of the object data members; specifically, if the object has a valid Union instance, and possesses either valid "original" data or valid "mutable data", then it is considered to be a valid object and this operator will return true.
-
void *MutableBase() const
Access the mutable copy of the struct data.
- Returns
Pointer to memory corresponding to the start of storage for the top-level struct.
-
size_t MutableBaseSize() const
Returns the size of mutable copy of the struct data.
-
void const *UnmodifiedBase() const
Access the original data (if any) used to make the deep copy.
- Returns
If the "copy" constructor was invoked, this will return the "base" pointer originally provided. If that pointer was null or the non-"copy" constructor was called, this method returns
nullptr
.