scsl 1.0.1
Shimmering Clarity Standard Library
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
scsl::Dictionary Class Reference

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Dictionary() [1/2]

scsl::Dictionary::Dictionary ( Arena arena)
inline

A Dictionary can be initialized with just a backing Arena.

Parameters
arenaThe backing arena for the Dictionary.

◆ Dictionary() [2/2]

scsl::Dictionary::Dictionary ( Arena arena,
uint8_t  kt,
uint8_t  vt 
)
inline

A Dictionary can also be configured with custom key and value types.

Parameters
arenaThe backing arena for the Dictionary.
ktThe value to use for key tags.
vtThe value to use for val tags.

Member Function Documentation

◆ Contains()

bool scsl::Dictionary::Contains ( const char *  key,
uint8_t  klen 
)

Contains checks the dictionary to see if it contains a given key.

Parameters
keyThe key to look up.
klenThe length of the key.
Returns
True if the key is in the Dictionary, otherwise false.

◆ Delete()

bool scsl::Dictionary::Delete ( const char *  key,
uint8_t  klen 
)

Delete removes the key from the Dictionary.

Parameters
keyThe key to look up.
klenThe length of the key.
Returns
True if the key was removed, otherwise false.

◆ DumpToFile()

int scsl::Dictionary::DumpToFile ( const char *  path)

DumpToFile is a wrapper aorund a call to Arena::Write on the underlying Arena.

Parameters
pathThe path to the dumped file.
Returns
0 on success, -1 on failure.

◆ Lookup()

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.

Parameters
keyThe key to search for.
klenThe length of the key.
resThe TLV::Record to store the value in;
Returns
True if the key was found, false otherwise.

◆ Set()

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.

Warning
If the key is present, but there isn't enough space to store the new Val, the Dictionary will not contain either key or value.
Parameters
keyThe key to associate.
klenThe length of the key.
valThe value to associate.
vlenThe length of the value.
Returns
Returns 0 on success and -1 on failure.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Dictionary dictionary 
)
friend

operator<< writes the key pairs phonto the output stream.

Parameters
osThe output stream to write to.
dictionaryThe dictionary to write out.
Returns
The output stream is returned.

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