32#ifndef NIDAS_CORE_SAMPLET_H
33#define NIDAS_CORE_SAMPLET_H
44#include <initializer_list>
50namespace nidas {
namespace core {
76#define GET_SAMPLE_TYPE(tid) ((tid) >> 26)
77#define SET_SAMPLE_TYPE(tid,val) (((tid) & 0x03ffffff) | ((unsigned int)(val) << 26))
79#define GET_FULL_ID(tid) ((tid) & 0x03ffffff)
80#define SET_FULL_ID(tid,val) (((tid) & 0xfc000000) | ((val) & 0x03ffffff))
82#define GET_DSM_ID(tid) (((tid) & 0x03ff0000) >> 16)
83#define SET_DSM_ID(tid,val) (((tid) & 0xfc00ffff) | (((unsigned int)(val) & 0x3ff) << 16))
85#define GET_SPS_ID(tid) ((tid) & 0xffff)
86#define GET_SHORT_ID(tid) ((tid) & 0xffff)
88#define SET_SPS_ID(tid,val) (((tid) & 0xffff0000) | ((val) & 0xffff))
89#define SET_SHORT_ID(tid,val) (((tid) & 0xffff0000) | ((val) & 0xffff))
95#define MUTEX_PROTECT_REF_COUNTS
341#ifdef USE_ATOMIC_REF_COUNT
344#ifdef MUTEX_PROTECT_REF_COUNTS
348#ifdef MUTEX_PROTECT_REF_COUNTS
368#ifdef MUTEX_PROTECT_REF_COUNTS
377#ifndef PROTECT_NSAMPLES
379#ifdef ENABLE_VALGRIND
383 friend class InitValgrind;
393template <
class DataT>
424 unsigned int len = values.size();
428 for (
auto v : values)
442 SampleT(std::initializer_list<DataT> values) :
547 DataT* newdata =
new DataT[
val];
664namespace nidas {
namespace core {
673 SamplePool<SampleT<T> >::getInstance()->getSample(
len);
684SampleT<char>*
getSample(
const char* data);
690template <
class DataT>
694#ifdef USE_ATOMIC_REF_COUNT
699 SamplePool<SampleT<DataT> >::getInstance()->putSample(
this);
701#ifdef MUTEX_PROTECT_REF_COUNTS
704 bool ref0 = --_refCount == 0;
706#ifdef MUTEX_PROTECT_REF_COUNTS
710 SamplePool<SampleT<DataT> >::getInstance()->putSample(
this);
#define GET_FULL_ID(tid)
Definition Sample.h:79
#define GET_SPS_ID(tid)
Definition Sample.h:85
#define SET_SPS_ID(tid, val)
Definition Sample.h:88
#define GET_DSM_ID(tid)
Definition Sample.h:82
#define GET_SAMPLE_TYPE(tid)
macros to get and set fields of the tid member of a Sample.
Definition Sample.h:76
#define SET_DSM_ID(tid, val)
Definition Sample.h:83
#define SET_FULL_ID(tid, val)
Definition Sample.h:80
SampleChar(const char *buffer)
Construct a SampleT<char> initialized to the bytes in buffer.
Definition Sample.h:639
Definition SampleLengthException.h:35
A typed Sample, with data of type DataT.
Definition Sample.h:394
static int sizeofDataType()
Definition Sample.h:555
void allocateData(unsigned int val)
Allocate data.
Definition Sample.h:526
void setDataLength(unsigned int val)
Set the number of elements of type DataT in data.
Definition Sample.h:465
void * getVoidDataPtr()
Get a void* pointer to the data portion of the sample.
Definition Sample.h:481
const void * getConstVoidDataPtr() const
Get a const void* pointer to the data portion of the sample.
Definition Sample.h:482
SampleT(const SampleT &)
No copy.
unsigned int getAllocLength() const
Get number of elements allocated in data portion of sample.
Definition Sample.h:515
unsigned int getAllocByteLength() const
Get number of bytes allocated in data portion of sample.
Definition Sample.h:520
void reallocateData(unsigned int val)
Re-allocate data, space, keeping contents.
Definition Sample.h:542
unsigned int getDataLength() const
Get number of elements of type DataT in data.
Definition Sample.h:456
void setDataValue(unsigned int i, float val)
Implementation of virtual method.
Definition Sample.h:507
double getDataValue(unsigned int i) const
Implementation of virtual method.
Definition Sample.h:491
const DataT * getConstDataPtr() const
Definition Sample.h:486
SampleT()
Definition Sample.h:416
void freeReference() const
Decrement the reference count for this sample.
Definition Sample.h:691
void setValues(std::initializer_list< DataT > values)
Definition Sample.h:422
DataT * getDataPtr()
Definition Sample.h:484
DataT * _data
Pointer to the actual data.
Definition Sample.h:613
void setDataValue(unsigned int i, double val)
Implementation of virtual method.
Definition Sample.h:499
SampleT & operator=(const SampleT &)
No assignment.
static unsigned int getMaxDataLength()
Maximum number of elements in data.
Definition Sample.h:476
~SampleT()
Definition Sample.h:449
unsigned int _allocLen
Number of bytes allocated in data.
Definition Sample.h:618
sampleType getType() const
Get the type of the sample.
Definition Sample.h:451
SampleT(std::initializer_list< DataT > values)
Construct a SampleT from an initializer list.
Definition Sample.h:442
Interface to a data sample.
Definition Sample.h:190
int _refCount
The reference count.
Definition Sample.h:366
virtual void reallocateData(unsigned int val)=0
Re-allocate a number of bytes of data, saving old contents.
void setDSMId(unsigned int val)
Set the DSM (data system) id portion of the sample header.
Definition Sample.h:247
virtual double getDataValue(unsigned int i) const =0
Get the numeric value of data element i.
const void * getHeaderPtr() const
Get a pointer to the header portion of the sample.
Definition Sample.h:282
dsm_sample_id_t getRawId() const
Definition Sample.h:229
virtual void freeReference() const =0
Decrement the reference count for this sample.
SampleHeader _header
Definition Sample.h:361
unsigned int getDSMId() const
Get the DSM (data system) id portion of the sample header.
Definition Sample.h:252
virtual void allocateData(unsigned int val)=0
Allocate a number of bytes of data.
virtual ~Sample()
Definition Sample.h:199
virtual sampleType getType() const =0
Get the type of the sample.
virtual unsigned int getAllocByteLength() const =0
Get number of bytes allocated in data portion of sample.
virtual void setDataValue(unsigned int i, float val)=0
Set the value of data element i to a float.
virtual void setDataLength(unsigned int val)=0
Set the number of elements in data portion of sample.
void setRawId(dsm_sample_id_t val)
Set the full, raw id portion of the sample header.
Definition Sample.h:227
dsm_sample_id_t getId() const
Get the id portion of the sample header.
Definition Sample.h:218
nidas::util::Mutex _refLock
Definition Sample.h:369
void setSpSId(unsigned int val)
Set the short id portion of the sample header, containing the sensor + sample ids.
Definition Sample.h:236
Sample(sampleType t=CHAR_ST)
Definition Sample.h:193
virtual unsigned int getAllocLength() const =0
Get number of elements allocated in data portion of sample.
void holdReference() const
Increment the reference count for this sample.
Definition Sample.h:340
dsm_time_t getTimeTag() const
Time-tag in non-leap microseconds since Jan 1, 1970 00:00 GMT.
Definition Sample.h:206
virtual unsigned int getDataLength() const =0
Get the number of elements in data portion of sample.
void setTimeTag(dsm_time_t val)
Definition Sample.h:201
virtual const void * getConstVoidDataPtr() const =0
Get a const void* pointer to the data portion of the sample.
unsigned int getHeaderLength() const
Number of bytes in header.
Definition Sample.h:277
virtual void * getVoidDataPtr()=0
Get a void* pointer to the data portion of the sample.
virtual void setDataValue(unsigned int i, double val)=0
Set the value of data element i to a double.
unsigned int getDataByteLength() const
Get the number of bytes in data portion of sample.
Definition Sample.h:257
unsigned int getSpSId() const
Get the short id portion of the sample header.
Definition Sample.h:242
static int _nsamps
Global count of the number of samples in use by a process.
Definition Sample.h:378
void setId(dsm_sample_id_t val)
Set the id portion of the sample header.
Definition Sample.h:213
A class which wraps a numeric value and guards operations on it with a Mutex.
Definition MutexCount.h:40
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
void lock()
Lock the Mutex.
Definition ThreadSupport.h:216
void unlock()
Unlock the Mutex.
Definition ThreadSupport.h:230
char buffer[5000]
Definition loop.c:35
const float floatNAN
Value of a float NAN for general use.
Definition Sample.cc:31
unsigned int maxValue(unsigned short)
maxValue is an overloaded function returning the maximum value of its integer argument.
Definition sample_type_traits.h:10
const double doubleNAN
Definition Sample.cc:33
sampleType getSampleType(T *)
Definition sample_type_traits.h:111
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
sampleType
Definition sample_type_traits.h:30
@ CHAR_ST
Definition sample_type_traits.h:31
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC.
Definition Sample.h:62
unsigned int dsm_sample_id_t
Definition Sample.h:64
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
int len
Definition sing.cc:948
Definition sample_type_traits.h:46
unsigned int dsm_sample_length_t
length of data portion of sample.
Definition types.h:51