ROOTANA
Loading...
Searching...
No Matches
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
19static std::string toString(int i)
20{
21 char buf[256];
22 snprintf(buf, sizeof(buf), "%d", i);
23 return buf;
24}
25
26/// Access to ODB saved in JSON format inside midas .mid files
27
28class JsonOdb : public MVOdb
29{
30public:
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
36public:
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
55public:
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 ReadKeyLastWritten(const char* varname, int *last_written, MVOdbError* error)
208 {
209 if (last_written) *last_written = 0;
210 // FIXME: not implemented
211 SetOk(error);
212 }
213
214 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)
215 {
216 // FIXME: not implemented
217 SetOk(error);
218 }
219
220 void RB(const char* varname, bool *value, bool create, MVOdbError* error)
221 {
222 RBAI(varname, 0, value, error);
223 };
224
225 void RI(const char* varname, int *value, bool create, MVOdbError* error)
226 {
227 RIAI(varname, 0, value, error);
228 };
229
230 void RD(const char* varname, double *value, bool create, MVOdbError* error)
231 {
232 RDAI(varname, 0, value, error);
233 };
234
235 void RF(const char* varname, float *value, bool create, MVOdbError* error)
236 {
237 RFAI(varname, 0, value, error);
238 };
239
240 void RS(const char* varname, std::string *value, bool create, int create_string_length, MVOdbError* error)
241 {
242 RSAI(varname, 0, value, error);
243 };
244
245 void RU16(const char* varname, uint16_t *value, bool create, MVOdbError* error)
246 {
247 RU16AI(varname, 0, value, error);
248 };
249
250 void RU32(const char* varname, uint32_t *value, bool create, MVOdbError* error)
251 {
252 RU32AI(varname, 0, value, error);
253 };
254
255 template <typename T>
256 void RXA(const char* varname, std::vector<T> *value, MVOdbError* error)
257 {
258 if (!value) {
259 SetOk(error);
260 return;
261 }
262
263 MJsonNode* node = FindPath(fDir, varname);
264 if (!node) {
265 SetNotFound(error, varname);
266 return;
267 }
268
269 //DumpTree(node);
270
271 if (node->GetType() == MJSON_OBJECT) {
272 SetVarError(error, varname, "JSON node is a subdirectory");
273 return;
274 } else if (node->GetType() == MJSON_ARRAY) {
275
276 const MJsonNodeVector* a = node->GetArray();
277
278 int num_values = a->size();
279
280 value->clear();
281
282 for (int i=0; i<num_values; i++) {
283 const MJsonNode* elem = (*a)[i];
284 T v;
285 bool ok = GetJsonValue<T>(varname, elem, &v, error);
286 if (!ok)
287 break;
288 value->push_back(v);
289 }
290 } else {
291 T v;
292 bool ok = GetJsonValue<T>(varname, node, &v, error);
293 if (!ok)
294 return;
295 value->clear();
296 value->push_back(v);
297 }
298 };
299
300 void RBA(const char* varname, std::vector<bool> *value, bool create, int create_size, MVOdbError* error)
301 {
302 RXA(varname, value, error);
303 }
304
305 void RIA(const char* varname, std::vector<int> *value, bool create, int create_size, MVOdbError* error)
306 {
307 RXA(varname, value, error);
308 }
309
310 void RDA(const char* varname, std::vector<double> *value, bool create, int create_size, MVOdbError* error)
311 {
312 RXA(varname, value, error);
313 }
314
315 void RFA(const char* varname, std::vector<float> *value, bool create, int create_size, MVOdbError* error)
316 {
317 RXA(varname, value, error);
318 }
319
320 void RSA(const char* varname, std::vector<std::string> *value, bool create, int create_size, int create_string_length, MVOdbError* error)
321 {
322 RXA(varname, value, error);
323 }
324
325 void RU16A(const char* varname, std::vector<uint16_t> *value, bool create, int create_size, MVOdbError* error)
326 {
327 RXA(varname, value, error);
328 }
329
330 void RU32A(const char* varname, std::vector<uint32_t> *value, bool create, int create_size, MVOdbError* error)
331 {
332 RXA(varname, value, error);
333 }
334
335 template <typename T>
336 void RXAI(const char* varname, int index, T* value, MVOdbError* error)
337 {
338 if (!value) {
339 SetOk(error);
340 return;
341 }
342
343 MJsonNode* node = FindPath(fDir, varname);
344 if (!node) {
345 SetNotFound(error, varname);
346 return;
347 }
348
349 //printf("varname [%s] index %d, found node %p:\n", varname, index, node);
350 //node->Dump();
351
352 if (node->GetType() == MJSON_OBJECT) {
353 SetVarError(error, varname, "JSON node is a subdirectory");
354 return;
355 } else if (node->GetType() == MJSON_ARRAY) {
356 //DumpTree(node);
357
358 const MJsonNodeVector* a = node->GetArray();
359
360 int num_values = a->size();
361
362 if (index < 0) {
363 std::string msg;
364 msg += "bad index ";
365 msg += toString(index);
366 msg += " for array of size ";
367 msg += toString(num_values);
368 SetVarError(error, varname, msg);
369 return;
370 }
371
372 if (index >= num_values) {
373 std::string msg;
374 msg += "bad index ";
375 msg += toString(index);
376 msg += " for array of size ";
377 msg += toString(num_values);
378 SetVarError(error, varname, msg);
379 return;
380 }
381
382 MJsonNode* elem = (*a)[index];
383
384 GetJsonValue<T>(varname, elem, value, error);
385 return;
386 } else {
387 if (index != 0) {
388 std::string msg;
389 msg += "non-zero index ";
390 msg += toString(index);
391 msg += " for non-array";
392 SetVarError(error, varname, msg);
393 return;
394 }
395
396 GetJsonValue<T>(varname, node, value, error);
397 return;
398 }
399 }
400
401 void RBAI(const char* varname, int index, bool *value, MVOdbError* error)
402 {
403 RXAI(varname, index, value, error);
404 }
405
406 void RIAI(const char* varname, int index, int *value, MVOdbError* error)
407 {
408 RXAI(varname, index, value, error);
409 }
410
411 void RDAI(const char* varname, int index, double *value, MVOdbError* error)
412 {
413 RXAI(varname, index, value, error);
414 }
415
416 void RFAI(const char* varname, int index, float *value, MVOdbError* error)
417 {
418 RXAI(varname, index, value, error);
419 }
420
421 void RSAI(const char* varname, int index, std::string *value, MVOdbError* error)
422 {
423 RXAI(varname, index, value, error);
424 }
425
426 void RU16AI(const char* varname, int index, uint16_t *value, MVOdbError* error)
427 {
428 RXAI(varname, index, value, error);
429 }
430
431 void RU32AI(const char* varname, int index, uint32_t *value, MVOdbError* error)
432 {
433 RXAI(varname, index, value, error);
434 }
435
436 // write functions do nothing
437
438 void WB(const char* varname, bool v, MVOdbError* error) { SetOk(error); };
439 void WI(const char* varname, int v, MVOdbError* error) { SetOk(error); };
440 void WD(const char* varname, double v, MVOdbError* error) { SetOk(error); };
441 void WF(const char* varname, float v, MVOdbError* error) { SetOk(error); };
442 void WS(const char* varname, const char* v, int string_length, MVOdbError* error) { SetOk(error); };
443 void WU16(const char* varname, uint16_t v, MVOdbError* error) { SetOk(error); };
444 void WU32(const char* varname, uint32_t v, MVOdbError* error) { SetOk(error); };
445
446 void WBA(const char* varname, const std::vector<bool>& v, MVOdbError* error) { SetOk(error); };
447 void WIA(const char* varname, const std::vector<int>& v, MVOdbError* error) { SetOk(error); };
448 void WDA(const char* varname, const std::vector<double>& v, MVOdbError* error) { SetOk(error); };
449 void WFA(const char* varname, const std::vector<float>& v, MVOdbError* error) { SetOk(error); };
450 void WSA(const char* varname, const std::vector<std::string>& data, int odb_string_length, MVOdbError* error) { SetOk(error); };
451 void WU16A(const char* varname, const std::vector<uint16_t>& v, MVOdbError* error) { SetOk(error); };
452 void WU32A(const char* varname, const std::vector<uint32_t>& v, MVOdbError* error) { SetOk(error); };
453
454 void WBAI(const char* varname, int index, bool v, MVOdbError* error) { SetOk(error); };
455 void WIAI(const char* varname, int index, int v, MVOdbError* error) { SetOk(error); };
456 void WDAI(const char* varname, int index, double v, MVOdbError* error) { SetOk(error); };
457 void WFAI(const char* varname, int index, float v, MVOdbError* error) { SetOk(error); };
458 void WSAI(const char* varname, int index, const char* v, MVOdbError* error) { SetOk(error); };
459 void WU16AI(const char* varname, int index, uint16_t v, MVOdbError* error) { SetOk(error); };
460 void WU32AI(const char* varname, int index, uint32_t v, MVOdbError* error) { SetOk(error); };
461
462 // delete function does nothing
463
464 void Delete(const char* odbname, MVOdbError* error) { SetOk(error); };
465};
466
467template<>
468bool JsonOdb::GetJsonValue<int>(const char* varname, const MJsonNode* node, int* value, MVOdbError* error)
469{
470 switch (node->GetType()) {
471 case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
472 default: SetWrongType(error, varname, node, "int"); return false;
473 }
474}
475
476template<>
477bool JsonOdb::GetJsonValue<double>(const char* varname, const MJsonNode* node, double* value, MVOdbError* error)
478{
479 switch (node->GetType()) {
480 case MJSON_INT: *value = (double)node->GetInt(); SetOk(error); return true;
481 case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
482 default: SetWrongType(error, varname, node, "double"); return false;
483 }
484}
485
486template<>
487bool JsonOdb::GetJsonValue<float>(const char* varname, const MJsonNode* node, float* value, MVOdbError* error)
488{
489 switch (node->GetType()) {
490 case MJSON_INT: *value = (float)node->GetInt(); SetOk(error); return true;
491 case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
492 default: SetWrongType(error, varname, node, "float"); return false;
493 }
494}
495
496template<>
497bool JsonOdb::GetJsonValue<bool>(const char* varname, const MJsonNode* node, bool* value, MVOdbError* error)
498{
499 switch (node->GetType()) {
500 //case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
501 //case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
502 case MJSON_BOOL: *value = node->GetBool(); SetOk(error); return true;
503 default: SetWrongType(error, varname, node, "bool"); return false;
504 }
505}
506
507template<>
508bool JsonOdb::GetJsonValue<uint16_t>(const char* varname, const MJsonNode* node, uint16_t* value, MVOdbError* error)
509{
510 switch (node->GetType()) {
511 case MJSON_INT: *value = (0xFFFF & node->GetInt()); SetOk(error); return true;
512 case MJSON_STRING: *value = (0xFFFF & strtoul(node->GetString().c_str(), NULL, 0)); SetOk(error); return true;
513 default: SetWrongType(error, varname, node, "uint16_t"); return false;
514 }
515}
516
517template<>
518bool JsonOdb::GetJsonValue<uint32_t>(const char* varname, const MJsonNode* node, uint32_t* value, MVOdbError* error)
519{
520 switch (node->GetType()) {
521 case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
522 case MJSON_STRING: *value = strtoul(node->GetString().c_str(), NULL, 0); SetOk(error); return true;
523 default: SetWrongType(error, varname, node, "uint32_t"); return false;
524 }
525}
526
527template<>
528bool JsonOdb::GetJsonValue<std::string>(const char* varname, const MJsonNode* node, std::string* value, MVOdbError* error)
529{
530 switch (node->GetType()) {
531 case MJSON_STRING: *value = node->GetString(); SetOk(error); return true;
532 default: SetWrongType(error, varname, node, "std::string"); return false;
533 }
534}
535
536MVOdb* MakeJsonFileOdb(const char* filename, MVOdbError* error)
537{
538 std::string data;
539
540 {
541 FILE *fp = fopen(filename, "r");
542 if (!fp) {
543 std::string msg;
544 msg += "Cannot open file ";
545 msg += "\"";
546 msg += filename;
547 msg += "\"";
548 msg += " fopen() errno: ";
549 msg += toString(errno);
550 msg += " (";
551 msg += strerror(errno);
552 msg += ")";
553 SetError(error, true, filename, msg);
554 return MakeNullOdb();
555 }
556
557 while (1) {
558 char buf[1024*1024];
559 const char* s = fgets(buf, sizeof(buf), fp);
560 if (!s)
561 break;
562 data += s;
563 }
564
565 fclose(fp);
566 fp = NULL;
567 }
568
569 MJsonNode* root = MJsonNode::Parse(data.c_str());
570 //root->Dump();
571 return new JsonOdb(root, root, error);
572}
573
574MVOdb* MakeJsonBufferOdb(const char* buf, int bufsize, MVOdbError* error)
575{
576 MJsonNode* root = MJsonNode::Parse(buf);
577 //root->Dump();
578 return new JsonOdb(root, root, error);
579 //return MakeNullOdb();
580}
581
582/* emacs
583 * Local Variables:
584 * tab-width: 8
585 * c-basic-offset: 3
586 * indent-tabs-mode: nil
587 * End:
588 */
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:460
void WB(const char *varname, bool v, MVOdbError *error)
Definition mjsonodb.cxx:438
void WF(const char *varname, float v, MVOdbError *error)
Definition mjsonodb.cxx:441
void RDA(const char *varname, std::vector< double > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:310
JsonOdb(MJsonNode *root, MJsonNode *dir, MVOdbError *error)
Definition mjsonodb.cxx:37
bool IsReadOnly() const
Definition mjsonodb.cxx:101
void WU16(const char *varname, uint16_t v, MVOdbError *error)
Definition mjsonodb.cxx:443
void WI(const char *varname, int v, MVOdbError *error)
Definition mjsonodb.cxx:439
std::string fPath
Definition mjsonodb.cxx:33
void WD(const char *varname, double v, MVOdbError *error)
Definition mjsonodb.cxx:440
void RU16AI(const char *varname, int index, uint16_t *value, MVOdbError *error)
Definition mjsonodb.cxx:426
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:454
void WIAI(const char *varname, int index, int v, MVOdbError *error)
Definition mjsonodb.cxx:455
void ReadKeyLastWritten(const char *varname, int *last_written, MVOdbError *error)
Definition mjsonodb.cxx:207
void WS(const char *varname, const char *v, int string_length, MVOdbError *error)
Definition mjsonodb.cxx:442
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:325
static MJsonNode * FindPath(MJsonNode *dir, const char *path)
Follow the ODB path through the JSON tree.
Definition mjsonodb.cxx:110
void RSAI(const char *varname, int index, std::string *value, MVOdbError *error)
Definition mjsonodb.cxx:421
void RBA(const char *varname, std::vector< bool > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:300
void RXA(const char *varname, std::vector< T > *value, MVOdbError *error)
Definition mjsonodb.cxx:256
void RB(const char *varname, bool *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:220
void WSA(const char *varname, const std::vector< std::string > &data, int odb_string_length, MVOdbError *error)
Definition mjsonodb.cxx:450
void RFA(const char *varname, std::vector< float > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:315
void RS(const char *varname, std::string *value, bool create, int create_string_length, MVOdbError *error)
Definition mjsonodb.cxx:240
void WU16A(const char *varname, const std::vector< uint16_t > &v, MVOdbError *error)
Definition mjsonodb.cxx:451
void SetPrintError(bool v)
Definition mjsonodb.cxx:56
void Delete(const char *odbname, MVOdbError *error)
Definition mjsonodb.cxx:464
void RU32A(const char *varname, std::vector< uint32_t > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:330
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:336
bool GetPrintError() const
Definition mjsonodb.cxx:61
void WBA(const char *varname, const std::vector< bool > &v, MVOdbError *error)
Definition mjsonodb.cxx:446
void RD(const char *varname, double *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:230
void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error)
Definition mjsonodb.cxx:449
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:214
MVOdb * Chdir(const char *subdir, bool create, MVOdbError *error)
Definition mjsonodb.cxx:158
void RU16(const char *varname, uint16_t *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:245
void RU32(const char *varname, uint32_t *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:250
void WU16AI(const char *varname, int index, uint16_t v, MVOdbError *error)
Definition mjsonodb.cxx:459
void RF(const char *varname, float *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:235
void WDAI(const char *varname, int index, double v, MVOdbError *error)
Definition mjsonodb.cxx:456
void RIAI(const char *varname, int index, int *value, MVOdbError *error)
Definition mjsonodb.cxx:406
void WDA(const char *varname, const std::vector< double > &v, MVOdbError *error)
Definition mjsonodb.cxx:448
void WU32(const char *varname, uint32_t v, MVOdbError *error)
Definition mjsonodb.cxx:444
void RSA(const char *varname, std::vector< std::string > *value, bool create, int create_size, int create_string_length, MVOdbError *error)
Definition mjsonodb.cxx:320
void RI(const char *varname, int *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:225
void WSAI(const char *varname, int index, const char *v, MVOdbError *error)
Definition mjsonodb.cxx:458
void RFAI(const char *varname, int index, float *value, MVOdbError *error)
Definition mjsonodb.cxx:416
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:447
void WU32A(const char *varname, const std::vector< uint32_t > &v, MVOdbError *error)
Definition mjsonodb.cxx:452
void RBAI(const char *varname, int index, bool *value, MVOdbError *error)
Definition mjsonodb.cxx:401
void RDAI(const char *varname, int index, double *value, MVOdbError *error)
Definition mjsonodb.cxx:411
void RIA(const char *varname, std::vector< int > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:305
void WFAI(const char *varname, int index, float v, MVOdbError *error)
Definition mjsonodb.cxx:457
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:431
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:961
#define MJSON_STRING
Definition mjson.h:23
const MJsonNodeVector * GetArray() const
get node type: MJSON_xxx
Definition mjson.cxx:909
int GetType() const
delete a node from an object
Definition mjson.cxx:904
std::vector< MJsonNode * > MJsonNodeVector
Definition mjson.h:34
std::vector< std::string > MJsonStringVector
Definition mjson.h:33
long long GetInt() const
get string value, "" if not string or value is JSON "null"
Definition mjson.cxx:969
double GetDouble() const
get 64-bit long long value, 0 if not an integer or value is JSON "null"
Definition mjson.cxx:985
#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:925
#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:1011
const MJsonStringVector * GetObjectNames() const
get array value, NULL if not array, empty array if value is JSON "null"
Definition mjson.cxx:917
#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:1047
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition mvodb.cxx:70
MVOdb * MakeNullOdb()
Definition nullodb.cxx:129
void SetOk(MVOdbError *error)
Definition mvodb.cxx:31
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error)
Definition mjsonodb.cxx:536
static std::string toString(int i)
Definition mjsonodb.cxx:19
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error)
Definition mjsonodb.cxx:574