PerSt Pile   version 0.0.1
Persistent storage pile used for storing key/value pairs
perst_interface.h
1 
10 #ifndef GUARD_PERST_INTERFACE_H_INCLUDE
11 #define GUARD_PERST_INTERFACE_H_INCLUDE
12 
13 #include <perst/perst-config.h>
14 #include <stdint.h>
15 
17 class PERST_EXPORT PerstInterface {
18 
19 public:
20 
22  virtual bool
23  beginGroup (
24  const PERST_STRING & name) = 0;
25 
27  virtual bool
28  endGroup (
29  const PERST_STRING & name = "") = 0;
30 
32  virtual bool
33  beginWriteArray (
34  const PERST_STRING & name,
35  int predicted_count = -1) = 0;
36 
38  virtual int
39  beginReadArray (
40  const PERST_STRING & name) = 0;
41 
43  virtual bool
44  endArray (
45  const PERST_STRING & name = "") = 0;
46 
48  virtual int
49  arrayIndex () const = 0;
50 
52  virtual bool
53  setArrayIndex (
54  int index) = 0;
55 
57  virtual PERST_STRING
58  group () const = 0;
59 
61  virtual PERST_SLIST
62  groupPath () const = 0;
63 
65  virtual bool
66  hasKey (
67  const PERST_STRING & name) = 0;
68 
70  virtual bool
71  hasKey (
72  const PERST_SLIST & name) = 0;
73 
74 
76  virtual PERST_STRING
77  valueS (
78  const PERST_STRING & name) = 0;
79 
81  virtual PERST_SLIST
82  valueSList (
83  const PERST_STRING & name) = 0;
84 
86  virtual int64_t
87  valueInt (
88  const PERST_STRING & name) = 0;
89 
91  virtual uint64_t
92  valueUInt (
93  const PERST_STRING & name) = 0;
94 
96  virtual double
97  valueDbl (
98  const PERST_STRING & name) = 0;
99 
100 
102  inline PERST_STRING
104  const PERST_STRING & name,
105  const PERST_STRING & default_val) {
106  if (hasKey (name)) return valueS (name);
107  else return default_val;
108  }
109 
111  inline PERST_SLIST
113  const PERST_STRING & name,
114  const PERST_SLIST & default_val) {
115  if (hasKey (name)) return valueSList (name);
116  else return default_val;
117  }
118 
120  inline int64_t
122  const PERST_STRING & name,
123  int64_t default_val) {
124  if (hasKey (name)) return valueInt (name);
125  else return default_val;
126  }
127 
129  inline uint64_t
131  const PERST_STRING & name,
132  uint64_t default_val) {
133  if (hasKey (name)) return valueUInt (name);
134  else return default_val;
135  }
136 
138  inline double
140  const PERST_STRING & name,
141  double default_val) {
142  if (hasKey (name)) return valueDbl (name);
143  else return default_val;
144  }
145 
146 
148  virtual bool
149  setValue (
150  const PERST_STRING & name,
151  const PERST_STRING & value) = 0;
152 
154  virtual bool
155  setValue (
156  const PERST_STRING & name,
157  const PERST_SLIST & value) = 0;
158 
160  virtual bool
161  setValue (
162  const PERST_STRING & name,
163  int64_t value) = 0;
164 
166  virtual bool
167  setValue (
168  const PERST_STRING & name,
169  uint64_t value) = 0;
170 
172  virtual bool
174  const PERST_STRING & name,
175  int value) {
176  return setValue (name, (int64_t)value);
177  }
178 
180  virtual bool
181  setValue (
182  const PERST_STRING & name,
183  double value) = 0;
184 };
185 
186 #endif // GUARD_PERST_INTERFACE_H_INCLUDE
double valueDbl(const PERST_STRING &name, double default_val)
Get the real value for a key; the value type MUST be real.
Definition: perst_interface.h:139
Interface class for persistent storage.
Definition: perst_interface.h:17
PERST_SLIST valueSList(const PERST_STRING &name, const PERST_SLIST &default_val)
Get the string list for a key; the value type MUST be an array of strings.
Definition: perst_interface.h:112
uint64_t valueUInt(const PERST_STRING &name, uint64_t default_val)
Get the integer value for a key; the value type MUST be integer.
Definition: perst_interface.h:130
int64_t valueInt(const PERST_STRING &name, int64_t default_val)
Get the integer value for a key; the value type MUST be integer.
Definition: perst_interface.h:121
virtual bool setValue(const PERST_STRING &name, int value)
Set the integer value for a key.
Definition: perst_interface.h:173
PERST_STRING valueS(const PERST_STRING &name, const PERST_STRING &default_val)
Get the string value for a key; the value type MUST be string.
Definition: perst_interface.h:103