Class StructDataManager

Class Documentation

class StructDataManager

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 Struct metadata instance.

This class has two constructors; one takes only a pointer to the Struct 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.

Public Functions

StructDataManager()

Default constructor, initializes all members to nullptr.

See also

StructDataManager(void cosnt* base, Struct const* structDef)

StructDataManager(Struct const *structDef)

Allocate storage for the struct described by structDef.

See also

StructDataManager(void cosnt* base, Struct const* structDef)

Parameters

structDef -- Pointer to metadata describing the struct, whose data this class will manage.

StructDataManager(void const *base, Struct const *structDef)

"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.

StructDataManager(void const *base, size_t count, Struct const *structDef)

"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.

StructDataManager(Union const *unionDef)

Allocate storage for the union described by unionDef.

See also

StructDataManager(void cosnt* base, Union const* unionDef)

Parameters

unionDef -- Pointer to metadata describing the union, whose data this class will manage.

StructDataManager(void const *base, Union const *unionDef)

"Copy" constructor that will allocate storage for this union, and also for any "nested" data referenced by the union 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 union 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 unionDef 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 union.

  • unionDef -- Pointer to metadata describing the union, whose data this class will manage.

StructDataManager(void const *base, size_t count, Union const *unionDef)

"Copy" constructor that will allocate storage for the array of unions, and also for any "nested" data referenced by the unions data provided via base.

StructDataManager(StructDataManager const &other)

Standard copy constructor.

See also

operator=().

Parameters

other -- Source StructDataManager to copy.

StructDataManager(StructDataManager &&other) noexcept

Standard move constructor.

After this operation, the source object is left in its default-constructed state.

Parameters

other -- Source StructDataManager to move.

~StructDataManager()

Standard destructor.

StructDataManager &operator=(StructDataManager 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)

StructDataManager &operator=(StructDataManager &&other) noexcept

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 Struct 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.

Struct const *StructDef() const

Access the metadata for the top-level struct used to construct this class.

Returns

Pointer to the top-level struct metadata.

Union const *UnionDef() const

Access the metadata for the top-level union used to construct this class.

Returns

Pointer to the top-level union metadata.

void Observe(StructDataObserver &observer) const