Arduino KVComm  master
Key-Value pair communication library for Arduino
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
KV_Parser Class Reference

A parser for dictionaries generated by the KV_Builder. More...

#include <KVComm/KV_Parser.hpp>

Collaboration diagram for KV_Parser:

Classes

struct  strcmp
 Functor to compare the map keys. More...
 

Public Member Functions

 KV_Parser (const uint8_t *buffer, size_t length)
 Parse a raw buffer into a new KV_Parser. More...
 
bool contains (const char *key) const
 Check if the dictionary contains an element with the given key. More...
 
KV getElement (const char *key) const
 Get the element with the given key. More...
 
KV operator[] (const char *key) const
 Get the element with the given key. More...
 
map_t::iterator begin ()
 Begin iterator over all entries in the dictionary. More...
 
map_t::const_iterator begin () const
 Begin iterator over all entries in the dictionary. More...
 
map_t::iterator end ()
 End iterator over all entries in the dictionary. More...
 
map_t::const_iterator end () const
 End iterator over all entries in the dictionary. More...
 

Private Types

using KV = KV_Iterator::KV
 
using map_t = std::map< const char *, KV, strcmp >
 

Private Member Functions

map_t parse (const uint8_t *buffer, size_t length)
 Parse the buffer for key-value pairs, save their keys, type, and size in an std::map, together with a pointer to the actual value. More...
 

Private Attributes

map_t parseResult {}
 

Detailed Description

A parser for dictionaries generated by the KV_Builder.

Intended to run on your computer, not on the Arduino, because it uses std::map, dynamic memory allocation and exceptions.

Definition at line 30 of file KV_Parser.hpp.

Member Typedef Documentation

◆ KV

using KV = KV_Iterator::KV
private

Definition at line 36 of file KV_Parser.hpp.

◆ map_t

using map_t = std::map<const char *, KV, strcmp>
private

Definition at line 37 of file KV_Parser.hpp.

Constructor & Destructor Documentation

◆ KV_Parser()

KV_Parser ( const uint8_t *  buffer,
size_t  length 
)
inline

Parse a raw buffer into a new KV_Parser.

Parameters
bufferA pointer to the raw buffer containing the dictionary, as generated by a KV_Builder.
Only the pointer is saved, no copy is made of the actual buffer, so the lifetime of the buffer must be longer than the parser and the accessors.
lengthThe length of the dictionary in the buffer (in bytes).

Definition at line 54 of file KV_Parser.hpp.

Member Function Documentation

◆ contains()

bool contains ( const char *  key) const
inline

Check if the dictionary contains an element with the given key.

Parameters
keyThe key of the element to check.
Return values
trueThe dictionary contains an element with the given key.
falseOtherwise.

Definition at line 67 of file KV_Parser.hpp.

◆ getElement()

KV getElement ( const char *  key) const
inline

Get the element with the given key.

Parameters
keyThe key of the element to retreive.
Returns
The element with the given key.
Exceptions
std::out_of_rangeThere is no element with the given key.

Definition at line 80 of file KV_Parser.hpp.

◆ operator[]()

KV operator[] ( const char *  key) const
inline

Get the element with the given key.

Parameters
keyThe key of the element to retreive.
Returns
The element with the given key.
Exceptions
std::out_of_rangeThere is no element with the given key.

Definition at line 82 of file KV_Parser.hpp.

◆ begin() [1/2]

map_t::iterator begin ( )
inline

Begin iterator over all entries in the dictionary.

Definition at line 84 of file KV_Parser.hpp.

◆ begin() [2/2]

map_t::const_iterator begin ( ) const
inline

Begin iterator over all entries in the dictionary.

Definition at line 86 of file KV_Parser.hpp.

◆ end() [1/2]

map_t::iterator end ( )
inline

End iterator over all entries in the dictionary.

Definition at line 88 of file KV_Parser.hpp.

◆ end() [2/2]

map_t::const_iterator end ( ) const
inline

End iterator over all entries in the dictionary.

Definition at line 90 of file KV_Parser.hpp.

◆ parse()

KV_Parser::map_t parse ( const uint8_t *  buffer,
size_t  length 
)
private

Parse the buffer for key-value pairs, save their keys, type, and size in an std::map, together with a pointer to the actual value.

Parameters
bufferA pointer to the raw buffer containing the dictionary.
lengthThe length of the dictionary in the buffer (in bytes).
Returns
A map mapping the keys to the key-value dictionary entries.

Definition at line 9 of file KV_Parser.cpp.

Member Data Documentation

◆ parseResult

map_t parseResult {}
private

Definition at line 39 of file KV_Parser.hpp.


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