21 #include <type_traits> 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");
#define ur_get_type(field_id)
Get type of UniRec field Get type of any UniRec defined field.
UnirecArray< T > reserveUnirecArray(size_t elementsCount, ur_field_id_t fieldID)
Reserves memory for a UniRecArray within a UniRec field.
UnirecRecord & operator=(const UnirecRecord &other)
T getFieldAsValue(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 setFieldFromUnirecArray(const UnirecArray< T > &unirecArray, ur_field_id_t fieldID)
Sets the value of a UniRec field using a UnirecArray.
void checkDataTypeCompatibility(ur_field_id_t fieldID) const
#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...
A wrapper class for a contiguous array of values with the same unirec fieldID.
void copyFieldsFrom(const UnirecRecord &otherRecord)
#define ur_is_array(field_id)
T getFieldAsReference(ur_field_id_t fieldID) const
ur_template_t * m_unirecTemplate
#define ur_rec_size(tmplt, rec)
Get size of UniRec record (static and variable length) Get total size of whole UniRec record...
ur_template_t * m_unirecTemplate
A class for working with UniRec records and their fields.
void copyFieldsFrom(const UnirecRecordView &otherRecordView)
#define ur_array_allocate(tmplt, rec, field_id, elem_cnt)
Preallocates UniRec array field to have requested number of elements.
Provides a set of type traits and aliases for working with unirec++.
const void * m_recordData
Provides a view into a UniRec record.
void * ur_create_record(const ur_template_t *tmplt, uint16_t max_var_size)
UnirecRecord()
Default constructor.
UnirecRecord(ur_template_t *unirecTemplate, size_t maxVariableFieldsSize=UR_MAX_SIZE)
Constructor with template and maximum variable fields 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...
constexpr size_t size() const noexcept
Returns the number of elements in the UniRec field array.
void ur_free_record(void *record)
int16_t ur_field_id_t
Type of UniRec field identifiers.
const void * data() const noexcept
Returns a pointer to the data of the UniRec record.
Definition of UniRec structures and functions.
#define ur_array_get_elem_cnt(tmplt, rec, field_id)
Get number of elements stored in an UniRec array.
constexpr Iterator begin() const noexcept
Returns an iterator to the first element of the UniRec field array.
#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...
T getFieldAsPointer(ur_field_id_t fieldID) const
UnirecRecord(const UnirecRecord &other)
T getFieldAsType(ur_field_id_t fieldID) const
Gets the value of a UniRec field and converts it to the specified type.
T getFieldAsStringType(ur_field_id_t fieldID) const
This file contains functions for determining the expected UniRec type for various C++ types...
void copyFrom(const UnirecRecord &other)
Provides a view into a UniRec record.
~UnirecRecord()
Destructor.
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 ...
constexpr T & at(size_t pos) const
Returns a reference to the element at the specified position in the UniRec field array, with bounds checking.
void setFieldFromType(const T &fieldData, ur_field_id_t fieldID)
Sets the value of a UniRec field using data of a specified type.
UniRec template. It contains a table mapping a field to its position in an UniRec record...
constexpr Iterator end() const noexcept
Returns an iterator to the element following the last element of the UniRec field array...
UnirecArray< T > getFieldAsUnirecArray(ur_field_id_t fieldID)
Gets a UniRecArray representing a UniRec field.
size_t size() const noexcept
Returns the size of the UniRec record.
Header file containing the definition of the UnirecArray class and its Iterator subclass.