HydroCouple  2.0.0-alpha.1
HydroCouple Interface Definitions
Loading...
Searching...
No Matches
HydroCouple::Helpers Namespace Reference

Non-normative convenience helpers for the HydroCouple interface standard. More...

Classes

struct  DataKindOf
 DataKindOf maps a C++ type to its DataKind at compile time. More...
 
struct  DataKindOf< bool >
 
struct  DataKindOf< double >
 
struct  DataKindOf< float >
 
struct  DataKindOf< int16_t >
 
struct  DataKindOf< int32_t >
 
struct  DataKindOf< int64_t >
 
struct  DataKindOf< int8_t >
 
struct  DataKindOf< std::string >
 
struct  DataKindOf< uint16_t >
 
struct  DataKindOf< uint32_t >
 
struct  DataKindOf< uint64_t >
 
struct  DataKindOf< uint8_t >
 

Functions

constexpr int64_t dataKindSize (DataKind kind)
 Size in bytes of one element of the given DataKind.
 
constexpr int64_t elementCount (const BufferDescriptor &d)
 Number of elements a BufferDescriptor describes (product of shape; 1 for rank 0).
 
constexpr bool isContiguous (const BufferDescriptor &d)
 Checks whether a BufferDescriptor's layout is C-contiguous (row-major, packed).
 
constexpr int64_t byteOffset (const BufferDescriptor &d, std::span< const int64_t > index)
 Byte offset from a descriptor's base address of the element at the given index.
 
constexpr int64_t contiguousByteSize (const BufferDescriptor &d)
 Total byte extent of a C-contiguous buffer of the descriptor's shape and kind.
 
constexpr BufferDescriptor makeContiguous (void *data, DataKind kind, std::span< const int64_t > shape)
 Builds a C-contiguous host BufferDescriptor.
 
constexpr bool isValidComponentStatusTransition (IModelComponent::ComponentStatus from, IModelComponent::ComponentStatus to)
 Encodes the normative component lifecycle state machine.
 
template<typename T>
bool getValue (const IComponentDataItem &item, T &value, std::span< const int64_t > index)
 Typed convenience: reads the single element at the given index of a data item.
 
template<typename T>
bool setValue (IComponentDataItem &item, const T &value, std::span< const int64_t > index)
 Typed convenience: writes the single element at the given index of a data item.
 
template<typename T>
bool getValues (const IComponentDataItem &item, std::span< T > destination, std::span< const int64_t > start, std::span< const int64_t > count)
 Typed convenience: reads a hyperslab into a flat contiguous span in C order.
 
template<typename T>
bool setValues (IComponentDataItem &item, std::span< const T > source, std::span< const int64_t > start, std::span< const int64_t > count)
 Typed convenience: writes a hyperslab from a flat contiguous span in C order.
 

Detailed Description

Non-normative convenience helpers for the HydroCouple interface standard.

Function Documentation

◆ byteOffset()

int64_t HydroCouple::Helpers::byteOffset ( const BufferDescriptor & d,
std::span< const int64_t > index )
nodiscardconstexpr

Byte offset from a descriptor's base address of the element at the given index.

Parameters
[in]dis the descriptor to query.
[in]indexis the multi-dimensional element index; its length must equal d.rank.
Here is the call graph for this function:

◆ contiguousByteSize()

int64_t HydroCouple::Helpers::contiguousByteSize ( const BufferDescriptor & d)
nodiscardconstexpr

Total byte extent of a C-contiguous buffer of the descriptor's shape and kind.

Parameters
[in]dis the descriptor to query.
Here is the call graph for this function:

◆ dataKindSize()

int64_t HydroCouple::Helpers::dataKindSize ( DataKind kind)
constexpr

Size in bytes of one element of the given DataKind.

Parameters
[in]kindis the element kind to query.
Returns
The element size in bytes; 0 for String, Opaque, and Unknown.
Here is the caller graph for this function:

◆ elementCount()

int64_t HydroCouple::Helpers::elementCount ( const BufferDescriptor & d)
nodiscardconstexpr

Number of elements a BufferDescriptor describes (product of shape; 1 for rank 0).

Parameters
[in]dis the descriptor to query.
Here is the caller graph for this function:

◆ getValue()

template<typename T>
bool HydroCouple::Helpers::getValue ( const IComponentDataItem & item,
T & value,
std::span< const int64_t > index )
nodiscard

Typed convenience: reads the single element at the given index of a data item.

Template Parameters
Tis the C++ element type; DataKindOf<T>::kind must equal item.dataKind().
Parameters
[in]itemis the data item to read from.
[out]valuereceives the element.
[in]indexis the full multi-dimensional element index.
Returns
True on success.
Here is the call graph for this function:

◆ getValues()

template<typename T>
bool HydroCouple::Helpers::getValues ( const IComponentDataItem & item,
std::span< T > destination,
std::span< const int64_t > start,
std::span< const int64_t > count )
nodiscard

Typed convenience: reads a hyperslab into a flat contiguous span in C order.

Template Parameters
Tis the C++ element type; DataKindOf<T>::kind must equal item.dataKind().
Parameters
[in]itemis the data item to read from.
[out]destinationreceives the selection; its size must equal the product of count.
[in]startis the first index of the selection in each dimension.
[in]countis the selection extent in each dimension.
Returns
True on success.
Here is the call graph for this function:

◆ isContiguous()

bool HydroCouple::Helpers::isContiguous ( const BufferDescriptor & d)
nodiscardconstexpr

Checks whether a BufferDescriptor's layout is C-contiguous (row-major, packed).

Parameters
[in]dis the descriptor to query.
Here is the call graph for this function:

◆ isValidComponentStatusTransition()

bool HydroCouple::Helpers::isValidComponentStatusTransition ( IModelComponent::ComponentStatus from,
IModelComponent::ComponentStatus to )
nodiscardconstexpr

Encodes the normative component lifecycle state machine.

Implementations must not perform status transitions for which this function returns false.

Parameters
[in]fromis the current status.
[in]tois the proposed next status.
Returns
True if the transition is legal.

◆ makeContiguous()

BufferDescriptor HydroCouple::Helpers::makeContiguous ( void * data,
DataKind kind,
std::span< const int64_t > shape )
nodiscardconstexpr

Builds a C-contiguous host BufferDescriptor.

Parameters
[in]datais the base address of the buffer.
[in]kindis the element type.
[in]shapeis the extent per dimension; the pointed-to array must outlive the descriptor.
Here is the caller graph for this function:

◆ setValue()

template<typename T>
bool HydroCouple::Helpers::setValue ( IComponentDataItem & item,
const T & value,
std::span< const int64_t > index )
nodiscard

Typed convenience: writes the single element at the given index of a data item.

Template Parameters
Tis the C++ element type; DataKindOf<T>::kind must equal item.dataKind().
Parameters
[in]itemis the data item to write to.
[in]valueis the element to write.
[in]indexis the full multi-dimensional element index.
Returns
True on success.
Here is the call graph for this function:

◆ setValues()

template<typename T>
bool HydroCouple::Helpers::setValues ( IComponentDataItem & item,
std::span< const T > source,
std::span< const int64_t > start,
std::span< const int64_t > count )
nodiscard

Typed convenience: writes a hyperslab from a flat contiguous span in C order.

Template Parameters
Tis the C++ element type; DataKindOf<T>::kind must equal item.dataKind().
Parameters
[in]itemis the data item to write to.
[in]sourceprovides the selection; its size must equal the product of count.
[in]startis the first index of the selection in each dimension.
[in]countis the selection extent in each dimension.
Returns
True on success.
Here is the call graph for this function: