#include <struct_utils.hpp>
Public Member Functions | |
| size_t | get_struct_sz (arion::CPU_ARCH arch) |
| size_t | get_host_struct_sz () |
| STRUCT_ID | feed (arion::CPU_ARCH arch, arion::BYTE *struct_inst) |
| STRUCT_ID | feed_host (T *struct_inst) |
| arion::BYTE * | build (STRUCT_ID id, arion::CPU_ARCH arch, size_t &struct_len) |
| T * | build_host (STRUCT_ID id) |
| std::string | to_string (STRUCT_ID id, std::shared_ptr< arion::Arion > arion, arion::CPU_ARCH arch) |
| void | release_struct (STRUCT_ID id) |
| void | clear_structs () |
Protected Types | |
| using | ftype = arion_poly_struct::POLYMORPHIC_STRUCT_FIELD_TYPE |
Macro for easy access to POLYMORPHIC_STRUCT_FIELD_TYPE in subclass definitions. | |
Protected Member Functions | |
| PolymorphicStructFactory (std::vector< POLYMORPHIC_STRUCT_FIELD > fields) | |
| ~PolymorphicStructFactory () | |
Private Member Functions | |
| STRUCT_ID | gen_next_id () |
| STRUCT_ID | add_struct_entry (std::unique_ptr< PolymorphicStruct > struct_inst) |
| uint8_t | get_align (arion::CPU_ARCH arch) |
| uint8_t | get_ptr_sz (arion::CPU_ARCH arch) |
| uint16_t | get_arch_sz (arion::CPU_ARCH arch) |
Private Attributes | |
| STRUCT_ID | curr_id = 1 |
| Counter for generating unique structure IDs. | |
| std::stack< STRUCT_ID > | free_ids |
| Stack of released IDs for reuse. | |
| std::map< STRUCT_ID, std::unique_ptr< PolymorphicStruct > > | curr_structs |
| Map of currently allocated polymorphic structure instances. | |
| std::vector< POLYMORPHIC_STRUCT_FIELD > | fields |
| Definition of all potential fields in the polymorphic structure. | |
Manages the definition and instantiation of polymorphic structures (structs whose layout changes per architecture).
| T | The host-side C++ type corresponding to the structure being managed. |
|
protected |
Macro for easy access to POLYMORPHIC_STRUCT_FIELD_TYPE in subclass definitions.
|
inlineprotected |
Builder for PolymorphicStructFactory instances.
| [in] | fields | The vector of field definitions defining the structure layout. |
|
inlineprotected |
Destructor: cleans up all currently managed structure instances.
|
inlineprivate |
Allocates a new STRUCT_ID and stores the polymorphic instance.
| [in] | struct_inst | Unique pointer to the PolymorphicStruct instance. |
STRUCT_ID.
|
inline |
Builds the raw memory representation of a managed structure instance for a target architecture.
| [in] | id | The ID of the managed structure instance. |
| [in] | arch | The target CPU architecture for layout. |
| [out] | struct_len | The size of the resulting raw data buffer. |
|
inline |
Builds and returns a host-side C++ structure (T) instance from a managed instance.
| [in] | id | The ID of the managed structure instance. |
T*).
|
inline |
Releases all currently managed structure instances.
|
inline |
Parses raw memory data representing a structure instance and creates a corresponding PolymorphicStruct object.
| [in] | arch | The architecture used to interpret the structure layout (size, alignment). |
| [in] | struct_inst | Pointer to the raw byte data of the structure. |
PolymorphicStruct instance.
|
inline |
Feeds an existing host-side structure instance to the factory and gets its STRUCT_ID.
| [in] | struct_inst | Pointer to the host structure instance. |
PolymorphicStruct instance.
|
inlineprivate |
Generates a new unique STRUCT_ID.
STRUCT_ID.
|
inlineprivate |
Retrieves the required memory alignment for the given architecture.
| [in] | arch | The CPU architecture. |
|
inlineprivate |
Retrieves the bit size (32 or 64) for the given architecture.
| [in] | arch | The CPU architecture. |
|
inline |
Calculates the memory size of the structure instance for the host architecture.
|
inlineprivate |
Retrieves the pointer size for the given architecture.
| [in] | arch | The CPU architecture. |
|
inline |
Calculates the memory size of the structure instance for a given target architecture, accounting for padding and alignment.
| [in] | arch | The target CPU architecture. |
|
inline |
Releases a managed structure instance, freeing its allocated resources and making its ID available for reuse.
| [in] | id | The ID of the structure instance to release. |
|
inline |
Generates a string representation of the managed structure instance, formatting values using their KernelType.
| [in] | id | The ID of the managed structure instance. |
| [in] | arion | Shared pointer to the Arion instance (needed for memory access in some KernelType::str calls). |
| [in] | arch | The architecture to assume for pointer sizes and field interpretation. |
|
private |
Counter for generating unique structure IDs.
|
private |
Map of currently allocated polymorphic structure instances.
|
private |
Definition of all potential fields in the polymorphic structure.
|
private |
Stack of released IDs for reuse.