PahoMqttCpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
mqtt::string_collection Class Reference

#include <string_collection.h>

Public Types

using collection_type = std::vector<string>
 
using const_iterator = collection_type::const_iterator
 
using ptr_t = std::shared_ptr<string_collection>
 
using const_ptr_t = std::shared_ptr<const string_collection>
 

Public Member Functions

 string_collection ()=default
 
 string_collection (const string &str)
 
 string_collection (string &&str)
 
 string_collection (const collection_type &vec)
 
 string_collection (collection_type &&vec)
 
 string_collection (const string_collection &coll)
 
 string_collection (string_collection &&coll)=default
 
 string_collection (std::initializer_list< string > sl)
 
 string_collection (std::initializer_list< const char * > sl)
 
string_collectionoperator= (const string_collection &coll)
 
string_collectionoperator= (string_collection &&coll)=default
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
bool empty () const
 
size_t size () const
 
void push_back (const string &str)
 
void push_back (string &&str)
 
void clear ()
 
const stringoperator[] (size_t i) const
 
char *const * c_arr () const
 

Static Public Member Functions

static ptr_t create (const string &str)
 
static ptr_t create (string &&str)
 
static ptr_t create (const collection_type &vec)
 
static ptr_t create (collection_type &&vec)
 
static ptr_t create (std::initializer_list< string > sl)
 
static ptr_t create (std::initializer_list< const char * > sl)
 

Detailed Description

Type for a collection of strings, such as MQTT topics.

This acts like a standard collection of strings but carries an array of pointers to the C strings for easy interactions with the Paho C library.

Member Typedef Documentation

◆ collection_type

The type for the collection of strings

◆ const_iterator

using mqtt::string_collection::const_iterator = collection_type::const_iterator

Iterator over const items

◆ ptr_t

Smart/shared pointer to an object of this type

◆ const_ptr_t

Smart/shared pointer to a const object of this type

Constructor & Destructor Documentation

◆ string_collection() [1/9]

mqtt::string_collection::string_collection ( )
default

Construct an empty string collection.

◆ string_collection() [2/9]

mqtt::string_collection::string_collection ( const string & str)

Construct a collection initially containing a single string.

Parameters
strThe string

◆ string_collection() [3/9]

mqtt::string_collection::string_collection ( string && str)

Construct a collection initially containing a single string.

Parameters
strThe string

◆ string_collection() [4/9]

mqtt::string_collection::string_collection ( const collection_type & vec)

Constructs a string collection by copying a vector of strings.

Parameters
vecA vector of strings.

◆ string_collection() [5/9]

mqtt::string_collection::string_collection ( collection_type && vec)

Constructs a string collection by moving a vector of strings.

Parameters
vecA vector of strings.

◆ string_collection() [6/9]

mqtt::string_collection::string_collection ( const string_collection & coll)

Copy constructor.

Parameters
collAn existing string collection.

◆ string_collection() [7/9]

mqtt::string_collection::string_collection ( string_collection && coll)
default

Move constructor.

Parameters
collAn existing string collection.

◆ string_collection() [8/9]

mqtt::string_collection::string_collection ( std::initializer_list< string > sl)

Construct a string collection from an initialization list of strings.

Parameters
slAn initialization list of strings.

◆ string_collection() [9/9]

mqtt::string_collection::string_collection ( std::initializer_list< const char * > sl)

Construct a string collection from an initialization list of C string pointers.

Parameters
slAn initialization list of C character arrays.

Member Function Documentation

◆ create() [1/6]

static ptr_t mqtt::string_collection::create ( const string & str)
inlinestatic

Create an empty string collection on the heap.

Returns
A smart/shared pointer to a string collection.

◆ create() [2/6]

static ptr_t mqtt::string_collection::create ( string && str)
inlinestatic

Create a string collection on the heap, initially containing a single string.

Parameters
strThe string
Returns
A smart/shared pointer to a string collection.

◆ create() [3/6]

static ptr_t mqtt::string_collection::create ( const collection_type & vec)
inlinestatic

Creates a string collection on the heap by copying a vector of strings.

Parameters
vecA vector of strings.

◆ create() [4/6]

static ptr_t mqtt::string_collection::create ( collection_type && vec)
inlinestatic

Creates a string collection on the heap by copying a vector of strings.

Parameters
vecA vector of strings.
Returns
A smart/shared pointer to a string collection.

◆ create() [5/6]

static ptr_t mqtt::string_collection::create ( std::initializer_list< string > sl)
inlinestatic

Create a string collection on the heap from an initialization list of strings.

Parameters
slAn initialization list of strings.
Returns
A smart/shared pointer to a string collection.

◆ create() [6/6]

static ptr_t mqtt::string_collection::create ( std::initializer_list< const char * > sl)
inlinestatic

Create a string collection on the heap from an initialization list of C string pointers.

Parameters
slAn initialization list of C character arrays.
Returns
A smart/shared pointer to a string collection.

◆ operator=() [1/2]

string_collection & mqtt::string_collection::operator= ( const string_collection & coll)

Copy assignment. Copy another string collection to this one.

Parameters
collA string collection
Returns
A reference to this collection.

◆ operator=() [2/2]

string_collection & mqtt::string_collection::operator= ( string_collection && coll)
default

Move assignment. Move another string collection to this one.

Parameters
collA string collection
Returns
A reference to this collection.

◆ begin()

const_iterator mqtt::string_collection::begin ( ) const
inline

Gets a const iterator to the beginning of the collection.

Returns
A const iterator to the beginning of the collection.

◆ end()

const_iterator mqtt::string_collection::end ( ) const
inline

Gets a const iterator to the end of the collection.

Returns
A const iterator to the end of the collection.

◆ cbegin()

const_iterator mqtt::string_collection::cbegin ( ) const
inline

Gets a const iterator to the beginning of the collection.

Returns
A const iterator to the beginning of the collection.

◆ cend()

const_iterator mqtt::string_collection::cend ( ) const
inline

Gets a const iterator to the end of the collection.

Returns
A const iterator to the end of the collection.

◆ empty()

bool mqtt::string_collection::empty ( ) const
inline

Determines if the collection is empty.

Returns
true if the collection is empty, false if not.

◆ size()

size_t mqtt::string_collection::size ( ) const
inline

Gets the number of strings in the collection.

Returns
The number of strings in the collection.

◆ push_back() [1/2]

void mqtt::string_collection::push_back ( const string & str)

Copies a string onto the back of the collection.

Parameters
strA string.

◆ push_back() [2/2]

void mqtt::string_collection::push_back ( string && str)

Moves a string onto the back of the collection.

Parameters
strA string.

◆ clear()

void mqtt::string_collection::clear ( )

Removes all the strings from the collection.

◆ operator[]()

const string & mqtt::string_collection::operator[] ( size_t i) const
inline

Gets the n'th string in the collection.

Parameters
iIndex to the desired string.
Returns
A const reference to the string.

◆ c_arr()

char *const * mqtt::string_collection::c_arr ( ) const
inline

Gets a pointer to an array of NUL-terminated C string pointers. This is the collection type supported by the underlying Paho C library. The returned pointer is guaranteed valid so long as the object is not updated. The return value may change if the object is modified, so the application should not cache the return value, but rather request the value when needed.

Returns
pointer to an array of NUL-terminated C string pointers of the C++ strings in the object.

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