| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
MTL::Instrument::CSCPIBuffer Class Reference

Instrument Buffer. More...

`#include <SCPIInstrumentBuffer.h>`

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

## 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] | InitialCapacity | Initial 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] | pData | Data buffer location.
  [in] | DataLen | Data buffer size, in bytes.

Definition at line 63 of file SCPIInstrumentBuffer.h.

## ◆ ~CSCPIBuffer()

virtual MTL::Instrument::CSCPIBuffer::~CSCPIBuffer | ( |  | ) |
| inline virtual

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] | First | Pointer to first byte of data.
  [in] | Last | Pointer 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] | pData | Pointer to first byte of data.
  [in] | n | Number 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 | ( |  | ) |
| 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
| inline noexcept

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 | ( |  | ) |
| inline noexcept

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] | capacity | Desired capacity.

Definition at line 83 of file SCPIInstrumentBuffer.h.

## ◆ resize()

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

Resize the buffer.

Parameters

  [in] | size | New 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:

- Common/SCPI/include/SCPIInstrumentBuffer.h