ROOTANA
mjsonodb.cxx
Go to the documentation of this file.
1 //
2 // ALPHA ROOT analyzer
3 //
4 // Access to ODB stored in JSON odb save file or ODB JSON dump in MIDAS data file.
5 //
6 // Name: mjsonodb.cxx
7 // Author: K.Olchanski, 28-May-2019
8 //
9 
10 #include <stdio.h>
11 #include <assert.h>
12 #include <stdlib.h>
13 #include <string.h> // memset()
14 #include <errno.h> // errno
15 
16 #include "mvodb.h"
17 #include "mjson.h"
18 
19 static std::string toString(int i)
20 {
21  char buf[256];
22  sprintf(buf, "%d", i);
23  return buf;
24 }
25 
26 /// Access to ODB saved in JSON format inside midas .mid files
27 
28 class JsonOdb : public MVOdb
29 {
30 public:
31  MJsonNode* fRoot; // root of JSON document, NULL if we are a subdirectory
32  MJsonNode* fDir; // current ODB directory
33  std::string fPath; // path to correct ODB directory
35 
36 public:
37  JsonOdb(MJsonNode* root, MJsonNode* dir, MVOdbError* error) // ctor
38  {
39  fPrintError = false;
40  fRoot = root;
41  fDir = dir;
42  fPath = "";
43  SetOk(error);
44  }
45 
46  ~JsonOdb() // dtor
47  {
48  if (fRoot) {
49  delete fRoot;
50  fRoot = NULL;
51  }
52  fDir = NULL;
53  }
54 
55 public:
56  void SetPrintError(bool v)
57  {
58  fPrintError = true;
59  }
60 
61  bool GetPrintError() const
62  {
63  return fPrintError;
64  }
65 
66  void SetNotFound(MVOdbError* error, const char* varname)
67  {
68  std::string msg;
69  msg += "Cannot find ";
70  msg += "\"";
71  msg += varname;
72  msg += "\"";
73  SetError(error, fPrintError, fPath, msg);
74  }
75 
76  void SetVarError(MVOdbError* error, const char* varname, std::string msg)
77  {
78  std::string path;
79  path += fPath;
80  path += "/";
81  path += varname;
82  SetError(error, fPrintError, path, msg);
83  }
84 
85  void SetWrongType(MVOdbError* error, const char* varname, const MJsonNode* node, const char* wanted_type)
86  {
87  std::string path;
88  path += fPath;
89  path += "/";
90  path += varname;
91  std::string msg;
92  msg += "JSON node type mismatch: cannot convert node type ";
93  msg += MJsonNode::TypeToString(node->GetType());
94  msg += " to c++ type ";
95  msg += "\"";
96  msg += wanted_type;
97  msg += "\"";
98  SetError(error, fPrintError, path, msg);
99  }
100 
101  bool IsReadOnly() const
102  {
103  return true;
104  }
105 
106  template <typename T>
107  bool GetJsonValue(const char* varname, const MJsonNode* node, T* value, MVOdbError *error);
108 
109  /// Follow the ODB path through the JSON tree
110  static MJsonNode* FindPath(MJsonNode* dir, const char* path)
111  {
112  assert(dir);
113 
114  while (1) {
115  // skip leading slashes
116  while (*path == '/')
117  path++;
118 
119  if (*path == 0)
120  return dir;
121 
122  std::string elem;
123 
124  // copy the next path element into "elem"-
125  // copy "path" until we hit "/" or end of string
126  while (1) {
127  if (*path==0 || *path=='/')
128  break;
129  elem += *path++;
130  }
131 
132  //printf("looking for \"%s\" more \"%s\"\n", elem.c_str(), path);
133 
134  MJsonNode* found = NULL;
135 
136  const MJsonStringVector* s = dir->GetObjectNames();
137  const MJsonNodeVector* n = dir->GetObjectNodes();
138  assert(s->size() == n->size());
139 
140  for (unsigned i=0; i<s->size(); i++) {
141  if (strcasecmp(elem.c_str(), (*s)[i].c_str()) == 0) {
142  if (dir->GetType() == MJSON_OBJECT) {
143  // found the right subdirectory, descend into it
144  found = (*n)[i];
145  break;
146  } else {
147  return (*n)[i];
148  }
149  }
150  }
151 
152  if (!found)
153  return NULL;
154  dir = found;
155  }
156  }
157 
158  MVOdb* Chdir(const char* subdir, bool create, MVOdbError* error)
159  {
160  MJsonNode* node = FindPath(fDir, subdir);
161  if (!node) {
162  SetNotFound(error, subdir);
163  if (create) {
164  return MakeNullOdb();
165  } else {
166  return NULL;
167  }
168  }
169 
170  if (node->GetType() != MJSON_OBJECT) {
171  std::string msg;
172  msg += "\"";
173  msg += subdir;
174  msg += "\"";
175  msg += " JSON node is ";
176  msg += "\"";
177  msg += MJsonNode::TypeToString(node->GetType());
178  msg += "\"";
179  msg += " instead of subdirectory";
180  SetError(error, fPrintError, fPath, msg);
181  if (create)
182  return MakeNullOdb();
183  else
184  return NULL;
185  }
186 
187  //printf("Found subdir [%s]\n", subdir);
188  //DumpTree(node);
189 
190  JsonOdb* x = new JsonOdb(NULL, node, error);
191  x->fPath = fPath + "/" + subdir;
192 
193  SetOk(error);
194  return x;
195  }
196 
197  void ReadKey(const char* varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError* error)
198  {
199  if (tid) *tid = 0;
200  if (num_values) *num_values = 0;
201  if (total_size) *total_size = 0;
202  if (item_size) *item_size = 0;
203  // FIXME: not implemented
204  SetOk(error);
205  }
206 
207  void ReadDir(std::vector<std::string>* varname, std::vector<int> *tid, std::vector<int> *num_values, std::vector<int> *total_size, std::vector<int> *item_size, MVOdbError* error)
208  {
209  // FIXME: not implemented
210  SetOk(error);
211  }
212 
213  void RB(const char* varname, bool *value, bool create, MVOdbError* error)
214  {
215  RBAI(varname, 0, value, error);
216  };
217 
218  void RI(const char* varname, int *value, bool create, MVOdbError* error)
219  {
220  RIAI(varname, 0, value, error);
221  };
222 
223  void RD(const char* varname, double *value, bool create, MVOdbError* error)
224  {
225  RDAI(varname, 0, value, error);
226  };
227 
228  void RF(const char* varname, float *value, bool create, MVOdbError* error)
229  {
230  RFAI(varname, 0, value, error);
231  };
232 
233  void RS(const char* varname, std::string *value, bool create, int create_string_length, MVOdbError* error)
234  {
235  RSAI(varname, 0, value, error);
236  };
237 
238  void RU16(const char* varname, uint16_t *value, bool create, MVOdbError* error)
239  {
240  RU16AI(varname, 0, value, error);
241  };
242 
243  void RU32(const char* varname, uint32_t *value, bool create, MVOdbError* error)
244  {
245  RU32AI(varname, 0, value, error);
246  };
247 
248  template <typename T>
249  void RXA(const char* varname, std::vector<T> *value, MVOdbError* error)
250  {
251  if (!value) {
252  SetOk(error);
253  return;
254  }
255 
256  MJsonNode* node = FindPath(fDir, varname);
257  if (!node) {
258  SetNotFound(error, varname);
259  return;
260  }
261 
262  //DumpTree(node);
263 
264  if (node->GetType() == MJSON_OBJECT) {
265  SetVarError(error, varname, "JSON node is a subdirectory");
266  return;
267  } else if (node->GetType() == MJSON_ARRAY) {
268 
269  const MJsonNodeVector* a = node->GetArray();
270 
271  int num_values = a->size();
272 
273  value->clear();
274 
275  for (int i=0; i<num_values; i++) {
276  const MJsonNode* elem = (*a)[i];
277  T v;
278  bool ok = GetJsonValue<T>(varname, elem, &v, error);
279  if (!ok)
280  break;
281  value->push_back(v);
282  }
283  } else {
284  T v;
285  bool ok = GetJsonValue<T>(varname, node, &v, error);
286  if (!ok)
287  return;
288  value->clear();
289  value->push_back(v);
290  }
291  };
292 
293  void RBA(const char* varname, std::vector<bool> *value, bool create, int create_size, MVOdbError* error)
294  {
295  RXA(varname, value, error);
296  }
297 
298  void RIA(const char* varname, std::vector<int> *value, bool create, int create_size, MVOdbError* error)
299  {
300  RXA(varname, value, error);
301  }
302 
303  void RDA(const char* varname, std::vector<double> *value, bool create, int create_size, MVOdbError* error)
304  {
305  RXA(varname, value, error);
306  }
307 
308  void RFA(const char* varname, std::vector<float> *value, bool create, int create_size, MVOdbError* error)
309  {
310  RXA(varname, value, error);
311  }
312 
313  void RSA(const char* varname, std::vector<std::string> *value, bool create, int create_size, int create_string_length, MVOdbError* error)
314  {
315  RXA(varname, value, error);
316  }
317 
318  void RU16A(const char* varname, std::vector<uint16_t> *value, bool create, int create_size, MVOdbError* error)
319  {
320  RXA(varname, value, error);
321  }
322 
323  void RU32A(const char* varname, std::vector<uint32_t> *value, bool create, int create_size, MVOdbError* error)
324  {
325  RXA(varname, value, error);
326  }
327 
328  template <typename T>
329  void RXAI(const char* varname, int index, T* value, MVOdbError* error)
330  {
331  if (!value) {
332  SetOk(error);
333  return;
334  }
335 
336  MJsonNode* node = FindPath(fDir, varname);
337  if (!node) {
338  SetNotFound(error, varname);
339  return;
340  }
341 
342  //printf("varname [%s] index %d, found node %p:\n", varname, index, node);
343  //node->Dump();
344 
345  if (node->GetType() == MJSON_OBJECT) {
346  SetVarError(error, varname, "JSON node is a subdirectory");
347  return;
348  } else if (node->GetType() == MJSON_ARRAY) {
349  //DumpTree(node);
350 
351  const MJsonNodeVector* a = node->GetArray();
352 
353  int num_values = a->size();
354 
355  if (index < 0) {
356  std::string msg;
357  msg += "bad index ";
358  msg += toString(index);
359  msg += " for array of size ";
360  msg += toString(num_values);
361  SetVarError(error, varname, msg);
362  return;
363  }
364 
365  if (index >= num_values) {
366  std::string msg;
367  msg += "bad index ";
368  msg += toString(index);
369  msg += " for array of size ";
370  msg += toString(num_values);
371  SetVarError(error, varname, msg);
372  return;
373  }
374 
375  MJsonNode* elem = (*a)[index];
376 
377  GetJsonValue<T>(varname, elem, value, error);
378  return;
379  } else {
380  if (index != 0) {
381  std::string msg;
382  msg += "non-zero index ";
383  msg += toString(index);
384  msg += " for non-array";
385  SetVarError(error, varname, msg);
386  return;
387  }
388 
389  GetJsonValue<T>(varname, node, value, error);
390  return;
391  }
392  }
393 
394  void RBAI(const char* varname, int index, bool *value, MVOdbError* error)
395  {
396  RXAI(varname, index, value, error);
397  }
398 
399  void RIAI(const char* varname, int index, int *value, MVOdbError* error)
400  {
401  RXAI(varname, index, value, error);
402  }
403 
404  void RDAI(const char* varname, int index, double *value, MVOdbError* error)
405  {
406  RXAI(varname, index, value, error);
407  }
408 
409  void RFAI(const char* varname, int index, float *value, MVOdbError* error)
410  {
411  RXAI(varname, index, value, error);
412  }
413 
414  void RSAI(const char* varname, int index, std::string *value, MVOdbError* error)
415  {
416  RXAI(varname, index, value, error);
417  }
418 
419  void RU16AI(const char* varname, int index, uint16_t *value, MVOdbError* error)
420  {
421  RXAI(varname, index, value, error);
422  }
423 
424  void RU32AI(const char* varname, int index, uint32_t *value, MVOdbError* error)
425  {
426  RXAI(varname, index, value, error);
427  }
428 
429  // write functions do nothing
430 
431  void WB(const char* varname, bool v, MVOdbError* error) { SetOk(error); };
432  void WI(const char* varname, int v, MVOdbError* error) { SetOk(error); };
433  void WD(const char* varname, double v, MVOdbError* error) { SetOk(error); };
434  void WF(const char* varname, float v, MVOdbError* error) { SetOk(error); };
435  void WS(const char* varname, const char* v, int string_length, MVOdbError* error) { SetOk(error); };
436  void WU16(const char* varname, uint16_t v, MVOdbError* error) { SetOk(error); };
437  void WU32(const char* varname, uint32_t v, MVOdbError* error) { SetOk(error); };
438 
439  void WBA(const char* varname, const std::vector<bool>& v, MVOdbError* error) { SetOk(error); };
440  void WIA(const char* varname, const std::vector<int>& v, MVOdbError* error) { SetOk(error); };
441  void WDA(const char* varname, const std::vector<double>& v, MVOdbError* error) { SetOk(error); };
442  void WFA(const char* varname, const std::vector<float>& v, MVOdbError* error) { SetOk(error); };
443  void WSA(const char* varname, const std::vector<std::string>& data, int odb_string_length, MVOdbError* error) { SetOk(error); };
444  void WU16A(const char* varname, const std::vector<uint16_t>& v, MVOdbError* error) { SetOk(error); };
445  void WU32A(const char* varname, const std::vector<uint32_t>& v, MVOdbError* error) { SetOk(error); };
446 
447  void WBAI(const char* varname, int index, bool v, MVOdbError* error) { SetOk(error); };
448  void WIAI(const char* varname, int index, int v, MVOdbError* error) { SetOk(error); };
449  void WDAI(const char* varname, int index, double v, MVOdbError* error) { SetOk(error); };
450  void WFAI(const char* varname, int index, float v, MVOdbError* error) { SetOk(error); };
451  void WSAI(const char* varname, int index, const char* v, MVOdbError* error) { SetOk(error); };
452  void WU16AI(const char* varname, int index, uint16_t v, MVOdbError* error) { SetOk(error); };
453  void WU32AI(const char* varname, int index, uint32_t v, MVOdbError* error) { SetOk(error); };
454 
455  // delete function does nothing
456 
457  void Delete(const char* odbname, MVOdbError* error) { SetOk(error); };
458 };
459 
460 template<>
461 bool JsonOdb::GetJsonValue<int>(const char* varname, const MJsonNode* node, int* value, MVOdbError* error)
462 {
463  switch (node->GetType()) {
464  case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
465  default: SetWrongType(error, varname, node, "int"); return false;
466  }
467 }
468 
469 template<>
470 bool JsonOdb::GetJsonValue<double>(const char* varname, const MJsonNode* node, double* value, MVOdbError* error)
471 {
472  switch (node->GetType()) {
473  case MJSON_INT: *value = (double)node->GetInt(); SetOk(error); return true;
474  case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
475  default: SetWrongType(error, varname, node, "double"); return false;
476  }
477 }
478 
479 template<>
480 bool JsonOdb::GetJsonValue<float>(const char* varname, const MJsonNode* node, float* value, MVOdbError* error)
481 {
482  switch (node->GetType()) {
483  case MJSON_INT: *value = (float)node->GetInt(); SetOk(error); return true;
484  case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
485  default: SetWrongType(error, varname, node, "float"); return false;
486  }
487 }
488 
489 template<>
490 bool JsonOdb::GetJsonValue<bool>(const char* varname, const MJsonNode* node, bool* value, MVOdbError* error)
491 {
492  switch (node->GetType()) {
493  //case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
494  //case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
495  case MJSON_BOOL: *value = node->GetBool(); SetOk(error); return true;
496  default: SetWrongType(error, varname, node, "bool"); return false;
497  }
498 }
499 
500 template<>
501 bool JsonOdb::GetJsonValue<uint16_t>(const char* varname, const MJsonNode* node, uint16_t* value, MVOdbError* error)
502 {
503  switch (node->GetType()) {
504  case MJSON_INT: *value = (0xFFFF & node->GetInt()); SetOk(error); return true;
505  case MJSON_STRING: *value = (0xFFFF & strtoul(node->GetString().c_str(), NULL, 0)); SetOk(error); return true;
506  default: SetWrongType(error, varname, node, "uint16_t"); return false;
507  }
508 }
509 
510 template<>
511 bool JsonOdb::GetJsonValue<uint32_t>(const char* varname, const MJsonNode* node, uint32_t* value, MVOdbError* error)
512 {
513  switch (node->GetType()) {
514  case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
515  case MJSON_STRING: *value = strtoul(node->GetString().c_str(), NULL, 0); SetOk(error); return true;
516  default: SetWrongType(error, varname, node, "uint32_t"); return false;
517  }
518 }
519 
520 template<>
521 bool JsonOdb::GetJsonValue<std::string>(const char* varname, const MJsonNode* node, std::string* value, MVOdbError* error)
522 {
523  switch (node->GetType()) {
524  case MJSON_STRING: *value = node->GetString(); SetOk(error); return true;
525  default: SetWrongType(error, varname, node, "std::string"); return false;
526  }
527 }
528 
529 MVOdb* MakeJsonFileOdb(const char* filename, MVOdbError* error)
530 {
531  std::string data;
532 
533  {
534  FILE *fp = fopen(filename, "r");
535  if (!fp) {
536  std::string msg;
537  msg += "Cannot open file ";
538  msg += "\"";
539  msg += filename;
540  msg += "\"";
541  msg += " fopen() errno: ";
542  msg += toString(errno);
543  msg += " (";
544  msg += strerror(errno);
545  msg += ")";
546  SetError(error, true, filename, msg);
547  return MakeNullOdb();
548  }
549 
550  while (1) {
551  char buf[1024*1024];
552  const char* s = fgets(buf, sizeof(buf), fp);
553  if (!s)
554  break;
555  data += s;
556  }
557 
558  fclose(fp);
559  fp = NULL;
560  }
561 
562  MJsonNode* root = MJsonNode::Parse(data.c_str());
563  //root->Dump();
564  return new JsonOdb(root, root, error);
565 }
566 
567 MVOdb* MakeJsonBufferOdb(const char* buf, int bufsize, MVOdbError* error)
568 {
569  MJsonNode* root = MJsonNode::Parse(buf);
570  //root->Dump();
571  return new JsonOdb(root, root, error);
572  //return MakeNullOdb();
573 }
574 
575 /* emacs
576  * Local Variables:
577  * tab-width: 8
578  * c-basic-offset: 3
579  * indent-tabs-mode: nil
580  * End:
581  */
Access to ODB saved in JSON format inside midas .mid files.
Definition: mjsonodb.cxx:29
void WU32AI(const char *varname, int index, uint32_t v, MVOdbError *error)
Definition: mjsonodb.cxx:453
void WB(const char *varname, bool v, MVOdbError *error)
Definition: mjsonodb.cxx:431
void WF(const char *varname, float v, MVOdbError *error)
Definition: mjsonodb.cxx:434
void RDA(const char *varname, std::vector< double > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:303
JsonOdb(MJsonNode *root, MJsonNode *dir, MVOdbError *error)
Definition: mjsonodb.cxx:37
MVOdb * Chdir(const char *subdir, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:158
bool IsReadOnly() const
Definition: mjsonodb.cxx:101
void WU16(const char *varname, uint16_t v, MVOdbError *error)
Definition: mjsonodb.cxx:436
void WI(const char *varname, int v, MVOdbError *error)
Definition: mjsonodb.cxx:432
std::string fPath
Definition: mjsonodb.cxx:33
void WD(const char *varname, double v, MVOdbError *error)
Definition: mjsonodb.cxx:433
void RU16AI(const char *varname, int index, uint16_t *value, MVOdbError *error)
Definition: mjsonodb.cxx:419
void SetNotFound(MVOdbError *error, const char *varname)
Definition: mjsonodb.cxx:66
void WBAI(const char *varname, int index, bool v, MVOdbError *error)
Definition: mjsonodb.cxx:447
void WIAI(const char *varname, int index, int v, MVOdbError *error)
Definition: mjsonodb.cxx:448
~JsonOdb()
Definition: mjsonodb.cxx:46
void WS(const char *varname, const char *v, int string_length, MVOdbError *error)
Definition: mjsonodb.cxx:435
MJsonNode * fRoot
Definition: mjsonodb.cxx:31
bool fPrintError
Definition: mjsonodb.cxx:34
void RU16A(const char *varname, std::vector< uint16_t > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:318
void RSAI(const char *varname, int index, std::string *value, MVOdbError *error)
Definition: mjsonodb.cxx:414
void RBA(const char *varname, std::vector< bool > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:293
void RXA(const char *varname, std::vector< T > *value, MVOdbError *error)
Definition: mjsonodb.cxx:249
void RB(const char *varname, bool *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:213
void WSA(const char *varname, const std::vector< std::string > &data, int odb_string_length, MVOdbError *error)
Definition: mjsonodb.cxx:443
void RFA(const char *varname, std::vector< float > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:308
void RS(const char *varname, std::string *value, bool create, int create_string_length, MVOdbError *error)
Definition: mjsonodb.cxx:233
void WU16A(const char *varname, const std::vector< uint16_t > &v, MVOdbError *error)
Definition: mjsonodb.cxx:444
void SetPrintError(bool v)
Definition: mjsonodb.cxx:56
void Delete(const char *odbname, MVOdbError *error)
Definition: mjsonodb.cxx:457
void RU32A(const char *varname, std::vector< uint32_t > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:323
void ReadKey(const char *varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError *error)
Definition: mjsonodb.cxx:197
MJsonNode * fDir
Definition: mjsonodb.cxx:32
void RXAI(const char *varname, int index, T *value, MVOdbError *error)
Definition: mjsonodb.cxx:329
bool GetPrintError() const
Definition: mjsonodb.cxx:61
void WBA(const char *varname, const std::vector< bool > &v, MVOdbError *error)
Definition: mjsonodb.cxx:439
void RD(const char *varname, double *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:223
void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error)
Definition: mjsonodb.cxx:442
void ReadDir(std::vector< std::string > *varname, std::vector< int > *tid, std::vector< int > *num_values, std::vector< int > *total_size, std::vector< int > *item_size, MVOdbError *error)
Definition: mjsonodb.cxx:207
void RU16(const char *varname, uint16_t *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:238
void RU32(const char *varname, uint32_t *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:243
void WU16AI(const char *varname, int index, uint16_t v, MVOdbError *error)
Definition: mjsonodb.cxx:452
void RF(const char *varname, float *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:228
void WDAI(const char *varname, int index, double v, MVOdbError *error)
Definition: mjsonodb.cxx:449
void RIAI(const char *varname, int index, int *value, MVOdbError *error)
Definition: mjsonodb.cxx:399
void WDA(const char *varname, const std::vector< double > &v, MVOdbError *error)
Definition: mjsonodb.cxx:441
void WU32(const char *varname, uint32_t v, MVOdbError *error)
Definition: mjsonodb.cxx:437
void RSA(const char *varname, std::vector< std::string > *value, bool create, int create_size, int create_string_length, MVOdbError *error)
Definition: mjsonodb.cxx:313
static MJsonNode * FindPath(MJsonNode *dir, const char *path)
Follow the ODB path through the JSON tree.
Definition: mjsonodb.cxx:110
void RI(const char *varname, int *value, bool create, MVOdbError *error)
Definition: mjsonodb.cxx:218
void WSAI(const char *varname, int index, const char *v, MVOdbError *error)
Definition: mjsonodb.cxx:451
void RFAI(const char *varname, int index, float *value, MVOdbError *error)
Definition: mjsonodb.cxx:409
void SetVarError(MVOdbError *error, const char *varname, std::string msg)
Definition: mjsonodb.cxx:76
void WIA(const char *varname, const std::vector< int > &v, MVOdbError *error)
Definition: mjsonodb.cxx:440
void WU32A(const char *varname, const std::vector< uint32_t > &v, MVOdbError *error)
Definition: mjsonodb.cxx:445
void RBAI(const char *varname, int index, bool *value, MVOdbError *error)
Definition: mjsonodb.cxx:394
void RDAI(const char *varname, int index, double *value, MVOdbError *error)
Definition: mjsonodb.cxx:404
void RIA(const char *varname, std::vector< int > *value, bool create, int create_size, MVOdbError *error)
Definition: mjsonodb.cxx:298
void WFAI(const char *varname, int index, float v, MVOdbError *error)
Definition: mjsonodb.cxx:450
void SetWrongType(MVOdbError *error, const char *varname, const MJsonNode *node, const char *wanted_type)
Definition: mjsonodb.cxx:85
bool GetJsonValue(const char *varname, const MJsonNode *node, T *value, MVOdbError *error)
void RU32AI(const char *varname, int index, uint32_t *value, MVOdbError *error)
Definition: mjsonodb.cxx:424
Definition: mvodb.h:21
std::string GetString() const
find subnode with given name, NULL if not object, NULL is name not found
Definition: mjson.cxx:960
#define MJSON_STRING
Definition: mjson.h:23
const MJsonNodeVector * GetArray() const
get node type: MJSON_xxx
Definition: mjson.cxx:910
int GetType() const
delete a node from an object
Definition: mjson.cxx:905
int GetInt() const
get string value, "" if not string or value is JSON "null"
Definition: mjson.cxx:968
std::vector< MJsonNode * > MJsonNodeVector
Definition: mjson.h:34
std::vector< std::string > MJsonStringVector
Definition: mjson.h:31
double GetDouble() const
get integer value, 0 if not an integer or value is JSON "null"
Definition: mjson.cxx:976
#define MJSON_BOOL
Definition: mjson.h:26
const MJsonNodeVector * GetObjectNodes() const
get array of object names, NULL if not object, empty array if value is JSON "null"
Definition: mjson.cxx:926
#define MJSON_OBJECT
Definition: mjson.h:22
#define MJSON_ARRAY
Definition: mjson.h:21
bool GetBool() const
get number or integer value, 0 if not a number or value is JSON "null"
Definition: mjson.cxx:1001
const MJsonStringVector * GetObjectNames() const
get array value, NULL if not array, empty array if value is JSON "null"
Definition: mjson.cxx:918
#define MJSON_INT
Definition: mjson.h:24
static MJsonNode * Parse(const char *jsonstring)
Definition: mjson.cxx:645
#define MJSON_NUMBER
Definition: mjson.h:25
static const char * TypeToString(int type)
get error message from MJSON_ERROR nodes
Definition: mjson.cxx:1042
MVOdb * MakeNullOdb()
Definition: nullodb.cxx:123
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition: mvodb.cxx:70
void SetOk(MVOdbError *error)
Definition: mvodb.cxx:31
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error)
Definition: mjsonodb.cxx:529
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error)
Definition: mjsonodb.cxx:567
static std::string toString(int i)
Definition: mjsonodb.cxx:19