|
GridFire v0.7.6rc4.0
General Purpose Nuclear Network
|
Container for managing a collection of typed scratchpad instances. More...
#include <blob.h>
Public Types | |
| enum class | Error : uint8_t { SCRATCHPAD_NOT_FOUND , SCRATCHPAD_BAD_CAST , SCRATCHPAD_NOT_INITIALIZED , SCRATCHPAD_TYPE_COLLISION , SCRATCHPAD_OUT_OF_BOUNDS , SCRATCHPAD_UNKNOWN_ERROR } |
| Error codes for scratchpad operations. More... | |
| enum class | ScratchPadStatus : uint8_t { NOT_ENROLLED , ENROLLED_NOT_INITIALIZED , ENROLLED_INITIALIZED } |
| Status codes for scratchpad slots. More... | |
Public Member Functions | |
| StateBlob ()=default | |
| Default constructor. | |
| ~StateBlob ()=default | |
| Default destructor. | |
| template<IsScratchPad CTX> | |
| void | enroll () |
| Enroll a new scratchpad type into the blob. | |
| template<IsScratchPad CTX> | |
| std::expected< CTX *, Error > | get () const |
| Retrieve a scratchpad by type. | |
| template<IsScratchPad CTX, bool MUST_BE_INITIALIZED> | |
| std::expected< CTX *, Error > | get () const |
| Retrieve a scratchpad by type with optional initialization check. | |
| std::expected< AbstractScratchPad *, Error > | get (const ScratchPadType type) const |
| Retrieve a scratchpad by runtime ScratchPadType value. | |
| std::unique_ptr< StateBlob > | clone_structure () const |
| Create a deep copy of this blob with all enrolled scratchpads. | |
| std::unordered_set< ScratchPadType > | get_registered_scratchpads () const |
| Get the set of all registered scratchpad types. | |
| template<IsScratchPad CTX> | |
| bool | initialized () const |
| Check if a specific scratchpad type is initialized. | |
| template<IsScratchPad CTX> | |
| ScratchPadStatus | get_status () const |
| Get the status of a specific scratchpad type. | |
| std::unordered_map< ScratchPadType, ScratchPadStatus > | get_status_map () const |
| Get a map of all scratchpad types to their current status. | |
Static Public Member Functions | |
| static std::string | error_to_string (const Error error) |
| Convert an Error enum value to a human-readable string. | |
Private Attributes | |
| std::array< std::unique_ptr< AbstractScratchPad >, MAX_SCRATCHPADS > | scratchpads {} |
| Array of scratchpad instances indexed by ScratchPadType. | |
| std::array< bool, MAX_SCRATCHPADS > | scratchpad_enrolled_flags {false} |
| Flags indicating which scratchpad slots have been enrolled. | |
Static Private Attributes | |
| static constexpr size_t | MAX_SCRATCHPADS = static_cast<size_t>(ScratchPadType::_COUNT) |
| Maximum number of scratchpad slots, derived from ScratchPadType::_COUNT. | |
Container for managing a collection of typed scratchpad instances.
StateBlob provides a centralized registry for scratchpads used by engines. It uses a fixed-size array indexed by ScratchPadType for O(1) access, with compile-time type safety enforced through the IsScratchPad concept.
The blob supports:
|
strong |
Error codes for scratchpad operations.
| Enumerator | |
|---|---|
| SCRATCHPAD_NOT_FOUND | Requested scratchpad type is not enrolled. |
| SCRATCHPAD_BAD_CAST | Dynamic cast to requested type failed. |
| SCRATCHPAD_NOT_INITIALIZED | Scratchpad exists but is not initialized. |
| SCRATCHPAD_TYPE_COLLISION | Attempted to enroll duplicate type. |
| SCRATCHPAD_OUT_OF_BOUNDS | ScratchPadType index exceeds array bounds. |
| SCRATCHPAD_UNKNOWN_ERROR | Unspecified error condition. |
|
strong |
|
default |
Default constructor.
|
default |
Default destructor.
|
inlinenodiscard |
Create a deep copy of this blob with all enrolled scratchpads.
Clones the blob structure and all enrolled scratchpads using their clone() methods. The resulting blob is independent and can be used in a separate thread.
|
inline |
Enroll a new scratchpad type into the blob.
Creates a new instance of the specified scratchpad type and registers it in the appropriate slot. Only one instance per type is allowed.
| CTX | The scratchpad type to enroll (must satisfy IsScratchPad). |
| exceptions::ScratchPadError | if a scratchpad of this type is already enrolled. |
|
inlinestatic |
Convert an Error enum value to a human-readable string.
| error | The error code to convert. |
|
inline |
Retrieve a scratchpad by type.
Returns a pointer to the enrolled scratchpad of the specified type. In debug builds, performs a dynamic_cast for type safety; in release builds, uses static_cast for performance.
| CTX | The scratchpad type to retrieve (must satisfy IsScratchPad). |
|
inline |
Retrieve a scratchpad by type with optional initialization check.
Returns a pointer to the enrolled scratchpad of the specified type. When MUST_BE_INITIALIZED is true, also verifies that the scratchpad has been initialized before returning it.
| CTX | The scratchpad type to retrieve (must satisfy IsScratchPad). |
| MUST_BE_INITIALIZED | If true, returns an error for uninitialized scratchpads. |
|
inlinenodiscard |
Retrieve a scratchpad by runtime ScratchPadType value.
Returns a pointer to the abstract base class for the scratchpad at the specified type index. Useful when the concrete type is not known at compile time.
| type | The ScratchPadType enum value identifying the scratchpad. |
|
inlinenodiscard |
Get the set of all registered scratchpad types.
|
inlinenodiscard |
Get the status of a specific scratchpad type.
| CTX | The scratchpad type to query (must satisfy IsScratchPad). |
|
inlinenodiscard |
Get a map of all scratchpad types to their current status.
|
inlinenodiscard |
Check if a specific scratchpad type is initialized.
| CTX | The scratchpad type to check (must satisfy IsScratchPad). |
| exceptions::ScratchPadError | if the scratchpad type is not enrolled. |
|
staticconstexprprivate |
Maximum number of scratchpad slots, derived from ScratchPadType::_COUNT.
|
private |
Flags indicating which scratchpad slots have been enrolled.
|
private |
Array of scratchpad instances indexed by ScratchPadType.