nidas v1.2.3
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
nidas::core::SampleChar Class Reference

#include <Sample.h>

Inheritance diagram for nidas::core::SampleChar:
Inheritance graph
[legend]

Public Member Functions

 SampleChar (const char *buffer)
 Construct a SampleT<char> initialized to the bytes in buffer.
 
void setValues (std::initializer_list< char > values)
 
sampleType getType () const
 Get the type of the sample.
 
unsigned int getDataLength () const
 Get number of elements of type DataT in data.
 
void setDataLength (unsigned int val)
 Set the number of elements of type DataT in data.
 
voidgetVoidDataPtr ()
 Get a void* pointer to the data portion of the sample.
 
const voidgetConstVoidDataPtr () const
 Get a const void* pointer to the data portion of the sample.
 
chargetDataPtr ()
 
const chargetConstDataPtr () const
 
double getDataValue (unsigned int i) const
 Implementation of virtual method.
 
void setDataValue (unsigned int i, double val)
 Implementation of virtual method.
 
void setDataValue (unsigned int i, float val)
 Implementation of virtual method.
 
unsigned int getAllocLength () const
 Get number of elements allocated in data portion of sample.
 
unsigned int getAllocByteLength () const
 Get number of bytes allocated in data portion of sample.
 
void allocateData (unsigned int val)
 Allocate data.
 
void reallocateData (unsigned int val)
 Re-allocate data, space, keeping contents.
 
void freeReference () const
 Decrement the reference count for this sample.
 
void setTimeTag (dsm_time_t val)
 
dsm_time_t getTimeTag () const
 Time-tag in non-leap microseconds since Jan 1, 1970 00:00 GMT.
 
void setId (dsm_sample_id_t val)
 Set the id portion of the sample header.
 
dsm_sample_id_t getId () const
 Get the id portion of the sample header.
 
void setRawId (dsm_sample_id_t val)
 Set the full, raw id portion of the sample header.
 
dsm_sample_id_t getRawId () const
 
void setSpSId (unsigned int val)
 Set the short id portion of the sample header, containing the sensor + sample ids.
 
unsigned int getSpSId () const
 Get the short id portion of the sample header.
 
void setDSMId (unsigned int val)
 Set the DSM (data system) id portion of the sample header.
 
unsigned int getDSMId () const
 Get the DSM (data system) id portion of the sample header.
 
unsigned int getDataByteLength () const
 Get the number of bytes in data portion of sample.
 
unsigned int getHeaderLength () const
 Number of bytes in header.
 
const voidgetHeaderPtr () const
 Get a pointer to the header portion of the sample.
 
void holdReference () const
 Increment the reference count for this sample.
 

Static Public Member Functions

static unsigned int getMaxDataLength ()
 Maximum number of elements in data.
 
static int sizeofDataType ()
 

Protected Attributes

char_data
 Pointer to the actual data.
 
unsigned int _allocLen
 Number of bytes allocated in data.
 
SampleHeader _header
 
int _refCount
 The reference count.
 
nidas::util::Mutex _refLock
 

Static Protected Attributes

static int _nsamps
 Global count of the number of samples in use by a process.
 

Constructor & Destructor Documentation

◆ SampleChar()

nidas::core::SampleChar::SampleChar ( const char * buffer)
inline

Construct a SampleT<char> initialized to the bytes in buffer.

The buffer must be null-terminated, and the null will be included in the Sample data.

Parameters
buffernull-terminated array of chars

References nidas::core::SampleT< char >::allocateData(), buffer, nidas::core::SampleT< char >::getDataPtr(), nidas::core::getSample(), len, and nidas::core::SampleT< char >::setDataLength().

Member Function Documentation

◆ allocateData()

void nidas::core::SampleT< char >::allocateData ( unsigned int val)
inlinevirtualinherited

Allocate data.

Parameters
valnumber of DataT's to allocated.

Implements nidas::core::Sample.

◆ freeReference()

void nidas::core::SampleT< char >::freeReference ( ) const
virtualinherited

Decrement the reference count for this sample.

Free a reference to a sample.

If the reference count is zero, then put the Sample into the SamplePool. freeReference() can be performed on a const Sample. However if at any moment a user of a const Sample has called freeReference more times than they have called holdReference, then they have violated the contract of a const Sample. Once the sample goes back into the sample pool it may be altered.

Samples can be used like normal variables without reference counting: { SampleT< samp; // automatic variable samp.setTimeTag(99); ... } // automatic variable destroyed

Or the reference count capability can be used. Here one saves samples into a buffer, and then later pops them off.

void pushSample(const Sample* samp) { samp->holdReference(); buffer.push_back(samp); } const Sample* popSample() { const Sample* samp = buffer.back(); buffer.pop_back(); samp->freeReference(); return samp; }

// Get sample from SamplePool. // The reference count will be one after the sample // is fetched from the pool - holdReference is // called for you by SamplePool. Sample* samp = SamplePool::getInstance()->getSample(100); ... pushSample(samp); ... samp = popSample(); ... // When you're completely done with it, call freeReference(). samp->freeReference();

Return it to its pool if no-one is using it.

Implements nidas::core::Sample.

◆ getAllocByteLength()

unsigned int nidas::core::SampleT< char >::getAllocByteLength ( ) const
inlinevirtualinherited

Get number of bytes allocated in data portion of sample.

Implements nidas::core::Sample.

◆ getAllocLength()

unsigned int nidas::core::SampleT< char >::getAllocLength ( ) const
inlinevirtualinherited

Get number of elements allocated in data portion of sample.

Implements nidas::core::Sample.

◆ getConstDataPtr()

const char * nidas::core::SampleT< char >::getConstDataPtr ( ) const
inlineinherited

◆ getConstVoidDataPtr()

const void * nidas::core::SampleT< char >::getConstVoidDataPtr ( ) const
inlinevirtualinherited

Get a const void* pointer to the data portion of the sample.

Implements nidas::core::Sample.

◆ getDataByteLength()

unsigned int nidas::core::Sample::getDataByteLength ( ) const
inlineinherited

◆ getDataLength()

unsigned int nidas::core::SampleT< char >::getDataLength ( ) const
inlinevirtualinherited

Get number of elements of type DataT in data.

Implements nidas::core::Sample.

◆ getDataPtr()

char * nidas::core::SampleT< char >::getDataPtr ( )
inlineinherited

◆ getDataValue()

double nidas::core::SampleT< char >::getDataValue ( unsigned int i) const
inlinevirtualinherited

Implementation of virtual method.

Implements nidas::core::Sample.

◆ getDSMId()

unsigned int nidas::core::Sample::getDSMId ( ) const
inlineinherited

Get the DSM (data system) id portion of the sample header.

References nidas::core::Sample::_header, and nidas::core::SampleHeader::getDSMId().

Referenced by nidas::core::NearestResamplerAtRate::connect().

◆ getHeaderLength()

unsigned int nidas::core::Sample::getHeaderLength ( ) const
inlineinherited

Number of bytes in header.

References nidas::core::SampleHeader::getSizeOf().

◆ getHeaderPtr()

const void * nidas::core::Sample::getHeaderPtr ( ) const
inlineinherited

Get a pointer to the header portion of the sample.

References nidas::core::Sample::_header.

Referenced by nidas::core::operator<<().

◆ getId()

dsm_sample_id_t nidas::core::Sample::getId ( ) const
inlineinherited

◆ getMaxDataLength()

static unsigned int nidas::core::SampleT< char >::getMaxDataLength ( )
inlinestaticinherited

Maximum number of elements in data.

◆ getRawId()

dsm_sample_id_t nidas::core::Sample::getRawId ( ) const
inlineinherited

◆ getSpSId()

unsigned int nidas::core::Sample::getSpSId ( ) const
inlineinherited

Get the short id portion of the sample header.

This is the portion of the id without the DSM id.

References nidas::core::Sample::_header, and nidas::core::SampleHeader::getSpSId().

◆ getTimeTag()

dsm_time_t nidas::core::Sample::getTimeTag ( ) const
inlineinherited

◆ getType()

sampleType nidas::core::SampleT< char >::getType ( ) const
inlinevirtualinherited

Get the type of the sample.

Implements nidas::core::Sample.

◆ getVoidDataPtr()

void * nidas::core::SampleT< char >::getVoidDataPtr ( )
inlinevirtualinherited

Get a void* pointer to the data portion of the sample.

Implements nidas::core::Sample.

◆ holdReference()

void nidas::core::Sample::holdReference ( ) const
inlineinherited

Increment the reference count for this sample.

Sample supports a form of reference counting. See freeReference. We have to use a hack-like cast of the this pointer to a const so that holdReference can be used on a const Sample. The SamplePool class supports Sample reference counting.

References nidas::core::Sample::_refCount, nidas::core::Sample::_refLock, nidas::core::getSample(), nidas::util::Mutex::lock(), and nidas::util::Mutex::unlock().

Referenced by nidas::core::SamplePool< SampleType >::getSample(), and nidas::dynld::raf::LamsNetSensor::process().

◆ reallocateData()

void nidas::core::SampleT< char >::reallocateData ( unsigned int val)
inlinevirtualinherited

Re-allocate data, space, keeping contents.

Parameters
valnumber of DataT's to allocated.

Implements nidas::core::Sample.

◆ setDataLength()

void nidas::core::SampleT< char >::setDataLength ( unsigned int val)
inlinevirtualinherited

Set the number of elements of type DataT in data.

Parameters
valnumber of elements.

Implements nidas::core::Sample.

◆ setDataValue() [1/2]

void nidas::core::SampleT< char >::setDataValue ( unsigned int i,
double val )
inlinevirtualinherited

Implementation of virtual method.

Implements nidas::core::Sample.

◆ setDataValue() [2/2]

void nidas::core::SampleT< char >::setDataValue ( unsigned int i,
float val )
inlinevirtualinherited

Implementation of virtual method.

Implements nidas::core::Sample.

◆ setDSMId()

void nidas::core::Sample::setDSMId ( unsigned int val)
inlineinherited

Set the DSM (data system) id portion of the sample header.

References nidas::core::Sample::_header, and nidas::core::SampleHeader::setDSMId().

◆ setId()

void nidas::core::Sample::setId ( dsm_sample_id_t val)
inlineinherited

◆ setRawId()

void nidas::core::Sample::setRawId ( dsm_sample_id_t val)
inlineinherited

Set the full, raw id portion of the sample header.

This method is not typically used except when doing raw IO on a sample. The raw id contains an enumeration of the sample type, along with the fields returned by getId().

References nidas::core::Sample::_header, and nidas::core::SampleHeader::setRawId().

◆ setSpSId()

void nidas::core::Sample::setSpSId ( unsigned int val)
inlineinherited

Set the short id portion of the sample header, containing the sensor + sample ids.

This is the portion of the id without the DSM id.

References nidas::core::Sample::_header, and nidas::core::SampleHeader::setSpSId().

◆ setTimeTag()

void nidas::core::Sample::setTimeTag ( dsm_time_t val)
inlineinherited

◆ setValues()

void nidas::core::SampleT< char >::setValues ( std::initializer_list< char > values)
inlineinherited

◆ sizeofDataType()

static int nidas::core::SampleT< char >::sizeofDataType ( )
inlinestaticinherited

Member Data Documentation

◆ _allocLen

unsigned int nidas::core::SampleT< char >::_allocLen
protectedinherited

Number of bytes allocated in data.

◆ _data

char * nidas::core::SampleT< char >::_data
protectedinherited

Pointer to the actual data.

◆ _header

SampleHeader nidas::core::Sample::_header
protectedinherited

◆ _nsamps

int Sample::_nsamps
staticprotectedinherited

Global count of the number of samples in use by a process.

Incremented in the constructor, decremented in the destructor. Useful for development debugging to track leaks.

Referenced by nidas::core::Sample::Sample(), and nidas::core::Sample::~Sample().

◆ _refCount

int nidas::core::Sample::_refCount
mutableprotectedinherited

The reference count.

Referenced by nidas::core::Sample::holdReference().

◆ _refLock

nidas::util::Mutex nidas::core::Sample::_refLock
mutableprotectedinherited

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