sentence¶
-
struct
mikrotik::api::sentence¶ Contains a command with optional additional words sent to the MikroTik device.
A sentence is a command followed by zero or more attribute or query words and is terminated by the empty word. A sentence is sent to the MikroTik device which processes it when the empty word is received.
A valid sentence matches the following EBNF grammar:
For the command, attribute, and query grammars see their documentation.sentence ::= command, [ additional words ]; additional words ::= { attribute } | { query } ;
- Since
v1.0.0
Public Functions
-
sentence() = default¶ Constructs the empty sentence.
Creates the empty sentence which is always ignored when sent.
- Since
v1.1.0
-
sentence(command cmd)¶ Constructs a sentence from a command.
Constructs a sentence from a command with zero attributes. Useful for use with the DSL.
- Since
v1.0.0
- Parameters
cmd: The command to create the sentence from
-
sentence(std::initializer_list<std::string> words)¶ Creates a sentence from a sequence of words.
Takes an initializer_list of strings and interprets them as a sequence of words to create a sentence from. The first word is the command, which must be a valid MikroTik API command word, as the following words must be valid MikroTik API attribute or query words. All words are sent verbatim.
- Since
v1.0.0
- Parameters
words: The sequence of words to create a sentence from
-
template<class
It>sentence(It beg, It end)¶ Creates a sentence from an iterator provided range of words.
Essentially does the same thing as sentence(std::initializer_list<std::string>) but with an iterator pair.
Starts reading from
begand copies all words until it reachesend. The value pointed to bybegis the command and it must be a valid MikroTik API command word, as the following words must be valid MikroTik API attribute or query words. All words are sent verbatim.- Since
v1.0.0
- Template Parameters
It: The type of the given iterator
- Parameters
beg: The iterator pointing at the beginning of the rangeend: The iterator pointing past the end of the range
-
sentence &
operator[](attribute attr) &&¶ Adds an attribute to the sentence.
As an attribute may also be constructed implicitly from a string the following two invocations are usable:
They of course may be chained.sentence snt{ // ... }; snt = snt["name-without-value"]; snt = snt[{"name-with-value", "value"}];
- Return
The modified sentence
- Since
v1.0.0
- Parameters
attr: The attribute to add.
-
sentence
operator[](attribute attr) const &¶ Adds an attribute to the sentence.
As an attribute may also be constructed implicitly from a string the following two invocations are usable:
They of course may be chained.sentence snt{ // ... }; snt = snt["name-without-value"]; snt = snt[{"name-with-value", "value"}];
- Return
The modified sentence
- Since
v1.0.0
- Parameters
attr: The attribute to add.
-
sentence &
operator()(query q) &&¶ Adds an query to the sentence.
As a query may also be constructed implicitly from a string the following two invocations are usable:
They of course may be chained.sentence snt{ // ... }; snt = snt("name-without-value"); // this creates ?name-without-value snt = snt({"name-with-value", "value"}); // ?name-with-value=value
- Return
The modified sentence
- Since
v1.0.0
- Parameters
q: The query to add.
-
sentence
operator()(query q) const &¶ Adds an query to the sentence.
As a query may also be constructed implicitly from a string the following two invocations are usable:
They of course may be chained.sentence snt{ // ... }; snt = snt("name-without-value"); // this creates ?name-without-value snt = snt({"name-with-value", "value"}); // ?name-with-value=value
- Return
The modified sentence
- Since
v1.0.0
- Parameters
q: The query to add.
-
void
add_word(std::string_view word)¶ Adds a word to the sentence as is.
- Since
v1.0.0
- Parameters
word: The word to add to the sentence
-
const std::vector<std::string> &
words() const¶ Returns the current words of the sentence.
- Return
The words stored by the sentence