62 throw std::runtime_error(
"Allocation of UniRec record failed");
69 throw std::runtime_error(
70 "UnirecRecord::copyFieldsFrom() has failed. Record has no template or allocated "
88 throw std::runtime_error(
89 "UnirecRecord::copyFieldsFrom() has failed. Record has no template or allocated "
157 using BaseType =
typename std::remove_cv_t<
158 typename std::remove_pointer_t<typename std::remove_reference_t<T>>>;
160 checkDataTypeCompatibility<T>(fieldID);
162 if constexpr (is_string_v<T>) {
163 return getFieldAsStringType<T>(fieldID);
164 }
else if constexpr (std::is_pointer_v<T>) {
165 return getFieldAsPointer<T>(fieldID);
166 }
else if constexpr (std::is_reference_v<T>) {
167 return getFieldAsReference<BaseType>(fieldID);
169 return getFieldAsValue<T>(fieldID);
226 if (retCode !=
UR_OK) {
227 throw std::runtime_error(
"Unable to allocate memory for UnirecArray");
253 if constexpr (is_string_v<T>) {
272 checkDataTypeCompatibility<T>(fieldID);
281 setFieldFromType<T>(unirecArray.
at(0), fieldID);
289 if (&other ==
this) {
317 checkDataTypeCompatibility<T>(fieldID);
320 throw std::runtime_error(
"Cannot set vector to non-array unirec field");
325 sourceVector.begin(),
334 using BaseType =
typename std::remove_cv_t<
335 typename std::remove_pointer_t<typename std::remove_reference_t<T>>>;
336 using RequiredType =
typename std::conditional_t<is_string_v<BaseType>, T, BaseType>;
340 expectedType = getExpectedUnirecType<RequiredType*>();
342 expectedType = getExpectedUnirecType<RequiredType>();
346 throw std::runtime_error(
347 "UnirecRecord data type format mismatch: " + std::string(
typeid(T).name()));
385 throw std::runtime_error(
"Allocation of UniRec record failed");
A wrapper class for a contiguous array of values with the same unirec fieldID.
constexpr Iterator begin() const noexcept
Returns an iterator to the first element of the UniRec field array.
constexpr Iterator end() const noexcept
Returns an iterator to the element following the last element of the UniRec field array.
constexpr size_t size() const noexcept
Returns the number of elements in the UniRec field array.
constexpr T & at(size_t pos) const
Returns a reference to the element at the specified position in the UniRec field array,...
Provides a view into a UniRec record.
ur_template_t * m_unirecTemplate
const void * m_recordData
A class for working with UniRec records and their fields.
UnirecArray< T > getFieldAsUnirecArray(ur_field_id_t fieldID)
Gets a UniRecArray representing a UniRec field.
T getFieldAsType(ur_field_id_t fieldID) const
Gets the value of a UniRec field and converts it to the specified type.
T getFieldAsPointer(ur_field_id_t fieldID) const
~UnirecRecord()
Destructor.
void checkDataTypeCompatibility(ur_field_id_t fieldID) const
UnirecArray< T > reserveUnirecArray(size_t elementsCount, ur_field_id_t fieldID)
Reserves memory for a UniRecArray within a UniRec field.
void setFieldFromUnirecArray(const UnirecArray< T > &unirecArray, ur_field_id_t fieldID)
Sets the value of a UniRec field using a UnirecArray.
void copyFieldsFrom(const UnirecRecord &otherRecord)
T getFieldAsReference(ur_field_id_t fieldID) const
void setFieldFromType(const T &fieldData, ur_field_id_t fieldID)
Sets the value of a UniRec field using data of a specified type.
ur_template_t * m_unirecTemplate
UnirecRecord(ur_template_t *unirecTemplate, size_t maxVariableFieldsSize=UR_MAX_SIZE)
Constructor with template and maximum variable fields size.
const void * data() const noexcept
Returns a pointer to the data of the UniRec record.
void copyFrom(const UnirecRecord &other)
UnirecRecord()
Default constructor.
T getFieldAsValue(ur_field_id_t fieldID) const
UnirecRecord(const UnirecRecord &other)
UnirecRecord & operator=(const UnirecRecord &other)
size_t size() const noexcept
Returns the size of the UniRec record.
T getFieldAsStringType(ur_field_id_t fieldID) const
void setFieldFromVector(const std::vector< T > &sourceVector, ur_field_id_t fieldID)
Sets the value of a UniRec array field using a vector of values.
void copyFieldsFrom(const UnirecRecordView &otherRecordView)
#define ur_set_string(tmplt, rec, field_id, str)
Set variable-length field to given string. Set contents of a variable-length field in the record....
#define ur_array_allocate(tmplt, rec, field_id, elem_cnt)
Preallocates UniRec array field to have requested number of elements.
#define ur_is_array(field_id)
#define ur_rec_size(tmplt, rec)
Get size of UniRec record (static and variable length) Get total size of whole UniRec record.
void * ur_create_record(const ur_template_t *tmplt, uint16_t max_var_size)
#define ur_get_var_len(tmplt, rec, field_id)
Get size of a variable sized field in the record. Get size of a variable-length field in the record....
#define ur_array_get_elem_cnt(tmplt, rec, field_id)
Get number of elements stored in an UniRec array.
void ur_copy_fields(const ur_template_t *dst_tmplt, void *dst, const ur_template_t *src_tmplt, const void *src)
Copy data from one UniRec record to another. Copies all fields present in both templates from src to ...
#define ur_get_type(field_id)
Get type of UniRec field Get type of any UniRec defined field.
void ur_free_record(void *record)
#define ur_get_ptr_by_id(tmplt, data, field_id)
Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_ge...
Header file containing the definition of the UnirecArray class and its Iterator subclass.
Provides a view into a UniRec record.
Provides a set of type traits and aliases for working with unirec++.
This file contains functions for determining the expected UniRec type for various C++ types.
Definition of UniRec structures and functions.
int16_t ur_field_id_t
Type of UniRec field identifiers.
UniRec template. It contains a table mapping a field to its position in an UniRec record.