@@ -35,27 +35,38 @@ namespace mqtt {
35
35
// ///////////////////////////////////////////////////////////////////////////
36
36
37
37
/* *
38
- * Type for a collection of topics.
39
- * This acts like a collection of strings but carries an array of pointers
40
- * to the C strings for easy interactions with the Paho C library.
38
+ * Type for a collection of strings, such as MQTT topics.
39
+ *
40
+ * This acts like a standard collection of strings but carries an array of
41
+ * pointers to the C strings for easy interactions with the Paho C library.
41
42
*/
42
43
class string_collection
43
44
{
45
+ public:
44
46
/* * The type for the collection of strings */
45
47
using collection_type = std::vector<string>;
48
+ /* * Iterator over const items */
49
+ using const_iterator = collection_type::const_iterator;
50
+
51
+ /* * Smart/shared pointer to an object of this type */
52
+ using ptr_t = std::shared_ptr<string_collection>;
53
+ /* * Smart/shared pointer to a const object of this type */
54
+ using const_ptr_t = std::shared_ptr<const string_collection>;
55
+
56
+ private:
46
57
/* * The type for the array of C pointers */
47
58
using c_arr_type = std::vector<const char *>;
48
59
49
60
/* *
50
- * The collection of strings for the topics .
61
+ * The collection of strings.
51
62
*/
52
63
collection_type coll_;
53
64
/* *
54
- * A collection of pointers to NUL-terminated C strings for the topics .
65
+ * A collection of pointers to NUL-terminated C strings.
55
66
* This is what is required by the Paho C library, and thus the lifetime
56
67
* of the pointers will remain consistent with the lifetime of the
57
- * object. The value is kept consistent with the current topics and
58
- * updated whenever topics are added or removed.
68
+ * object. The value is kept consistent with the current stringss and
69
+ * updated whenever strings are added or removed.
59
70
*/
60
71
c_arr_type cArr_;
61
72
/* *
@@ -66,11 +77,6 @@ class string_collection
66
77
void update_c_arr ();
67
78
68
79
public:
69
- /* * Smart/shared pointer to an object of this type */
70
- using ptr_t = std::shared_ptr<string_collection>;
71
- /* * Smart/shared pointer to a const object of this type */
72
- using const_ptr_t = std::shared_ptr<const string_collection>;
73
-
74
80
/* *
75
81
* Construct an empty string collection.
76
82
*/
@@ -104,7 +110,7 @@ class string_collection
104
110
* Move constructor.
105
111
* @param coll An existing string collection.
106
112
*/
107
- string_collection (string_collection&& coll) = default ;
113
+ string_collection (string_collection&& coll) =default ;
108
114
/* *
109
115
* Construct a string collection from an initialization list of strings.
110
116
* @param sl An initialization list of strings.
@@ -180,7 +186,27 @@ class string_collection
180
186
* @param coll A string collection
181
187
* @return A reference to this collection.
182
188
*/
183
- string_collection& operator =(string_collection&& coll) = default ;
189
+ string_collection& operator =(string_collection&& coll) =default ;
190
+ /* *
191
+ * Gets a const iterator to the begining of the collecion.
192
+ * @return A const iterator to the begining of the collecion.
193
+ */
194
+ const_iterator begin () const { return coll_.begin (); }
195
+ /* *
196
+ * Gets a const iterator to the end of the collecion.
197
+ * @return A const iterator to the end of the collecion.
198
+ */
199
+ const_iterator end () const { return coll_.end (); }
200
+ /* *
201
+ * Gets a const iterator to the begining of the collecion.
202
+ * @return A const iterator to the begining of the collecion.
203
+ */
204
+ const_iterator cbegin () const { return coll_.cbegin (); }
205
+ /* *
206
+ * Gets a const iterator to the end of the collecion.
207
+ * @return A const iterator to the end of the collecion.
208
+ */
209
+ const_iterator cend () const { return coll_.cend (); }
184
210
/* *
185
211
* Determines if the collection is empty.
186
212
* @return @em true if the collection is empty, @em false if not.
@@ -192,12 +218,12 @@ class string_collection
192
218
*/
193
219
size_t size () const { return coll_.size (); }
194
220
/* *
195
- * Copies a string to the back of the collection.
221
+ * Copies a string onto the back of the collection.
196
222
* @param str A string.
197
223
*/
198
224
void push_back (const string& str);
199
225
/* *
200
- * Moves a string to the back of the collection.
226
+ * Moves a string onto the back of the collection.
201
227
* @param str A string.
202
228
*/
203
229
void push_back (string&& str);
@@ -219,21 +245,15 @@ class string_collection
219
245
* modified, so the application should not cache the return value, but
220
246
* rather request the value when needed.
221
247
* @return pointer to an array of NUL-terminated C string pointers of
222
- * the topics in the object.
248
+ * the C++ strings in the object.
223
249
*
224
250
*/
225
251
char * const * c_arr () const { return (char * const *) cArr_.data (); }
226
-
227
- using const_iterator = collection_type::const_iterator;
228
-
229
- const_iterator begin () const { return coll_.begin (); }
230
-
231
- const_iterator end () const { return coll_.end (); }
232
252
};
233
253
234
254
// ///////////////////////////////////////////////////////////////////////////
235
255
236
- /* * Smart/shared pointer to a topic collection */
256
+ /* * Smart/shared pointer to a string collection */
237
257
using string_collection_ptr = string_collection::ptr_t ;
238
258
239
259
/* * Smart/shared pointer to a const string_collection */
@@ -303,7 +323,7 @@ class name_value_collection
303
323
* Move constructor.
304
324
* @param other Another collection of name/value pairs
305
325
*/
306
- name_value_collection (name_value_collection&& other) = default ;
326
+ name_value_collection (name_value_collection&& other) =default ;
307
327
/* *
308
328
* Constructs the collection with an initializer list.
309
329
*
@@ -330,7 +350,7 @@ class name_value_collection
330
350
* Move constructor.
331
351
* @param other Another collection of name/value pairs
332
352
*/
333
- name_value_collection& operator =(name_value_collection&& other) = default ;
353
+ name_value_collection& operator =(name_value_collection&& other) =default ;
334
354
/* *
335
355
* Determines if the collection is empty.
336
356
* @return @em true if the container is empty, @em false if it contains
0 commit comments