UniRec 3.0.0
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
NemeaPlusPlus::UnirecRecord Class Reference

A class for working with UniRec records and their fields. More...

#include <unirecRecord.hpp>

Public Member Functions

 UnirecRecord ()
 Default constructor.
 
 UnirecRecord (ur_template_t *unirecTemplate, size_t maxVariableFieldsSize=UR_MAX_SIZE)
 Constructor with template and maximum variable fields size.
 
void copyFieldsFrom (const UnirecRecord &otherRecord)
 
void copyFieldsFrom (const UnirecRecordView &otherRecordView)
 
 ~UnirecRecord ()
 Destructor.
 
const void * data () const noexcept
 Returns a pointer to the data of the UniRec record.
 
size_t size () const noexcept
 Returns the size of the UniRec record.
 
template<typename T >
getFieldAsType (ur_field_id_t fieldID) const
 Gets the value of a UniRec field and converts it to the specified type.
 
template<typename T >
UnirecArray< T > getFieldAsUnirecArray (ur_field_id_t fieldID)
 Gets a UniRecArray representing a UniRec field.
 
template<typename T >
UnirecArray< T > reserveUnirecArray (size_t elementsCount, ur_field_id_t fieldID)
 Reserves memory for a UniRecArray within a UniRec field.
 
template<typename T >
void setFieldFromType (const T &fieldData, ur_field_id_t fieldID)
 Sets the value of a UniRec field using data of a specified type.
 
template<typename T >
void setFieldFromUnirecArray (const UnirecArray< T > &unirecArray, ur_field_id_t fieldID)
 Sets the value of a UniRec field using a UnirecArray.
 
 UnirecRecord (const UnirecRecord &other)
 
UnirecRecordoperator= (const UnirecRecord &other)
 
template<typename T >
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.
 

Private Member Functions

template<typename T >
void checkDataTypeCompatibility (ur_field_id_t fieldID) const
 
template<typename T >
getFieldAsStringType (ur_field_id_t fieldID) const
 
template<typename T >
getFieldAsPointer (ur_field_id_t fieldID) const
 
template<typename T >
getFieldAsReference (ur_field_id_t fieldID) const
 
template<typename T >
getFieldAsValue (ur_field_id_t fieldID) const
 
void copyFrom (const UnirecRecord &other)
 

Private Attributes

size_t m_recordSize
 
void * m_recordData
 
ur_template_tm_unirecTemplate
 

Detailed Description

A class for working with UniRec records and their fields.

The UnirecRecord class facilitates the manipulation of UniRec records and their individual fields. It provides functions to access, set, and transform data within the UniRec record.

Definition at line 33 of file unirecRecord.hpp.

Constructor & Destructor Documentation

◆ UnirecRecord() [1/3]

NemeaPlusPlus::UnirecRecord::UnirecRecord ( )
inline

Default constructor.

Constructs an uninitialized UnirecRecord object.

Definition at line 40 of file unirecRecord.hpp.

◆ UnirecRecord() [2/3]

NemeaPlusPlus::UnirecRecord::UnirecRecord ( ur_template_t unirecTemplate,
size_t  maxVariableFieldsSize = UR_MAX_SIZE 
)
inline

Constructor with template and maximum variable fields size.

Constructs a UnirecRecord object with a specified UniRec template and maximum size for variable fields.

Parameters
unirecTemplateThe UniRec template to associate with the record.
maxVariableFieldsSizeThe maximum size for variable fields in the record.

Definition at line 56 of file unirecRecord.hpp.

◆ ~UnirecRecord()

NemeaPlusPlus::UnirecRecord::~UnirecRecord ( )
inline

Destructor.

Frees the memory associated with the UniRec record.

Definition at line 110 of file unirecRecord.hpp.

◆ UnirecRecord() [3/3]

NemeaPlusPlus::UnirecRecord::UnirecRecord ( const UnirecRecord other)
inline

Definition at line 285 of file unirecRecord.hpp.

Member Function Documentation

◆ checkDataTypeCompatibility()

template<typename T >
void NemeaPlusPlus::UnirecRecord::checkDataTypeCompatibility ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 332 of file unirecRecord.hpp.

◆ copyFieldsFrom() [1/2]

void NemeaPlusPlus::UnirecRecord::copyFieldsFrom ( const UnirecRecord otherRecord)
inline

Definition at line 66 of file unirecRecord.hpp.

◆ copyFieldsFrom() [2/2]

void NemeaPlusPlus::UnirecRecord::copyFieldsFrom ( const UnirecRecordView otherRecordView)
inline

Definition at line 85 of file unirecRecord.hpp.

◆ copyFrom()

void NemeaPlusPlus::UnirecRecord::copyFrom ( const UnirecRecord other)
inlineprivate

Definition at line 377 of file unirecRecord.hpp.

◆ data()

const void * NemeaPlusPlus::UnirecRecord::data ( ) const
inlinenoexcept

Returns a pointer to the data of the UniRec record.

Returns
A pointer to the data of the UniRec record.

Definition at line 117 of file unirecRecord.hpp.

◆ getFieldAsPointer()

template<typename T >
T NemeaPlusPlus::UnirecRecord::getFieldAsPointer ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 360 of file unirecRecord.hpp.

◆ getFieldAsReference()

template<typename T >
T NemeaPlusPlus::UnirecRecord::getFieldAsReference ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 366 of file unirecRecord.hpp.

◆ getFieldAsStringType()

template<typename T >
T NemeaPlusPlus::UnirecRecord::getFieldAsStringType ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 352 of file unirecRecord.hpp.

◆ getFieldAsType()

template<typename T >
T NemeaPlusPlus::UnirecRecord::getFieldAsType ( ur_field_id_t  fieldID) const
inline

Gets the value of a UniRec field and converts it to the specified type.

This function retrieves the value of a UniRec field, converts it to the specified type, and returns the result.

Template Parameters
TThe type to which the field value should be converted.
Parameters
fieldIDThe ID of the UniRec field.
Returns
The value of the field, converted to the specified type.
Exceptions
std::runtime_errorIf there is a data type format mismatch or other error.
// memory allocation in std::string
std::string stringValue = urRecord.getFieldAsType<std::string>(fieldID);
// no memory allocation
std::string_view stringValue = urRecord.getFieldAsType<std::string_view>(fieldID);
// Get pointer to unirec field value
int* intValuePtr = urRecord.getFieldAsType<int*>(fieldID);
// Get reference to unirec field value
int& intValueRef = urRecord.getFieldAsType<int&>(fieldID);
// Get value of unirec field
int intValue = urRecord.getFieldAsType<int>(fieldID);

Definition at line 155 of file unirecRecord.hpp.

◆ getFieldAsUnirecArray()

template<typename T >
UnirecArray< T > NemeaPlusPlus::UnirecRecord::getFieldAsUnirecArray ( ur_field_id_t  fieldID)
inline

Gets a UniRecArray representing a UniRec field.

This function returns a UnirecArray object representing a UniRec field that holds an array of values.

Template Parameters
TThe type of elements in the array.
Parameters
fieldIDThe ID of the UniRec field.
Returns
A UnirecArray representing the UniRec field.
// Get array of int values as UnirecArray
UnirecArray<int> array = urRecord.getFieldAsUnirecArray<int>(fieldID);
A wrapper class for a contiguous array of values with the same unirec fieldID.
Definition: unirecArray.hpp:30

Definition at line 189 of file unirecRecord.hpp.

◆ getFieldAsValue()

template<typename T >
T NemeaPlusPlus::UnirecRecord::getFieldAsValue ( ur_field_id_t  fieldID) const
inlineprivate

Definition at line 372 of file unirecRecord.hpp.

◆ operator=()

UnirecRecord & NemeaPlusPlus::UnirecRecord::operator= ( const UnirecRecord other)
inline

Definition at line 287 of file unirecRecord.hpp.

◆ reserveUnirecArray()

template<typename T >
UnirecArray< T > NemeaPlusPlus::UnirecRecord::reserveUnirecArray ( size_t  elementsCount,
ur_field_id_t  fieldID 
)
inline

Reserves memory for a UniRecArray within a UniRec field.

This function allocates memory for a UniRecArray within a UniRec field and returns a UnirecArray object that can be used to populate the field.

Template Parameters
TThe type of elements in the array.
Parameters
elementsCountThe number of elements to allocate space for.
fieldIDThe ID of the UniRec field.
Returns
A UnirecArray object for populating the UniRec field.
Exceptions
std::runtime_errorIf memory allocation fails or other errors occur.
// Create a UnirecRecord with a template
UnirecRecord urRecord(urTemplate);
// Reserve memory for a UnirecArray of integers with 10 elements in field with ID 'fieldID'
UnirecArray<int> intArray = urRecord.reserveUnirecArray<int>(10, fieldID);
// Populate the array with values (directly modifying the Unirec record data)
for (int i = 0; i < 10; ++i) {
intArray.at(i) = i * 2;
}
constexpr T & at(size_t pos) const
Returns a reference to the element at the specified position in the UniRec field array,...
A class for working with UniRec records and their fields.

Definition at line 223 of file unirecRecord.hpp.

◆ setFieldFromType()

template<typename T >
void NemeaPlusPlus::UnirecRecord::setFieldFromType ( const T &  fieldData,
ur_field_id_t  fieldID 
)
inline

Sets the value of a UniRec field using data of a specified type.

This function sets the value of a UniRec field using the provided data of a specified type.

Template Parameters
TThe type of the field data.
Parameters
fieldDataThe data to set the field to.
fieldIDThe ID of the UniRec field.
// set string value to unirec field with ID 'stringFieldID'
urRecord.setFieldFromType("example string", stringFieldID);

Definition at line 251 of file unirecRecord.hpp.

◆ setFieldFromUnirecArray()

template<typename T >
void NemeaPlusPlus::UnirecRecord::setFieldFromUnirecArray ( const UnirecArray< T > &  unirecArray,
ur_field_id_t  fieldID 
)
inline

Sets the value of a UniRec field using a UnirecArray.

This function sets the value of a UniRec field in Unirec record using a UnirecArray.

Template Parameters
TThe type of elements in the UnirecArray.
Parameters
unirecArrayThe UnirecArray to set the field to.
fieldIDThe ID of the UniRec field.

Definition at line 270 of file unirecRecord.hpp.

◆ setFieldFromVector()

template<typename T >
void NemeaPlusPlus::UnirecRecord::setFieldFromVector ( const std::vector< T > &  sourceVector,
ur_field_id_t  fieldID 
)
inline

Sets the value of a UniRec array field using a vector of values.

Template Parameters
TThe type of elements in the vector (and unirec record).
Parameters
sourceVectorThe vector of values to set the field to.
fieldIDThe ID of the UniRec field.
std::vector<int> intVector = {1, 2, 3, 4, 5};
urRecord.setFieldFromVector<int>(intVector, fieldID);

Definition at line 315 of file unirecRecord.hpp.

◆ size()

size_t NemeaPlusPlus::UnirecRecord::size ( ) const
inlinenoexcept

Returns the size of the UniRec record.

Returns
The size of the UniRec record.

Definition at line 124 of file unirecRecord.hpp.

Field Documentation

◆ m_recordData

void* NemeaPlusPlus::UnirecRecord::m_recordData
private

Definition at line 392 of file unirecRecord.hpp.

◆ m_recordSize

size_t NemeaPlusPlus::UnirecRecord::m_recordSize
private

Definition at line 390 of file unirecRecord.hpp.

◆ m_unirecTemplate

ur_template_t* NemeaPlusPlus::UnirecRecord::m_unirecTemplate
private

Definition at line 393 of file unirecRecord.hpp.


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