Porytiles
Loading...
Searching...
No Matches
porytiles2::OperandBundle Class Reference

A type-erased container for orchestration operands with runtime type checking. More...

#include <operand_bundle.hpp>

Public Types

using iterator = std::unordered_map< std::string, std::any >::iterator
 
using const_iterator = std::unordered_map< std::string, std::any >::const_iterator
 

Public Member Functions

 OperandBundle ()=default
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
std::optional< std::any > get (const std::string &key) const
 Retrieves an operand value as std::any.
 
template<typename T >
std::optional< T > get_unwrapped (const std::string &key) const
 Retrieves and casts an operand value to the specified type.
 
std::size_t size () const
 Returns the number of operands stored in the bundle.
 
void put (const std::string &key, const std::any &value)
 Stores an operand value with the given key.
 
bool contains (const std::string &key) const
 Checks if an operand with the given key exists.
 
std::optional< std::type_index > type_index_of (const std::string &key) const
 Retrieves the runtime type information for an operand.
 
bool satisfies_declarations (const std::vector< OperandDeclaration > &declarations) const
 Validates that the bundle satisfies a set of operand declarations.
 

Detailed Description

A type-erased container for orchestration operands with runtime type checking.

OperandBundle provides a key-value store that can hold operands of any type using std::any. It supports type-safe retrieval, validation against OperandDeclaration specifications, and range-based iteration. This class is primarily used by the orchestration framework to pass data between Operation instances while maintaining type safety at runtime.

Definition at line 25 of file operand_bundle.hpp.

Member Typedef Documentation

◆ const_iterator

using porytiles2::OperandBundle::const_iterator = std::unordered_map<std::string, std::any>::const_iterator

Definition at line 31 of file operand_bundle.hpp.

◆ iterator

using porytiles2::OperandBundle::iterator = std::unordered_map<std::string, std::any>::iterator

Definition at line 30 of file operand_bundle.hpp.

Constructor & Destructor Documentation

◆ OperandBundle()

porytiles2::OperandBundle::OperandBundle ( )
default

Member Function Documentation

◆ begin() [1/2]

OperandBundle::const_iterator porytiles2::OperandBundle::begin ( ) const
noexcept

Definition at line 19 of file operand_bundle.cpp.

◆ begin() [2/2]

OperandBundle::iterator porytiles2::OperandBundle::begin ( )
noexcept

Definition at line 9 of file operand_bundle.cpp.

◆ cbegin()

OperandBundle::const_iterator porytiles2::OperandBundle::cbegin ( ) const
noexcept

Definition at line 29 of file operand_bundle.cpp.

◆ cend()

OperandBundle::const_iterator porytiles2::OperandBundle::cend ( ) const
noexcept

Definition at line 34 of file operand_bundle.cpp.

◆ contains()

bool porytiles2::OperandBundle::contains ( const std::string &  key) const

Checks if an operand with the given key exists.

Parameters
keyThe string key to check for existence
Returns
true if the key exists in the bundle, false otherwise

Definition at line 58 of file operand_bundle.cpp.

◆ end() [1/2]

OperandBundle::const_iterator porytiles2::OperandBundle::end ( ) const
noexcept

Definition at line 24 of file operand_bundle.cpp.

◆ end() [2/2]

OperandBundle::iterator porytiles2::OperandBundle::end ( )
noexcept

Definition at line 14 of file operand_bundle.cpp.

◆ get()

std::optional< std::any > porytiles2::OperandBundle::get ( const std::string &  key) const

Retrieves an operand value as std::any.

Returns the operand associated with the given key wrapped in std::optional. If the key does not exist, returns std::nullopt.

Parameters
keyThe string key identifying the operand
Returns
std::optional<std::any> containing the value if found, std::nullopt otherwise

Definition at line 40 of file operand_bundle.cpp.

◆ get_unwrapped()

template<typename T >
std::optional< T > porytiles2::OperandBundle::get_unwrapped ( const std::string &  key) const
inline

Retrieves and casts an operand value to the specified type.

Performs type-safe retrieval and casting of an operand value. If the key exists but the stored type does not match T, the function will panic. If the key does not exist, returns std::nullopt.

Template Parameters
TThe expected type of the operand
Parameters
keyThe string key identifying the operand
Precondition
If key exists, the stored type must match T
Returns
std::optional<T> containing the cast value if found and type matches

Definition at line 66 of file operand_bundle.hpp.

◆ put()

void porytiles2::OperandBundle::put ( const std::string &  key,
const std::any &  value 
)

Stores an operand value with the given key.

Inserts or updates an operand in the bundle. If the key already exists, the previous value is replaced.

Parameters
keyThe string key to associate with the value
valueThe operand value to store (type-erased as std::any)

Definition at line 53 of file operand_bundle.cpp.

◆ satisfies_declarations()

bool porytiles2::OperandBundle::satisfies_declarations ( const std::vector< OperandDeclaration > &  declarations) const

Validates that the bundle satisfies a set of operand declarations.

Checks that all required operands specified in the declarations are present in the bundle and have the correct types. This is used by the orchestration framework to validate Operation inputs and outputs.

Parameters
declarationsVector of OperandDeclaration objects specifying required operands
Returns
true if all declarations are satisfied, false otherwise

Definition at line 71 of file operand_bundle.cpp.

◆ size()

std::size_t porytiles2::OperandBundle::size ( ) const

Returns the number of operands stored in the bundle.

Returns
The count of key-value pairs in the bundle

Definition at line 48 of file operand_bundle.cpp.

◆ type_index_of()

std::optional< std::type_index > porytiles2::OperandBundle::type_index_of ( const std::string &  key) const

Retrieves the runtime type information for an operand.

Returns the std::type_index of the value stored at the given key. This is useful for runtime type checking and validation.

Parameters
keyThe string key identifying the operand
Returns
std::optional<std::type_index> containing the type if key exists, std::nullopt otherwise

Definition at line 63 of file operand_bundle.cpp.


The documentation for this class was generated from the following files: