THM1176InstrumentManager  1.0
Qt Object abstraction for Metrolab THM1176
MTL::Instrument::CSCPIBuffer Class Reference

Instrument Buffer. More...

#include <SCPIInstrumentBuffer.h>

Public Member Functions

 CSCPIBuffer (size_t InitialCapacity=2048)
 Constructor: new empty buffer. More...
 
 CSCPIBuffer (const MTL_INSTRUMENT_BUFFER_TYPE *pData, size_t DataLen)
 Constructor: initialize with data provided. More...
 
virtual ~CSCPIBuffer ()
 Destructor. More...
 
void clear ()
 Clear by setting the buffer size to zero. More...
 
void reserve (size_t capacity)
 Allocate at least a given amount of space. More...
 
void resize (size_t size)
 Resize the buffer. More...
 
size_t size () const
 Return the buffer size. More...
 
size_t capacity () const
 Return the buffer capacity (allocated size). More...
 
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator begin ()
 Return an iterator to the beginning of the buffer. More...
 
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::const_iterator begin () const
 Return a const iterator to the beginning of the buffer. More...
 
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator end ()
 Return an iterator to the end of the buffer. More...
 
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::const_iterator end () const
 Return a const iterator to the end of the buffer. More...
 
MTL_INSTRUMENT_BUFFER_TYPEdata () noexcept
 Return a pointer to the data. More...
 
const MTL_INSTRUMENT_BUFFER_TYPEdata () const noexcept
 Return a const pointer to the data. More...
 
MTL_INSTRUMENT_BUFFER_TYPEoperator[] (size_t n)
 Return byte n of the buffer. More...
 
const MTL_INSTRUMENT_BUFFER_TYPEoperator[] (size_t n) const
 Return byte n of the buffer as const. More...
 
void assign (const MTL_INSTRUMENT_BUFFER_TYPE *First, const MTL_INSTRUMENT_BUFFER_TYPE *Last)
 Copy the given data into the buffer: variant with begin/end. More...
 
void assign (const MTL_INSTRUMENT_BUFFER_TYPE *pData, size_t n)
 Copy the given data into the buffer: variant with pointer/size. More...
 

Detailed Description

Instrument Buffer.

This class is intended to provide an efficient way of reading data and parsing a SCPI response. Read operations require an allocated buffer pointer and its length. Parsing methods (regex, find etc...) require std::string object or iterators.

  • std::string doesn't ensure that its data is stored contiguously: cannot write to it through a pointer.
  • std::vector ensures contiguous storage and it is allowed to write to its allocated storage (capacity) through a pointer. But it is impossible to set its size. It is thus not possible to indicate how many bytes have been stored into the vector after a read.

This class holds data in a std::vector. Storage is thus allocated in contiguous memory and memory allocation/deallocation is automatically handled. A size member is managed by this class itself and can be set by a method. We must ensure that this class size is always less than or equal to the contained vector size (the class capacity is equivalent to the contained vector size).

Definition at line 43 of file SCPIInstrumentBuffer.h.

Constructor & Destructor Documentation

◆ CSCPIBuffer() [1/2]

MTL::Instrument::CSCPIBuffer::CSCPIBuffer ( size_t  InitialCapacity = 2048)
inline

Constructor: new empty buffer.

Parameters
[in]InitialCapacityInitial buffer size, in bytes.

Definition at line 52 of file SCPIInstrumentBuffer.h.

◆ CSCPIBuffer() [2/2]

MTL::Instrument::CSCPIBuffer::CSCPIBuffer ( const MTL_INSTRUMENT_BUFFER_TYPE pData,
size_t  DataLen 
)
inline

Constructor: initialize with data provided.

Parameters
[in]pDataData buffer location.
[in]DataLenData buffer size, in bytes.

Definition at line 63 of file SCPIInstrumentBuffer.h.

◆ ~CSCPIBuffer()

virtual MTL::Instrument::CSCPIBuffer::~CSCPIBuffer ( )
inlinevirtual

Destructor.

Definition at line 70 of file SCPIInstrumentBuffer.h.

Member Function Documentation

◆ assign() [1/2]

void MTL::Instrument::CSCPIBuffer::assign ( const MTL_INSTRUMENT_BUFFER_TYPE First,
const MTL_INSTRUMENT_BUFFER_TYPE Last 
)
inline

Copy the given data into the buffer: variant with begin/end.

Parameters
[in]FirstPointer to first byte of data.
[in]LastPointer to first byte past the data.

Definition at line 188 of file SCPIInstrumentBuffer.h.

◆ assign() [2/2]

void MTL::Instrument::CSCPIBuffer::assign ( const MTL_INSTRUMENT_BUFFER_TYPE pData,
size_t  n 
)
inline

Copy the given data into the buffer: variant with pointer/size.

Parameters
[in]pDataPointer to first byte of data.
[in]nNumber of bytes.

Definition at line 201 of file SCPIInstrumentBuffer.h.

◆ begin() [1/2]

std::vector<MTL_INSTRUMENT_BUFFER_TYPE>::iterator MTL::Instrument::CSCPIBuffer::begin ( )
inline

Return an iterator to the beginning of the buffer.

Definition at line 122 of file SCPIInstrumentBuffer.h.

◆ begin() [2/2]

std::vector<MTL_INSTRUMENT_BUFFER_TYPE>::const_iterator MTL::Instrument::CSCPIBuffer::begin ( ) const
inline

Return a const iterator to the beginning of the buffer.

Definition at line 130 of file SCPIInstrumentBuffer.h.

◆ capacity()

size_t MTL::Instrument::CSCPIBuffer::capacity ( ) const
inline

Return the buffer capacity (allocated size).

Definition at line 114 of file SCPIInstrumentBuffer.h.

◆ clear()

void MTL::Instrument::CSCPIBuffer::clear ( void  )
inline

Clear by setting the buffer size to zero.

Definition at line 74 of file SCPIInstrumentBuffer.h.

◆ data() [1/2]

const MTL_INSTRUMENT_BUFFER_TYPE* MTL::Instrument::CSCPIBuffer::data ( ) const
inlinenoexcept

Return a const pointer to the data.

Definition at line 162 of file SCPIInstrumentBuffer.h.

◆ data() [2/2]

MTL_INSTRUMENT_BUFFER_TYPE* MTL::Instrument::CSCPIBuffer::data ( )
inlinenoexcept

Return a pointer to the data.

Definition at line 154 of file SCPIInstrumentBuffer.h.

◆ end() [1/2]

std::vector<MTL_INSTRUMENT_BUFFER_TYPE>::iterator MTL::Instrument::CSCPIBuffer::end ( )
inline

Return an iterator to the end of the buffer.

Definition at line 138 of file SCPIInstrumentBuffer.h.

◆ end() [2/2]

std::vector<MTL_INSTRUMENT_BUFFER_TYPE>::const_iterator MTL::Instrument::CSCPIBuffer::end ( ) const
inline

Return a const iterator to the end of the buffer.

Definition at line 146 of file SCPIInstrumentBuffer.h.

◆ operator[]() [1/2]

MTL_INSTRUMENT_BUFFER_TYPE& MTL::Instrument::CSCPIBuffer::operator[] ( size_t  n)
inline

Return byte n of the buffer.

Definition at line 170 of file SCPIInstrumentBuffer.h.

◆ operator[]() [2/2]

const MTL_INSTRUMENT_BUFFER_TYPE& MTL::Instrument::CSCPIBuffer::operator[] ( size_t  n) const
inline

Return byte n of the buffer as const.

Definition at line 178 of file SCPIInstrumentBuffer.h.

◆ reserve()

void MTL::Instrument::CSCPIBuffer::reserve ( size_t  capacity)
inline

Allocate at least a given amount of space.

Parameters
[in]capacityDesired capacity.

Definition at line 83 of file SCPIInstrumentBuffer.h.

◆ resize()

void MTL::Instrument::CSCPIBuffer::resize ( size_t  size)
inline

Resize the buffer.

Parameters
[in]sizeNew buffer size.

Definition at line 93 of file SCPIInstrumentBuffer.h.

◆ size()

size_t MTL::Instrument::CSCPIBuffer::size ( ) const
inline

Return the buffer size.

Definition at line 106 of file SCPIInstrumentBuffer.h.


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