Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
mqtt::string_collection Class Reference

Type for a collection of topics. More...

#include <string_collection.h>

Public Types

using ptr_t = std::shared_ptr< string_collection >
 Smart/shared pointer to an object of this type.
 
using const_ptr_t = std::shared_ptr< const string_collection >
 Smart/shared pointer to a const object of this type.
 

Public Member Functions

 string_collection ()=default
 Construct an empty string collection.
 
 string_collection (const string &str)
 Construct a collection initially containing a single string. More...
 
 string_collection (string &&str)
 Construct a collection initially containing a single string. More...
 
 string_collection (const collection_type &vec)
 Constructs a string collection by copying a vector of strings. More...
 
 string_collection (collection_type &&vec)
 Constructs a string collection by moving a vector of strings. More...
 
 string_collection (const string_collection &coll)
 Copy constructor. More...
 
 string_collection (string_collection &&coll)=default
 Move constructor. More...
 
 string_collection (std::initializer_list< string > sl)
 Construct a string collection from an initialization list of strings. More...
 
 string_collection (std::initializer_list< const char * > sl)
 Construct a string collection from an initialization list of C string pointers. More...
 
string_collectionoperator= (const string_collection &coll)
 Copy assignment. More...
 
string_collectionoperator= (string_collection &&coll)=default
 Move assignment. More...
 
bool empty () const
 Determines if the collection is empty. More...
 
size_t size () const
 Gets the number of strings in the collection. More...
 
void push_back (const string &str)
 Copies a string to the back of the collection. More...
 
void push_back (string &&str)
 Moves a string to the back of the collection. More...
 
void clear ()
 Removes all the strings from the collection.
 
const string & operator[] (size_t i) const
 Gets the n'th string in the collection. More...
 
char *const * c_arr () const
 Gets a pointer to an array of NUL-terminated C string pointers. More...
 

Static Public Member Functions

static ptr_t create (const string &str)
 Create an empty string collection on the heap. More...
 
static ptr_t create (string &&str)
 Create a string collection on the heap, initially containing a single string. More...
 
static ptr_t create (const collection_type &vec)
 Creates a string collection on the heap by copying a vector of strings. More...
 
static ptr_t create (collection_type &&vec)
 Creates a string collection on the heap by copying a vector of strings. More...
 
static ptr_t create (std::initializer_list< string > sl)
 Create a string collection on the heap from an initialization list of strings. More...
 
static ptr_t create (std::initializer_list< const char * > sl)
 Create a string collection on the heap from an initialization list of C string pointers. More...
 

Detailed Description

Type for a collection of topics.

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

Constructor & Destructor Documentation

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

Construct a collection initially containing a single string.

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

Construct a collection initially containing a single string.

Parameters
strThe string
mqtt::string_collection::string_collection ( const collection_type &  vec)

Constructs a string collection by copying a vector of strings.

Parameters
vecA vector of strings.
mqtt::string_collection::string_collection ( collection_type &&  vec)

Constructs a string collection by moving a vector of strings.

Parameters
vecA vector of strings.
mqtt::string_collection::string_collection ( const string_collection coll)

Copy constructor.

Parameters
collAn existing string collection.
mqtt::string_collection::string_collection ( string_collection &&  coll)
default

Move constructor.

Parameters
collAn existing string collection.
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.
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

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 topics in the object.
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.
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.
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.
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.
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.
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.
bool mqtt::string_collection::empty ( ) const
inline

Determines if the collection is empty.

Returns
true if the collection is empty, false if not.
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.
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.
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.
void mqtt::string_collection::push_back ( const string &  str)

Copies a string to the back of the collection.

Parameters
strA string.
void mqtt::string_collection::push_back ( string &&  str)

Moves a string to the back of the collection.

Parameters
strA string.
size_t mqtt::string_collection::size ( ) const
inline

Gets the number of strings in the collection.

Returns
The number of strings in the collection.

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