Stgs Pile   version 0.0.1
Stgs pile.
stgs.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_STGS_H_INCLUDE
11 #define GUARD_STGS_H_INCLUDE
12 
13 #undef PERST_STRING
14 #define PERST_STRING QString
15 
16 #include <stgs/stgs-config.h>
17 #include <perst/perst_interface.h>
18 
19 #include <QDate>
20 #include <QDateTime>
21 #include <QTime>
22 
23 QT_BEGIN_NAMESPACE
24 class QSettings;
25 QT_END_NAMESPACE
26 
28 class STGS_EXPORT Stgs : public PerstInterface {
29 
30  int version_;
31  int array_index_;
32  QSettings * impl_;
33 
34 public:
35 
37  Stgs ();
38 
40  virtual ~Stgs();
41 
43  void
44  setVersion (
45  int version);
46 
48  int
49  version () const {
50  return version_;
51  }
52 
53 
55  virtual bool
56  beginGroup (
57  const PERST_STRING & name);
58 
60  virtual bool
61  endGroup (
62  const PERST_STRING & name = "");
63 
65  virtual bool
66  beginWriteArray (
67  const PERST_STRING & name,
68  int predicted_count = -1);
69 
71  virtual int
72  beginReadArray (
73  const PERST_STRING & name);
74 
76  virtual bool
77  endArray (
78  const PERST_STRING & name = "");
79 
81  virtual int
82  arrayIndex () const;
83 
85  virtual bool
86  setArrayIndex (
87  int index);
88 
90  virtual PERST_STRING
91  group () const;
92 
94  virtual PERST_SLIST
95  groupPath () const;
96 
98  virtual bool
99  hasKey (
100  const PERST_STRING & name);
101 
103  virtual bool
104  hasKey (
105  const PERST_SLIST & name);
106 
107 
109  virtual PERST_STRING
110  valueS (
111  const PERST_STRING & name);
112 
114  virtual PERST_SLIST
115  valueSList (
116  const PERST_STRING & name);
117 
119  virtual int64_t
120  valueInt (
121  const PERST_STRING & name);
122 
124  virtual uint64_t
125  valueUInt (
126  const PERST_STRING & name);
127 
129  virtual double
130  valueDbl (
131  const PERST_STRING & name);
132 
133 
135  inline PERST_STRING
137  const PERST_STRING & name,
138  const PERST_STRING & default_val) {
139  if (hasKey (name)) return valueS (name);
140  else return default_val;
141  }
142 
144  inline PERST_SLIST
146  const PERST_STRING & name,
147  const PERST_SLIST & default_val) {
148  if (hasKey (name)) return valueSList (name);
149  else return default_val;
150  }
151 
153  inline int64_t
155  const PERST_STRING & name,
156  int64_t default_val) {
157  if (hasKey (name)) return valueInt (name);
158  else return default_val;
159  }
160 
162  inline uint64_t
164  const PERST_STRING & name,
165  uint64_t default_val) {
166  if (hasKey (name)) return valueUInt (name);
167  else return default_val;
168  }
169 
171  inline double
173  const PERST_STRING & name,
174  double default_val) {
175  if (hasKey (name)) return valueDbl (name);
176  else return default_val;
177  }
178 
179 
181  virtual bool
182  setValue (
183  const PERST_STRING & name,
184  const PERST_STRING & value);
185 
187  virtual bool
188  setValue (
189  const PERST_STRING & name,
190  const PERST_SLIST & value);
191 
193  virtual bool
194  setValue (
195  const PERST_STRING & name,
196  int64_t value);
197 
199  virtual bool
200  setValue (
201  const PERST_STRING & name,
202  uint64_t value);
203 
205  virtual bool
207  const PERST_STRING & name,
208  int value) {
209  return setValue (name, (int64_t)value);
210  }
211 
213  virtual bool
214  setValue (
215  const PERST_STRING & name,
216  double value);
217 
218 
219 
220 
221  // not part of the PerstInterface
222 
223 
224 
226  inline QByteArray
228  const PERST_STRING & name,
229  const QByteArray & default_val) {
230  if (hasKey (name)) return valueBA (name);
231  else return default_val;
232  }
233 
234  QByteArray
235  valueBA (
236  const PERST_STRING & name);
237 
239  virtual bool
240  setValue (
241  const PERST_STRING & name,
242  const QByteArray & value);
243 
244 
246  inline bool
248  const PERST_STRING & name,
249  bool default_val) {
250  if (hasKey (name)) return valueB (name);
251  else return default_val;
252  }
253 
254  bool
255  valueB (
256  const PERST_STRING & name);
257 
259  virtual bool
260  setValue (
261  const PERST_STRING & name,
262  bool value);
263 
264 
265 
267  inline QDate
269  const PERST_STRING & name,
270  const QDate & default_val) {
271  if (hasKey (name)) return valueDate (name);
272  else return default_val;
273  }
274 
276  inline QDate
278  const PERST_STRING & name) {
279  return QDate::fromString (valueS (name), Qt::ISODate);
280  }
282  virtual bool
284  const PERST_STRING & name,
285  const QDate & value) {
286  return Stgs::setValue(name, value.toString (Qt::ISODate));
287  }
288 
289 
291  inline QTime
293  const PERST_STRING & name,
294  const QTime & default_val) {
295  if (hasKey (name)) return valueTime (name);
296  else return default_val;
297  }
298 
300  inline QTime
302  const PERST_STRING & name) {
303  return QTime::fromString (valueS (name), Qt::ISODate);
304  }
306  virtual bool
308  const PERST_STRING & name,
309  const QTime & value) {
310  return Stgs::setValue(name, value.toString (Qt::ISODate));
311  }
312 
313 
315  inline QDateTime
317  const PERST_STRING & name,
318  const QDateTime & default_val) {
319  if (hasKey (name)) return valueDateTime (name);
320  else return default_val;
321  }
322 
324  inline QDateTime
326  const PERST_STRING & name) {
327  return QDateTime::fromString (valueS (name), Qt::ISODate);
328  }
330  virtual bool
332  const PERST_STRING & name,
333  const QDateTime & value) {
334  return Stgs::setValue(name, value.toString (Qt::ISODate));
335  }
336 
337 protected:
338 
339 private:
340 
341 };
342 
343 #endif // GUARD_STGS_H_INCLUDE
QDateTime valueDateTime(const PERST_STRING &name)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:325
bool valueB(const PERST_STRING &name, bool default_val)
Get the real value for a key; the value type MUST be real.
Definition: stgs.h:247
QByteArray valueBA(const PERST_STRING &name, const QByteArray &default_val)
Get the real value for a key; the value type MUST be real.
Definition: stgs.h:227
QDate valueDate(const PERST_STRING &name)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:277
int version() const
Tell current version.
Definition: stgs.h:49
virtual bool setValue(const PERST_STRING &name, const QDateTime &value)
Set the real value for a key.
Definition: stgs.h:331
virtual bool setValue(const PERST_STRING &name, const PERST_STRING &value)
Set the string value for a key.
Definition: stgs.cc:213
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: stgs.h:163
virtual bool setValue(const PERST_STRING &name, int value)
Set the integer value for a key.
Definition: stgs.h:206
QDateTime valueDateTime(const PERST_STRING &name, const QDateTime &default_val)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:316
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: stgs.h:154
brief description
Definition: stgs.h:28
QDate valueDate(const PERST_STRING &name, const QDate &default_val)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:268
QTime valueTime(const PERST_STRING &name)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:301
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: stgs.h:145
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: stgs.h:136
double valueDbl(const PERST_STRING &name, double default_val)
Get the real value for a key; the value type MUST be real.
Definition: stgs.h:172
QTime valueTime(const PERST_STRING &name, const QTime &default_val)
Get the string list for a key; the value type MUST be an array of strings.
Definition: stgs.h:292
virtual bool setValue(const PERST_STRING &name, const QDate &value)
Set the real value for a key.
Definition: stgs.h:283
virtual bool setValue(const PERST_STRING &name, const QTime &value)
Set the real value for a key.
Definition: stgs.h:307