scsl 0.2.4
Shimmering Clarity Standard Library
Dictionary.h
Go to the documentation of this file.
1
23
24
25#ifndef SCSL_DICTIONARY_H
26#define SCSL_DICTIONARY_H
27
28
29#include <cstdint>
30
31#include "Arena.h"
32#include "TLV.h"
33
34
35static constexpr uint8_t DICTIONARY_TAG_KEY = 1;
36static constexpr uint8_t DICTIONARY_TAG_VAL = 2;
37
38
39namespace scsl {
40
41
42/*
43 * A Dictionary is a collection of key-value pairs, similar to how
44 * a dictionary is a mapping of names to definitions.
45 */
53public:
57 Dictionary(Arena &arena) :
58 arena(arena),
59 kTag(DICTIONARY_TAG_KEY),
60 vTag(DICTIONARY_TAG_VAL)
61 {};
62
68 Dictionary(Arena &arena, uint8_t kt, uint8_t vt) :
69 arena(arena),
70 kTag(kt),
71 vTag(vt)
72 {};
73
80 bool Lookup(const char *key, uint8_t klen, TLV::Record &res);
81
97 int Set(const char *key, uint8_t klen, const char *val,
98 uint8_t vlen);
99
105 bool Contains(const char *key, uint8_t klen);
106
112 bool Delete(const char *key, uint8_t klen);
113
114
120 int DumpToFile(const char *path);
121
127 friend std::ostream &operator<<(std::ostream &os,
128 const Dictionary &dictionary);
129private:
130 uint8_t *seek(const char *key, uint8_t klen);
131
132 bool spaceAvailable(uint8_t klen, uint8_t vlen);
133
134 Arena &arena;
135 uint8_t kTag;
136 uint8_t vTag;
137};
138
139
140} // namespace scsl
141
142#endif
Memory management using an arena.
TLV.h implements basic tag-length-value records.
Definition: Arena.h:80
Definition: Dictionary.h:52
Dictionary(Arena &arena, uint8_t kt, uint8_t vt)
Definition: Dictionary.h:68
Dictionary(Arena &arena)
Definition: Dictionary.h:57
friend std::ostream & operator<<(std::ostream &os, const Dictionary &dictionary)
Definition: Dictionary.cc:157
bool Lookup(const char *key, uint8_t klen, TLV::Record &res)
Definition: Dictionary.cc:37
bool Contains(const char *key, uint8_t klen)
Definition: Dictionary.cc:114
int Set(const char *key, uint8_t klen, const char *val, uint8_t vlen)
Definition: Dictionary.cc:60
bool Delete(const char *key, uint8_t klen)
Definition: Dictionary.cc:121
int DumpToFile(const char *path)
Definition: Dictionary.cc:184
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:43
Definition: TLV.h:40