scsl 1.0.1
Shimmering Clarity Standard Library
Loading...
Searching...
No Matches
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
49public:
53 Dictionary(Arena &arena) :
54 arena(arena),
55 kTag(DICTIONARY_TAG_KEY),
56 vTag(DICTIONARY_TAG_VAL)
57 {};
58
64 Dictionary(Arena &arena, uint8_t kt, uint8_t vt) :
65 arena(arena),
66 kTag(kt),
67 vTag(vt)
68 {};
69
76 bool Lookup(const char *key, uint8_t klen, TLV::Record &res);
77
93 int Set(const char *key, uint8_t klen, const char *val,
94 uint8_t vlen);
95
101 bool Contains(const char *key, uint8_t klen);
102
108 bool Delete(const char *key, uint8_t klen);
109
110
116 int DumpToFile(const char *path);
117
123 friend std::ostream &operator<<(std::ostream &os,
124 const Dictionary &dictionary);
125private:
126 uint8_t *seek(const char *key, uint8_t klen);
127
128 bool spaceAvailable(uint8_t klen, uint8_t vlen);
129
130 Arena &arena;
131 uint8_t kTag;
132 uint8_t vTag;
133};
134
135
136} // namespace scsl
137
138#endif
Memory management using an arena.
TLV.h implements basic tag-length-value records.
Fixed, pre-allocated memory.
Definition Arena.h:74
Key-value store on top of Arena and TLV::Record.
Definition Dictionary.h:48
Dictionary(Arena &arena, uint8_t kt, uint8_t vt)
Definition Dictionary.h:64
Dictionary(Arena &arena)
Definition Dictionary.h:53
friend std::ostream & operator<<(std::ostream &os, const Dictionary &dictionary)
bool Lookup(const char *key, uint8_t klen, TLV::Record &res)
bool Contains(const char *key, uint8_t klen)
int Set(const char *key, uint8_t klen, const char *val, uint8_t vlen)
bool Delete(const char *key, uint8_t klen)
int DumpToFile(const char *path)
scsl is the top-level namespace containing all the code in this library.
Definition scsl.h:43
Tag-length-value record with single byte tags and lengths.
Definition TLV.h:42