24 #ifndef __mqtt_string_collection_h
25 #define __mqtt_string_collection_h
43 using collection_type = std::vector<string>;
45 using c_arr_type = std::vector<const char*>;
50 collection_type coll_;
68 using ptr_t = std::shared_ptr<string_collection>;
122 return std::make_shared<string_collection>(str);
131 return std::make_shared<string_collection>(str);
139 return std::make_shared<string_collection>(vec);
148 return std::make_shared<string_collection>(vec);
157 return std::make_shared<string_collection>(sl);
166 return std::make_shared<string_collection>(sl);
186 bool empty()
const {
return coll_.empty(); }
191 size_t size()
const {
return coll_.size(); }
211 const string&
operator[](
size_t i)
const {
return coll_[i]; }
224 char*
const*
c_arr()
const {
return (
char*
const *) cArr_.data(); }
240 #endif // __mqtt_string_collection_h
std::shared_ptr< string_collection > ptr_t
Smart/shared pointer to an object of this type.
Definition: string_collection.h:68
size_t size() const
Gets the number of strings in the collection.
Definition: string_collection.h:191
Basic types and type conversions for the Paho MQTT C++ library.
static ptr_t create(collection_type &&vec)
Creates a string collection on the heap by copying a vector of strings.
Definition: string_collection.h:147
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.
Definition: string_collection.h:165
void push_back(const string &str)
Copies a string to the back of the collection.
bool empty() const
Determines if the collection is empty.
Definition: string_collection.h:186
string_collection & operator=(const string_collection &coll)
Copy assignment.
static ptr_t create(const collection_type &vec)
Creates a string collection on the heap by copying a vector of strings.
Definition: string_collection.h:138
Type for a collection of topics.
Definition: string_collection.h:40
static ptr_t create(std::initializer_list< string > sl)
Create a string collection on the heap from an initialization list of strings.
Definition: string_collection.h:156
char *const * c_arr() const
Gets a pointer to an array of NUL-terminated C string pointers.
Definition: string_collection.h:224
static ptr_t create(string &&str)
Create a string collection on the heap, initially containing a single string.
Definition: string_collection.h:130
std::shared_ptr< const string_collection > const_ptr_t
Smart/shared pointer to a const object of this type.
Definition: string_collection.h:70
static ptr_t create(const string &str)
Create an empty string collection on the heap.
Definition: string_collection.h:121
string_collection()=default
Construct an empty string collection.
const string & operator[](size_t i) const
Gets the n'th string in the collection.
Definition: string_collection.h:211
void clear()
Removes all the strings from the collection.