|
scsl 1.0.1
Shimmering Clarity Standard Library
|
Key-value store on top of Arena and TLV::Record. More...
#include <Dictionary.h>
Public Member Functions | |
| Dictionary (Arena &arena) | |
| Dictionary (Arena &arena, uint8_t kt, uint8_t vt) | |
| bool | Lookup (const char *key, uint8_t klen, TLV::Record &res) |
| int | Set (const char *key, uint8_t klen, const char *val, uint8_t vlen) |
| bool | Contains (const char *key, uint8_t klen) |
| bool | Delete (const char *key, uint8_t klen) |
| int | DumpToFile (const char *path) |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Dictionary &dictionary) |
Key-value store on top of Arena and TLV::Record.
Keys and vales are stored as sequential pairs of TLV records; they are expected to contain string values but this isn't necessarily the case. The tag values default to a tag of DICTIONARY_TAG_KEY, and values to a tag of DICTIONARY_TAG_VAL.
|
inline |
A Dictionary can be initialized with just a backing Arena.
| arena | The backing arena for the Dictionary. |
|
inline |
A Dictionary can also be configured with custom key and value types.
| arena | The backing arena for the Dictionary. |
| kt | The value to use for key tags. |
| vt | The value to use for val tags. |
| bool scsl::Dictionary::Contains | ( | const char * | key, |
| uint8_t | klen | ||
| ) |
Contains checks the dictionary to see if it contains a given key.
| key | The key to look up. |
| klen | The length of the key. |
| bool scsl::Dictionary::Delete | ( | const char * | key, |
| uint8_t | klen | ||
| ) |
Delete removes the key from the Dictionary.
| key | The key to look up. |
| klen | The length of the key. |
| int scsl::Dictionary::DumpToFile | ( | const char * | path | ) |
DumpToFile is a wrapper aorund a call to Arena::Write on the underlying Arena.
| path | The path to the dumped file. |
| bool scsl::Dictionary::Lookup | ( | const char * | key, |
| uint8_t | klen, | ||
| TLV::Record & | res | ||
| ) |
Lookup checks to see if the Dictionary has a value under key.
| key | The key to search for. |
| klen | The length of the key. |
| res | The TLV::Record to store the value in; |
| int scsl::Dictionary::Set | ( | const char * | key, |
| uint8_t | klen, | ||
| const char * | val, | ||
| uint8_t | vlen | ||
| ) |
Set adds a pairing for key → value in the Dictionary.
If the key is already present in the dictionary, both the key and value are deleted, and a new pair is insert.
| key | The key to associate. |
| klen | The length of the key. |
| val | The value to associate. |
| vlen | The length of the value. |
|
friend |
operator<< writes the key pairs phonto the output stream.
| os | The output stream to write to. |
| dictionary | The dictionary to write out. |