![]() |
PahoMqttCpp
MQTT C++ Client for POSIX and Windows
|
#include <buffer_ref.h>
Public Types | |
using | value_type = T |
using | blob = std::basic_string< value_type > |
using | pointer_type = std::shared_ptr< const blob > |
Public Member Functions | |
buffer_ref ()=default | |
buffer_ref (const buffer_ref &buf)=default | |
buffer_ref (buffer_ref &&buf)=default | |
buffer_ref (const blob &b) | |
buffer_ref (blob &&b) | |
buffer_ref (const pointer_type &p) | |
buffer_ref (pointer_type &&p) | |
buffer_ref (const value_type *buf, size_t n) | |
buffer_ref (const char *buf) | |
buffer_ref & | operator= (const buffer_ref &rhs)=default |
buffer_ref & | operator= (buffer_ref &&rhs)=default |
buffer_ref & | operator= (const blob &b) |
buffer_ref & | operator= (blob &&b) |
buffer_ref & | operator= (const char *cstr) |
template<typename OT > | |
buffer_ref & | operator= (const buffer_ref< OT > &rhs) |
void | reset () |
operator bool () const | |
bool | is_null () const |
bool | empty () const |
const value_type * | data () const |
size_t | size () const |
size_t | length () const |
const blob & | str () const |
const blob & | to_string () const |
const char * | c_str () const |
const pointer_type & | ptr () const |
const value_type & | operator[] (size_t i) const |
A reference object for holding immutable data buffers, with cheap copy semantics and lifetime management.
Each object of this class contains a reference-counted pointer to an immutable data buffer. Objects can be copied freely and easily, even across threads, since all instances promise not to modify the contents of the buffer.
The buffer is immutable but the reference itself acts like a normal variable. It can be reassigned to point to a different buffer.
If no value has been assigned to a reference, then it is in a default "null" state. It is not safe to call any member functions on a null reference, other than to check if the object is null or empty.
* string_ref sr; * if (!sr) * cout << "null reference" << endl; * else * cout.write(sr.data(), sr.size()); *
using mqtt::buffer_ref< T >::value_type = T |
The underlying type for the buffer. Normally byte-wide data (char or uint8_t) for Paho.
using mqtt::buffer_ref< T >::blob = std::basic_string<value_type> |
The type for the buffer. We use basic_string for compatibility with string data.
using mqtt::buffer_ref< T >::pointer_type = std::shared_ptr<const blob> |
The pointer we use. Note that it is a pointer to a const blob.
|
default |
Default constructor creates a null reference.
|
default |
Copy constructor only copies a shared pointer.
buf | Another buffer reference. |
|
default |
Move constructor only moves a shared pointer.
buf | Another buffer reference. |
|
inline |
Creates a reference to a new buffer by copying data.
b | A string from which to create a new buffer. |
|
inline |
Creates a reference to a new buffer by moving a string into the buffer.
b | A string from which to create a new buffer. |
|
inline |
Creates a reference to an existing buffer by copying the shared pointer. Note that it is up to the caller to insure that there are no mutable references to the buffer.
p | A shared pointer to a string. |
|
inline |
Creates a reference to an existing buffer by moving the shared pointer. Note that it is up to the caller to insure that there are no mutable references to the buffer.
p | A shared pointer to a string. |
|
inline |
Creates a reference to a new buffer containing a copy of the data.
buf | The memory to copy |
n | The number of bytes to copy. |
|
inline |
Creates a reference to a new buffer containing a copy of the NUL-terminated char array.
buf | A NUL-terminated char array (C string). |
|
default |
Copy the reference to the buffer.
rhs | Another buffer |
|
default |
Move a reference to a buffer.
rhs | The other reference to move. |
|
inline |
Copy a string into this object, creating a new buffer. Modifies the reference for this object, pointing it to a newly-created buffer. Other references to the old object remain unchanges, so this follows copy-on-write semantics.
b | A new blob/string to copy. |
|
inline |
Move a string into this object, creating a new buffer. Modifies the reference for this object, pointing it to a newly-created buffer. Other references to the old object remain unchanges, so this follows copy-on-write semantics.
b | A new blob/string to move. |
|
inline |
Copy a NUL-terminated C char array into a new buffer
cstr | A NUL-terminated C string. |
|
inline |
Copy another type of buffer reference to this one. This can copy a buffer of different types, provided that the size of the data elements are the same. This is typically used to convert from char to byte, where the data is the same, but the interpretation is different. Note that this copies the underlying buffer.
rhs | A reference to a different type of buffer. |
|
inline |
Clears the reference to nil.
|
inlineexplicit |
|
inline |
|
inline |
Determines if the buffer is empty.
|
inline |
Gets a const pointer to the data buffer.
|
inline |
Gets the size of the data buffer.
|
inline |
Gets the size of the data buffer.
|
inline |
Gets the data buffer as a string.
|
inline |
Gets the data buffer as a string.
|
inline |
Gets the data buffer as NUL-terminated C string. Note that the reference must be set to call this function.
|
inline |
Gets a shared pointer to the (const) data buffer.
|
inline |
Gets elemental access to the data buffer (read only)
i | The index into the buffer. |