ADTF  3.18.2
sample_data< T, Enable >

Easy data access for input samples of non trivial type @T (see Supported types for adtf_memory<T> for writing and reading Samples). More...

Public Member Functions

 sample_data ()
 CTOR.
 
 sample_data (const sample_data &oSampleData)
 CTOR.
 
 sample_data (sample_data &&oSampleData)
 move CTOR More...
 
 sample_data (const ucom::iobject_ptr< const ant::ISample > &pSample)
 copy CTOR More...
 
 sample_data (const ucom::iobject_ptr< const flash::ISample > &pSample)
 
tTimeStamp GetTime () const
 retrieves the timestamp of the data. More...
 
adtf::base::flash::tNanoSeconds GetTimeNs () const
 retrieves the timestamp of the data. More...
 
const T * GetDataPtr () const
 Retrieves the pointer to the datas memory. More...
 
size_t GetDataSize () const
 
const T * operator-> ()
 Retrieves the pointer to the datas memory. More...
 
const T * operator-> () const
 Retrieves the pointer to the datas memory. More...
 
const T & GetData () const
 Retrieves a reference to the data. More...
 
const T & operator* () const
 Retrieves a reference to the data. More...
 
bool IsValid () const
 Validate if sample and sample buffer is set. More...
 
 operator const T & () const
 Return the content of sample buffer as a reference to the extracted non trivial value. More...
 
tResult Reset (const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
 Resets the sample the sample data reference to with a new reference to a sample. More...
 
tResult Reset ()
 Resets the sample the sample data reference to. More...
 
adtf_util::cVariant GetSampleInfo (const ISampleInfo::tHashKey &oHash, const adtf::util::cVariant oDefault=adtf::util::cVariant()) const
 Retrieves a variant value for the hash key oHash out of the samples sample information . More...
 

Private Attributes

ucom::object_ptr< const ant::ISamplem_pCurrentSample
 
ucom::object_ptr_shared_locked< const ISampleBufferm_pBuffer
 
m_oExtractedValue = {}
 

Detailed Description

template<typename T, typename Enable = void>
class adtf::streaming::penguin::sample_data< T, Enable >

Easy data access for input samples of non trivial type @T (see Supported types for adtf_memory<T> for writing and reading Samples).

This sample_data is for non-trivial types, where a specialization of adtf::base::adtf_memory for type T exists.

Example Usage

{
LOG_INFO("sample value = %u", *adtf::streaming::sample_data<uint32_t>(pSample));
}
void process_sample_array(const adtf::ucom::iobject_ptr<const adtf::streaming::ISample>& pSample)
{
LOG_INFO("sample value[4] = %u", adtf::streaming::sample_data<std::array<uint32_t, 5>>(pSample).GetData()[4]);
}
void process_sample_vector(const adtf::ucom::iobject_ptr<const adtf::streaming::ISample>& pSample)
{
if (sample_data_vector.GetData().size() > 4)
{
LOG_INFO("sample value[4] = %u", adtf::streaming::sample_data<std::vector<uint32_t>>(pSample).GetData()[4]);
}
}
Copyright © Audi Electronics Venture GmbH.
Easy data access for input samples of non trivial type @T (see Supported types for adtf_memory<T> for...
Definition: sample_data.h:428
const T & GetData() const
Retrieves a reference to the data.
Definition: sample_data.h:558
Base object pointer to realize binary compatible reference counting in interface methods.

or

struct tMyData
{
uint32_t nValue1;
uint32_t nValue2;
uint32_t nValue3;
};
{
LOG_INFO("my data = {%u, %u, %u}",
oMyData->nValue1,
oMyData->nValue2,
oMyData->nValue3);
}
Template Parameters
Ttype of content of the samples sample buffer to get via GetData or sample_data::operator::T
Remarks
as long a sample data holds an reference to a sample the buffer is read locked !
See also
output_sample_data

Definition at line 427 of file sample_data.h.

Constructor & Destructor Documentation

◆ sample_data() [1/2]

sample_data ( sample_data< T, Enable > &&  oSampleData)
inline

move CTOR

Parameters
oSampleDataData to move from

Definition at line 447 of file sample_data.h.

◆ sample_data() [2/2]

sample_data ( const ucom::iobject_ptr< const ant::ISample > &  pSample)
inline

copy CTOR

Parameters
pSampleSample to get the data from

Definition at line 455 of file sample_data.h.

References sample_data< T, Enable >::Reset().

Member Function Documentation

◆ GetData()

const T& GetData ( ) const
inline

Retrieves a reference to the data.

Internally it gets the buffer pointer of the sample.

Returns
returns a reference to the sample data.
Return values
T()if not valid.

Definition at line 558 of file sample_data.h.

References sample_data< T, Enable >::IsValid().

Referenced by sample_data< T, Enable >::operator const T &(), and sample_data< T, Enable >::operator*().

◆ GetDataPtr()

const T* GetDataPtr ( ) const
inline

Retrieves the pointer to the datas memory.

Internally it gets the buffer pointer of the sample.

Returns
returns the pointer to the sample data.
Return values
nullptrif no buffer set

Definition at line 507 of file sample_data.h.

Referenced by sample_data< T, Enable >::operator->().

◆ GetDataSize()

size_t GetDataSize ( ) const
inline
Returns
The size of the buffer that the data resides in.

Definition at line 522 of file sample_data.h.

◆ GetSampleInfo()

adtf_util::cVariant GetSampleInfo ( const ISampleInfo::tHashKey oHash,
const adtf::util::cVariant  oDefault = adtf::util::cVariant() 
) const
inline

Retrieves a variant value for the hash key oHash out of the samples sample information .

If the value does not exists the return value is the given default oDefault.

Parameters
[in]oHashThe hash key of the value.
[in]oDefaultdefault value if value does not exist.
Returns
retrieved value as variant.

Definition at line 638 of file sample_data.h.

References adtf::streaming::ant::get_sample_info().

◆ GetTime()

tTimeStamp GetTime ( ) const
inline

retrieves the timestamp of the data.

Internally it gets the time of the sample.

Returns
returns the sample time
Return values
-1if not valid.

Definition at line 473 of file sample_data.h.

◆ GetTimeNs()

adtf::base::flash::tNanoSeconds GetTimeNs ( ) const
inline

retrieves the timestamp of the data.

Internally it gets the time of the sample.

Returns
returns the sample time
Return values
-1if not valid.

Definition at line 490 of file sample_data.h.

References adtf::streaming::flash::get_sample_time().

◆ IsValid()

bool IsValid ( ) const
inline

Validate if sample and sample buffer is set.

Return values
trueis valid
falseis invalid

Definition at line 584 of file sample_data.h.

Referenced by sample_data< T, Enable >::GetData().

◆ operator const T &()

operator const T & ( ) const
inline

Return the content of sample buffer as a reference to the extracted non trivial value.

i.e. if using std::string the std::string content was extracted from sample buffer

Returns
the value of the sample buffer as T
Return values
T()if no sample buffer set
See also
IsValid

Definition at line 596 of file sample_data.h.

References sample_data< T, Enable >::GetData().

◆ operator*()

const T& operator* ( ) const
inline

Retrieves a reference to the data.

Internally it gets the buffer pointer of the sample.

Returns
returns a reference to the sample data.
Return values
T()if not valid.

Definition at line 574 of file sample_data.h.

References sample_data< T, Enable >::GetData().

◆ operator->() [1/2]

const T* operator-> ( )
inline

Retrieves the pointer to the datas memory.

Internally it gets the buffer pointer of the sample.

Returns
returns the pointer to the sample data.
Return values
nullptrif no buffer set

Definition at line 537 of file sample_data.h.

References sample_data< T, Enable >::GetDataPtr().

◆ operator->() [2/2]

const T* operator-> ( ) const
inline

Retrieves the pointer to the datas memory.

Internally it gets the buffer pointer of the sample.

Returns
returns the pointer to the sample data.
Return values
nullptrif no buffer set

Definition at line 545 of file sample_data.h.

References sample_data< T, Enable >::GetDataPtr().

◆ Reset() [1/2]

tResult Reset ( )
inline

Resets the sample the sample data reference to.

The reference will be empty.

Returns
standard result
Return values
ERR_NOERRORsample is reset
See also
IsValid

Definition at line 623 of file sample_data.h.

References object_ptr< T >::Reset(), and RETURN_NOERROR.

Referenced by sample_data< T, Enable >::sample_data().

◆ Reset() [2/2]

tResult Reset ( const ucom::ant::iobject_ptr< const ant::ISample > &  pSample)
inline

Resets the sample the sample data reference to with a new reference to a sample.

Parameters
pSample[in] Reference to the sampel the sample data will reference to
Returns
standard result
Return values
ERR_NOERRORsample is reset
See also
IsValid

Definition at line 608 of file sample_data.h.

References RETURN_IF_FAILED, and RETURN_NOERROR.