scsl 0.1.1
Shimmering Clarity Standard Library
Dictionary.h
1
6
7
8#ifndef SCSL_DICTIONARY_H
9#define SCSL_DICTIONARY_H
10
11
12#include "Arena.h"
13#include "TLV.h"
14
15
16static constexpr uint8_t DICTIONARY_TAG_KEY = 1;
17static constexpr uint8_t DICTIONARY_TAG_VAL = 2;
18
19
20namespace scsl {
21
22
23/*
24 * A Dictionary is a collection of key-value pairs, similar to how
25 * a dictionary is a mapping of names to definitions.
26 */
40public:
44 Dictionary(Arena &arena) :
45 arena(arena),
46 kTag(DICTIONARY_TAG_KEY),
47 vTag(DICTIONARY_TAG_VAL)
48 {};
49
55 Dictionary(Arena &arena, uint8_t kt, uint8_t vt) :
56 arena(arena),
57 kTag(kt),
58 vTag(vt)
59 {};
60
67 bool Lookup(const char *key, uint8_t klen, TLV::Record &res);
68
84 int Set(const char *key, uint8_t klen, const char *val,
85 uint8_t vlen);
86
92 bool Contains(const char *key, uint8_t klen);
93
99 bool Delete(const char *key, uint8_t klen);
100
101
107 int DumpToFile(const char *path);
108
114 friend std::ostream &operator<<(std::ostream &os,
115 const Dictionary &dictionary);
116private:
117 uint8_t *seek(const char *key, uint8_t klen);
118
119 bool spaceAvailable(uint8_t klen, uint8_t vlen);
120
121 Arena &arena;
122 uint8_t kTag;
123 uint8_t vTag;
124};
125
126
127} // namespace scsl
128
129#endif
Memory management using an arena.
TLV.h implements basic tag-length-value records.
Definition: Arena.h:65
Definition: Dictionary.h:39
Dictionary(Arena &arena, uint8_t kt, uint8_t vt)
Definition: Dictionary.h:55
Dictionary(Arena &arena)
Definition: Dictionary.h:44
friend std::ostream & operator<<(std::ostream &os, const Dictionary &dictionary)
Definition: Dictionary.cc:134
bool Lookup(const char *key, uint8_t klen, TLV::Record &res)
Definition: Dictionary.cc:14
bool Contains(const char *key, uint8_t klen)
Definition: Dictionary.cc:91
int Set(const char *key, uint8_t klen, const char *val, uint8_t vlen)
Definition: Dictionary.cc:37
bool Delete(const char *key, uint8_t klen)
Definition: Dictionary.cc:98
int DumpToFile(const char *path)
Definition: Dictionary.cc:161
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:37
Definition: TLV.h:39