IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::protocol::internal::BinaryData< NBytes, N > Struct Template Reference

Represents a binary data object within the protocol. More...

#include <binary.hpp>

Public Member Functions

 IRSOL_STATIC_ASSERT ((NBytes==1||NBytes==2), "Binary data element byte size must be 1 or 2")
 
 IRSOL_STATIC_ASSERT (N >=1, "Binary data dimensionality must be at least 1")
 
 BinaryData (std::vector< irsol::types::byte_t > &&data, const std::array< uint64_t, N > &shape, std::vector< BinaryDataAttribute > &&attributes={})
 Constructs a BinaryData object.
 
 BinaryData (BinaryData &&other)=default
 Move constructs a BinaryData object.
 
 BinaryData (const BinaryData &)=delete
 
BinaryDataoperator= (const BinaryData &)=delete
 
BinaryDataoperator= (BinaryData &&other) noexcept=delete
 
std::string toString () const
 Returns a string summary of the binary data buffer.
 

Public Attributes

std::vector< irsol::types::byte_tdata
 Owned binary data bytes.
 
std::array< uint64_t, DIMshape
 Shape of the binary data.
 
uint64_t numElements
 Total number of elements in the data.
 
uint64_t numBytes
 Total number of bytes (numElements * bytes per element).
 
std::vector< BinaryDataAttributeattributes
 Additional attributes related to the binary data.
 

Static Public Attributes

static constexpr uint8_t BYTES_PER_ELEMENT = NBytes
 Number of bytes per element.
 
static constexpr uint8_t DIM = N
 Dimensionality of the binary data.
 

Detailed Description

template<std::uint8_t NBytes, std::uint8_t N>
struct irsol::protocol::internal::BinaryData< NBytes, N >

Represents a binary data object within the protocol.

This class owns a contiguous block of binary data elements and their shape, along with optional additional attributes. It supports only move semantics to avoid unnecessary copies of potentially large data buffers.

Template Parameters
NBytesNumber of bytes per element (e.g., 1 for 8-bit data, 2 for 16-bit).
NDimensionality of the binary data (e.g., 2 for images).
Note
Copy construction and assignment are disabled to prevent expensive copies. Move semantics are supported to allow ownership transfer. Members are non-const to facilitate move operations.

Definition at line 106 of file binary.hpp.

Constructor & Destructor Documentation

◆ BinaryData() [1/3]

template<std::uint8_t NBytes, std::uint8_t N>
irsol::protocol::internal::BinaryData< NBytes, N >::BinaryData ( std::vector< irsol::types::byte_t > &&  data,
const std::array< uint64_t, N > &  shape,
std::vector< BinaryDataAttribute > &&  attributes = {} 
)
inline

Constructs a BinaryData object.

Parameters
dataRvalue reference to the binary data bytes; ownership is transferred.
shapeShape of the data as an array of size N.
attributesOptional additional attributes; ownership is transferred.
Exceptions
irsol::AssertExceptionif the data size does not match shape * bytes per element.

Definition at line 125 of file binary.hpp.

128 {})
129 : data(std::move(data))
130 , shape(shape)
131 , numElements(std::accumulate(shape.begin(), shape.end(), 1ull, std::multiplies<>{}))
133 , attributes(std::move(attributes))
134 {
135 IRSOL_LOG_TRACE("BinaryData constructed: {}", toString());
137 this->data.size() == this->numBytes,
138 "Data size (%lu) does not match the number of elements (%lu) multiplied by bytes per element "
139 "(%d).",
140 this->data.size(),
141 this->numElements,
142 this->BYTES_PER_ELEMENT);
143 }
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134
#define IRSOL_LOG_TRACE(...)
Logs a trace-level message using the default logger.
Definition logging.hpp:90
std::vector< BinaryDataAttribute > attributes
Additional attributes related to the binary data.
Definition binary.hpp:171
std::vector< irsol::types::byte_t > data
Owned binary data bytes.
Definition binary.hpp:159
std::array< uint64_t, DIM > shape
Shape of the binary data.
Definition binary.hpp:162
static constexpr uint8_t BYTES_PER_ELEMENT
Number of bytes per element.
Definition binary.hpp:112
std::string toString() const
Returns a string summary of the binary data buffer.
Definition binary.hpp:177
uint64_t numElements
Total number of elements in the data.
Definition binary.hpp:165
uint64_t numBytes
Total number of bytes (numElements * bytes per element).
Definition binary.hpp:168

◆ BinaryData() [2/3]

template<std::uint8_t NBytes, std::uint8_t N>
irsol::protocol::internal::BinaryData< NBytes, N >::BinaryData ( BinaryData< NBytes, N > &&  other)
default

Move constructs a BinaryData object.

Parameters
otherThe object to move from.

◆ BinaryData() [3/3]

template<std::uint8_t NBytes, std::uint8_t N>
irsol::protocol::internal::BinaryData< NBytes, N >::BinaryData ( const BinaryData< NBytes, N > &  )
delete

Member Function Documentation

◆ IRSOL_STATIC_ASSERT() [1/2]

template<std::uint8_t NBytes, std::uint8_t N>
irsol::protocol::internal::BinaryData< NBytes, N >::IRSOL_STATIC_ASSERT ( (NBytes==1||NBytes==2)  ,
"Binary data element byte size must be 1 or 2"   
)

◆ IRSOL_STATIC_ASSERT() [2/2]

template<std::uint8_t NBytes, std::uint8_t N>
irsol::protocol::internal::BinaryData< NBytes, N >::IRSOL_STATIC_ASSERT ( N >=  1,
"Binary data dimensionality must be at least 1"   
)

◆ operator=() [1/2]

template<std::uint8_t NBytes, std::uint8_t N>
BinaryData & irsol::protocol::internal::BinaryData< NBytes, N >::operator= ( BinaryData< NBytes, N > &&  other)
deletenoexcept

◆ operator=() [2/2]

template<std::uint8_t NBytes, std::uint8_t N>
BinaryData & irsol::protocol::internal::BinaryData< NBytes, N >::operator= ( const BinaryData< NBytes, N > &  )
delete

◆ toString()

template<std::uint8_t NBytes, std::uint8_t N>
std::string irsol::protocol::internal::BinaryData< NBytes, N >::toString ( ) const
inline

Returns a string summary of the binary data buffer.

Returns
A string describing dimensionality, shape, and size in bytes.

Definition at line 177 of file binary.hpp.

178 {
179 std::stringstream ss;
180 ss << BinaryDataBufferName<N>::name() << "u" << (BYTES_PER_ELEMENT == 1 ? "8" : "16")
181 << "[shape=(" << std::to_string(shape[0]);
182 for(uint8_t i = 1; i < DIM; ++i) {
183 ss << "x" << std::to_string(shape[i]);
184 }
185 ss << ")](" << std::to_string(numBytes) << " bytes)";
186 return ss.str();
187 }
static constexpr uint8_t DIM
Dimensionality of the binary data.
Definition binary.hpp:115

Member Data Documentation

◆ attributes

template<std::uint8_t NBytes, std::uint8_t N>
std::vector<BinaryDataAttribute> irsol::protocol::internal::BinaryData< NBytes, N >::attributes

Additional attributes related to the binary data.

Definition at line 171 of file binary.hpp.

◆ BYTES_PER_ELEMENT

template<std::uint8_t NBytes, std::uint8_t N>
constexpr uint8_t irsol::protocol::internal::BinaryData< NBytes, N >::BYTES_PER_ELEMENT = NBytes
staticconstexpr

Number of bytes per element.

Definition at line 112 of file binary.hpp.

◆ data

template<std::uint8_t NBytes, std::uint8_t N>
std::vector<irsol::types::byte_t> irsol::protocol::internal::BinaryData< NBytes, N >::data

Owned binary data bytes.

Definition at line 159 of file binary.hpp.

◆ DIM

template<std::uint8_t NBytes, std::uint8_t N>
constexpr uint8_t irsol::protocol::internal::BinaryData< NBytes, N >::DIM = N
staticconstexpr

Dimensionality of the binary data.

Definition at line 115 of file binary.hpp.

◆ numBytes

template<std::uint8_t NBytes, std::uint8_t N>
uint64_t irsol::protocol::internal::BinaryData< NBytes, N >::numBytes

Total number of bytes (numElements * bytes per element).

Definition at line 168 of file binary.hpp.

◆ numElements

template<std::uint8_t NBytes, std::uint8_t N>
uint64_t irsol::protocol::internal::BinaryData< NBytes, N >::numElements

Total number of elements in the data.

Definition at line 165 of file binary.hpp.

◆ shape

template<std::uint8_t NBytes, std::uint8_t N>
std::array<uint64_t, DIM> irsol::protocol::internal::BinaryData< NBytes, N >::shape

Shape of the binary data.

Definition at line 162 of file binary.hpp.


The documentation for this struct was generated from the following file: