![]() |
paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
|
#include <topic_matcher.h>
Data Structures | |
class | const_iterator |
class | iterator |
Public Types | |
using | key_type = string |
using | mapped_type = T |
using | value_type = std::pair<key_type, mapped_type> |
using | reference = value_type |
using | const_reference = const value_type& |
Public Member Functions | |
topic_matcher () | |
topic_matcher (std::initializer_list< value_type > lst) | |
void | insert (value_type &&val) |
void | insert (const value_type &val) |
iterator | find (const key_type &key) |
const_iterator | find (const key_type &key) const |
iterator | matches (const string &topic) |
const_iterator | matches (const string &topic) const |
const_iterator | end () const noexcept |
const_iterator | cend () const noexcept |
This can be used to get an iterator to all items that have a filter that matches a topic. To test against a single filter, see [TopicFilter
](crate::TopicFilter). This collection is more commonly used when there are a number of filters and each needs to be associated with a particular action or piece of data. Note, though, that a single incoming topic could match against several items in the collection. For example, the topic: data/temperature/engine
Could match against the filters: data/temperature/# data/+/engine
Thus, the collection gives an iterator for the items matching a topic.
A common use for this would be to store callbacks to process incoming messages based on topics.
This code was adapted from the Eclipse Python MQTTMatcher
class:
https://github.com/eclipse/paho.mqtt.python/blob/master/src/paho/mqtt/matcher.py
which use a prefix tree (trie) to store the values.
For example, if you had a topic_mapper<int>
and you inserted: insert({"some/random/topic", 42}) insert({"some/#", 99}) insert({"some/+/topic", 33})
The collection would be built like: "some" -> <null> "random" -> <null> "topic" -> <42> "#" -> <99> "+" -> <null> "topic" -> <33>
using mqtt::topic_matcher< T >::key_type = string |
using mqtt::topic_matcher< T >::mapped_type = T |
using mqtt::topic_matcher< T >::value_type = std::pair<key_type, mapped_type> |
using mqtt::topic_matcher< T >::reference = value_type |
using mqtt::topic_matcher< T >::const_reference = const value_type& |
|
inline |
Creates new, empty collection.
|
inline |
Creates a new collection with a list of key/value pairs.
This can be used to create a connection from a table of entries, as key/value pairs, like:
topic_matcher<int> matcher { { "#", -1 }, { "some/random/topic", 42 }, { "some/#", 99 } }
lst | The list of key/value pairs to populate the collection. |
|
inline |
Inserts a new key/value pair into the collection.
val | The value to place in the collection. |
|
inline |
Inserts a new value into the collection.
key | The topic/filter entry |
val | The value to associate with that entry. |
|
inline |
Gets a pointer to the value at the requested key.
key | The topic/filter entry to find. |
|
inline |
Gets a const pointer to the value at the requested key.
key | The topic/filter entry to find. |
|
inline |
Gets an iterator that can find the matches to the topic.
topic | The topic to search for matches. |
|
inline |
Gets a const iterator that can find the matches to the topic.
topic | The topic to search for matches. |
|
inlinenoexcept |
Gets an iterator for the end of the collection.
This simply returns an empty/null iterator which we can use to signal the end of the collection.
|
inlinenoexcept |
Gets an iterator for the end of the collection.
This simply returns an empty/null iterator which we can use to signal the end of the collection.