Loading...
Searching...
No Matches
HydroCouple::Helpers Namespace Reference

Convenience helpers for the HydroCouple interface standard; non-normative except for the two lifecycle transition tables. More...

Namespaces

namespace  Detail
 

Classes

struct  DataKindOf
 DataKindOf maps a C++ type to its DataKind at compile time. More...
 

Functions

constexpr int64_t dataKindSize (DataKind kind)
 Size in bytes of one element of the given DataKind.
 
constexpr int64_t itemSize (const BufferDescriptor &d)
 Size in bytes of one element of a descriptor: its itemSizeBytes when set, otherwise the kind's natural size (0 for an Opaque descriptor that failed to set it, which every consumer must treat as an error).
 
constexpr bool hasValidItemSize (const BufferDescriptor &d)
 Checks that a descriptor's element size is consistent with its kind.
 
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 BufferDescriptor makeOpaqueContiguous (void *data, int64_t itemSizeBytes, std::span< const int64_t > shape)
 Builds a C-contiguous host BufferDescriptor over opaque elements.
 
constexpr bool isValidComponentStatusTransition (IModelComponent::ComponentStatus from, IModelComponent::ComponentStatus to)
 Encodes the normative component lifecycle state machine.
 
constexpr bool isValidWorkflowStatusTransition (IWorkflowComponent::WorkflowStatus from, IWorkflowComponent::WorkflowStatus to)
 Encodes the normative workflow 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

Convenience helpers for the HydroCouple interface standard; non-normative except for the two lifecycle transition tables.

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:

◆ hasValidItemSize()

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

Checks that a descriptor's element size is consistent with its kind.

True when itemSizeBytes is 0 or equals the kind's natural size for fixed-size kinds; when itemSizeBytes > 0 for Opaque; when itemSizeBytes is sizeof(std::string) or 0 for String.

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.

Normative (the exception in this header): 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.

◆ isValidWorkflowStatusTransition()

bool HydroCouple::Helpers::isValidWorkflowStatusTransition ( IWorkflowComponent::WorkflowStatus from,
IWorkflowComponent::WorkflowStatus to )
nodiscardconstexpr

Encodes the normative workflow lifecycle state machine.

Normative (the exception in this header): 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.

◆ itemSize()

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

Size in bytes of one element of a descriptor: its itemSizeBytes when set, otherwise the kind's natural size (0 for an Opaque descriptor that failed to set it, which every consumer must treat as an error).

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

◆ 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 call graph for this function:
Here is the caller graph for this function:

◆ makeOpaqueContiguous()

BufferDescriptor HydroCouple::Helpers::makeOpaqueContiguous ( void * data,
int64_t itemSizeBytes,
std::span< const int64_t > shape )
nodiscardconstexpr

Builds a C-contiguous host BufferDescriptor over opaque elements.

Parameters
[in]datais the base address of the buffer.
[in]itemSizeBytesis the size of one element; must be positive.
[in]shapeis the extent per dimension; the pointed-to array must outlive the descriptor.

◆ 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: