29 return shift(((uint64_t) storesz)*8-4);
35 uint64_t actualsz = size() - pos;
37 if (actualsz==sz)
return true;
39 if (pos % 8 != 0) {
EOUT(
"start position not 8-byte aligned!!!");
return false; }
43 uint64_t rest = size() % 8;
44 if (rest > 0) shift(8 - rest);
48 if (sz % 8 != 0) {
EOUT(
"size is not 8-byte aligned!!!");
return false; }
51 EOUT(
"Too many bytes %lu was accessed in stream compared to provided %lu", (
long unsigned) actualsz, (
long unsigned) sz);
55 if (is_input())
return shift(sz-actualsz);
57 while (actualsz < sz) {
59 uint64_t portion = sz - actualsz;
60 if (portion>8) portion = 8;
70 uint64_t res =
sizeof(int32_t);
71 res += str.length() + 1;
72 while (res % 8 != 0) res++;
78 uint64_t sz = str_storesize(str);
79 if (sz > maxstoresize()) {
80 EOUT(
"Cannot store string in the buffer sz %lu maxsize %lu pos %lu real %s",
81 (
long unsigned) sz, (
long unsigned) maxstoresize(), (
long unsigned) size(),
DBOOL(is_real()));
85 uint64_t pos = size();
87 uint32_t storesz = sz / 8;
88 write_uint32(storesz);
89 write(str.c_str(), str.length()+1);
91 return verify_size(pos, sz);
96 uint64_t pos = size();
100 uint64_t sz = ((uint64_t) storesz) * 8;
102 if (sz > tmpbuf_size()) {
103 EOUT(
"Cannot read complete string!!!");
108 str.append(tmpbuf());
109 return verify_size(pos, sz);
116 if (len > fRemains)
return false;
124 if (len > fRemains)
return false;
125 memcpy(fCurr, src, len);
134 if (len > fRemains)
return false;
135 memcpy(tgt, fCurr, len);
151 buf.append(
dabc::format(
"%*s<item", compact() > 0 ? 0 : lvl * 2,
""));
152 if (first_node) { buf.append(
" xmlns:dabc=\"http://dabc.gsi.de/xhtml\""); first_node =
false; }
155 numchilds.push_back(0);
156 numflds.push_back(0);
159 buf.append(
dabc::format(
"%*s{", (compact() > 0) ? 0 : lvl * 4,
""));
161 numflds.push_back(0);
162 numchilds.push_back(0);
164 SetField(
"_name",
dabc::format(
"\"%s\"",nodename).c_str());
174 if (numflds.back() < 0) {
175 EOUT(
"Not allowed to set fields (here %s) after any child was created", field);
182 int vlen = strlen(value);
184 const char* v = value;
185 const char* stop = value+vlen;
187 if ((vlen > 1) && (value[0] ==
'\"') && (value[vlen-1] ==
'\"')) {
195 case '<' : buf.append(
"<");
break;
196 case '>' : buf.append(
">");
break;
197 case '&' : buf.append(
"&");
break;
198 case '\'' : buf.append(
"'");
break;
199 case '\"' : buf.append(
""");
break;
200 default: buf.append(v, 1);
break;
208 if (numflds.back()++ > 0) buf.append(
",");
210 buf.append(
dabc::format(
"%*s\"%s\"", (compact() > 0) ? 0 : lvl * 4 - 2,
"", field));
212 case 2: buf.append(
": ");
break;
213 case 3: buf.append(
":");
break;
214 default: buf.append(
" : ");
228 if (numchilds.back() > 0) {
229 buf.append(
dabc::format(
"%*s</item>", compact() > 0 ? 0 : lvl * 2,
""));
235 numchilds.pop_back();
239 numchilds.pop_back();
243 buf.append(
dabc::format(
"%*s}", (compact() > 0) ? 0 : lvl * 4,
""));
252 if (numchilds.back()++ == 0) { buf.append(
">"); NewLine(); }
257 if (numflds.back() > 0) buf.append(
",");
260 if (numchilds.back()++ == 0) {
263 if (basename==0) basename =
"_childs";
265 buf.append(
dabc::format(
"%*s\"%s\"", (compact() > 0) ? 0 : lvl * 4 - 2,
"", basename));
267 case 2: buf.append(
": [");
break;
268 case 3: buf.append(
":[");
break;
269 default: buf.append(
" : [");
281 if (numchilds.back() > 0) {
283 buf.append(
dabc::format(
"%*s]", (compact() > 0) ? 0 : lvl * 4 - 2,
""));
284 numchilds.back() = 0;
304 if (isreadonly())
return true;
315 case kind_none:
break;
316 case kind_bool: SetBool(src.
valueInt!=0);
break;
317 case kind_int: SetInt(src.
valueInt);
break;
318 case kind_datime: SetDatime(src.
valueUInt);
break;
319 case kind_uint: SetUInt(src.
valueUInt);
break;
320 case kind_double: SetDouble(src.
valueDouble);
break;
321 case kind_arrint: SetArrInt(src.
valueInt, (int64_t*) src.
arrInt);
break;
322 case kind_arruint: SetArrUInt(src.
valueInt, (uint64_t*) src.
arrUInt);
break;
324 case kind_string: SetStr(src.
valueStr);
break;
326 case kind_buffer: SetBuffer(*src.
valueBuf);
break;
327 case kind_reference: SetReference(*src.
valueRef);
break;
345 uint64_t pos = s.
size();
348 uint32_t storesz(0), storekind(0), storeversion(0);
351 sz = s.
is_real() ? StoreSize() : 0;
353 storekind = ((uint32_t)fKind & 0xffffff) | (storeversion << 24);
357 case kind_none:
break;
365 s.
write(arrInt, valueInt*
sizeof(int64_t));
369 s.
write(arrUInt, valueInt*
sizeof(uint64_t));
373 s.
write(arrDouble, valueInt*
sizeof(
double));
376 s.
write(valueStr, strlen(valueStr)+1);
381 for (int64_t n=0;n<valueInt;n++) {
382 int len = strlen(ps) + 1;
383 fulllen += len; ps += len;
386 s.
write(valueStr, fulllen);
391 s.
write(valueBuf->SegmentPtr(), valueBuf->SegmentSize());
401 sz = ((uint64_t) storesz) * 8;
404 fKind = (
ValueKind) (storekind & 0xffffff);
406 case kind_none:
break;
411 case kind_double: s.
read_double(valueDouble);
break;
414 arrInt =
new int64_t[valueInt];
415 s.
read(arrInt, valueInt*
sizeof(int64_t));
419 arrUInt =
new uint64_t[valueInt];
420 s.
read(arrUInt, valueInt*
sizeof(uint64_t));
424 arrDouble =
new double[valueInt];
425 s.
read(arrDouble, valueInt*
sizeof(
double));
428 valueStr = (
char*) malloc((storesz-1)*8);
429 s.
read(valueStr, (storesz-1)*8);
433 valueStr = (
char*) malloc((storesz-2)*8);
434 s.
read(valueStr, (storesz-2)*8);
442 s.
read(valueBuf->SegmentPtr(), (storesz-1)*8);
443 if (sz != (storesz-1)*8) valueBuf->SetTotalSize(sz);
459 case kind_none:
break;
460 case kind_bool:
break;
461 case kind_int:
break;
462 case kind_datime:
break;
463 case kind_uint:
break;
464 case kind_double:
break;
465 case kind_arrint:
delete [] arrInt; arrInt =
nullptr;
break;
466 case kind_arruint:
delete [] arrUInt; arrUInt =
nullptr;
break;
467 case kind_arrdouble:
delete [] arrDouble; arrDouble =
nullptr;
break;
469 case kind_arrstr: free(valueStr); valueStr =
nullptr;
break;
470 case kind_buffer:
delete valueBuf; valueBuf =
nullptr;
break;
471 case kind_reference:
delete valueRef; valueRef =
nullptr;
break;
480 case kind_none:
return dflt;
482 case kind_int:
return valueInt!=0;
484 case kind_uint:
return valueUInt!=0;
485 case kind_double:
return valueDouble!=0.;
486 case kind_arrint:
if (valueInt>0)
return arrInt[0]!=0;
break;
487 case kind_arruint:
if (valueInt>0)
return arrUInt[0]!=0;
break;
488 case kind_arrdouble:
if (valueInt>0)
return arrDouble[0]!=0;
break;
495 case kind_buffer:
if (valueBuf!=0)
return valueBuf->SegmentSize()!=0;
break;
496 case kind_reference:
if (valueRef!=0)
return !valueRef->null();
break;
504 case kind_none:
return dflt;
506 case kind_int:
return valueInt;
508 case kind_uint:
return (int64_t) valueUInt;
509 case kind_double:
return (int64_t) valueDouble;
510 case kind_arrint:
if (valueInt>0)
return arrInt[0];
break;
511 case kind_arruint:
if (valueInt>0)
return (int64_t) arrUInt[0];
break;
512 case kind_arrdouble:
if (valueInt>0)
return (int64_t) arrDouble[0];
break;
519 case kind_buffer:
return dflt;
520 case kind_reference:
return dflt;
528 case kind_none:
return dflt;
530 case kind_int:
return (uint64_t) valueInt;
532 case kind_uint:
return valueUInt;
533 case kind_double:
return (uint64_t) valueDouble;
534 case kind_arrint:
if (valueInt>0)
return (uint64_t) arrInt[0];
break;
535 case kind_arruint:
if (valueInt>0)
return arrUInt[0];
break;
536 case kind_arrdouble:
if (valueInt>0)
return (uint64_t) arrDouble[0];
break;
543 case kind_buffer:
return dflt;
544 case kind_reference:
return dflt;
552 case kind_none:
return dflt;
554 case kind_int:
return (
double) valueInt;
556 case kind_uint:
return (
double) valueUInt;
557 case kind_double:
return valueDouble;
558 case kind_arrint:
if (valueInt>0)
return (
double) arrInt[0];
break;
559 case kind_arruint:
if (valueInt>0)
return (
double) arrUInt[0];
break;
560 case kind_arrdouble:
if (valueInt>0)
return arrDouble[0];
break;
567 case kind_buffer:
return dflt;
568 case kind_reference:
return dflt;
575 std::vector<int64_t> res;
578 case kind_none:
break;
580 case kind_int: res.push_back(valueInt);
break;
582 case kind_uint: res.push_back((int64_t) valueUInt);
break;
583 case kind_double: res.push_back((int64_t) valueDouble);
break;
585 res.reserve(valueInt);
586 for (int64_t n=0;n<valueInt;n++)
587 res.push_back(arrInt[n]);
590 res.reserve(valueInt);
591 for (int64_t n=0;n<valueInt;n++)
592 res.push_back((int64_t) arrUInt[n]);
595 res.reserve(valueInt);
596 for (int64_t n=0;n<valueInt;n++)
597 res.push_back((int64_t) arrDouble[n]);
600 std::vector<std::string> svect;
603 if (StrToStrVect(valueStr, svect,
false)) {
604 for (
unsigned n=0;n<svect.size();n++)
609 if (
str_to_lint(valueStr, &res0)) res.push_back(res0);
613 res.reserve(valueInt);
617 for (int64_t n=0;n<valueInt;n++) {
624 case kind_buffer:
break;
625 case kind_reference:
break;
633 std::vector<uint64_t> res;
636 case kind_none:
break;
638 case kind_int: res.push_back((uint64_t) valueInt);
break;
640 case kind_uint: res.push_back(valueUInt);
break;
641 case kind_double: res.push_back((uint64_t) valueDouble);
break;
643 res.reserve(valueInt);
644 for (int64_t n=0;n<valueInt;n++)
645 res.push_back((uint64_t) arrInt[n]);
648 res.reserve(valueInt);
649 for (int64_t n=0;n<valueInt;n++)
650 res.push_back(arrUInt[n]);
653 res.reserve(valueInt);
654 for (int64_t n=0;n<valueInt;n++)
655 res.push_back((uint64_t) arrDouble[n]);
658 std::vector<std::string> svect;
661 if (StrToStrVect(valueStr, svect,
false)) {
662 for (
unsigned n=0;n<svect.size();n++)
672 res.reserve(valueInt);
676 for (int64_t n=0;n<valueInt;n++) {
683 case kind_buffer:
break;
684 case kind_reference:
break;
693 std::vector<double> res;
696 case kind_none:
break;
698 case kind_int: res.push_back((
double) valueInt);
break;
700 case kind_uint: res.push_back((
double) valueUInt);
break;
701 case kind_double: res.push_back(valueDouble);
break;
703 res.reserve(valueInt);
704 for (int64_t n=0;n<valueInt;n++)
705 res.push_back((
double) arrInt[n]);
708 res.reserve(valueInt);
709 for (int64_t n=0;n<valueInt;n++)
710 res.push_back((
double) arrUInt[n]);
713 res.reserve(valueInt);
714 for (int64_t n=0;n<valueInt;n++)
715 res.push_back(arrDouble[n]);
718 std::vector<std::string> svect;
721 if (StrToStrVect(valueStr, svect,
false)) {
722 for (
unsigned n=0;n<svect.size();n++)
731 res.reserve(valueInt);
735 for (int64_t n=0;n<valueInt;n++) {
742 case kind_buffer:
break;
743 case kind_reference:
break;
752 case kind_none:
return dflt;
754 case kind_int:
return dabc::format(
"%ld", (
long) valueInt);
757 return res.empty() ? dflt : res;
759 case kind_uint:
return dabc::format(
"%lu", (
long unsigned) valueUInt);
760 case kind_double:
return dabc::format(
"%g", valueDouble);
766 std::vector<std::string> vect = AsStrVect();
767 if (vect.size()==0)
return dflt;
769 std::string res(
"[");
770 for (
unsigned n=0; n<vect.size();n++) {
771 if (n>0) res.append(
",");
773 if (NeedJsonReformat(vect[n]))
774 res.append(JsonReformat(vect[n]));
783 if (valueStr!=0)
return valueStr;
786 case kind_buffer:
return dflt;
787 case kind_reference:
return dflt;
797 for (
unsigned n=0;n<str.length();n++)
806 case '/':
return true;
807 default:
if ((str[n] < 32) || (str[n]>126))
return true;
817 for (
unsigned n = 0; n<str.length(); n++)
819 case '\n': res.append(
"\\n");
break;
820 case '\t': res.append(
"\\t");
break;
821 case '\"': res.append(
"\\\"");
break;
822 case '\\': res.append(
"\\\\");
break;
823 case '\b': res.append(
"\\b");
break;
824 case '\f': res.append(
"\\f");
break;
825 case '\r': res.append(
"\\r");
break;
826 case '/': res.append(
"\\/");
break;
828 if ((str[n] > 31) && (str[n]<127)) res.append(1, str[n]);
829 else res.append(
dabc::format(
"\\u%04x", (
unsigned) str[n]));
838 case kind_none:
return "null";
839 case kind_bool:
return valueInt!=0 ?
"true" :
"false";
840 case kind_int:
return dabc::format(
"%ld", (
long) valueInt);
847 case kind_uint:
return dabc::format(
"%lu", (
long unsigned) valueUInt);
848 case kind_double:
return dabc::format(
"%g", valueDouble);
850 std::string res(
"[");
851 for (int64_t n=0; n<valueInt;n++) {
852 if (n>0) res.append(
",");
859 std::string res(
"[");
860 for (int64_t n=0; n<valueInt;n++) {
861 if (n>0) res.append(
",");
862 res.append(
dabc::format(
"%lu", (
long unsigned) arrUInt[n]));
867 case kind_arrdouble: {
868 std::string res(
"[");
869 for (int64_t n=0; n<valueInt;n++) {
870 if (n>0) res.append(
",");
878 std::vector<std::string> vect = AsStrVect();
880 std::string res(
"[");
881 for (
unsigned n=0; n<vect.size();n++) {
882 if (n>0) res.append(
",");
884 if (NeedJsonReformat(vect[n]))
885 res.append(JsonReformat(vect[n]));
894 if (valueStr==0)
return "\"\"";
895 std::string res(
"\"");
896 if (NeedJsonReformat(valueStr))
897 res.append(JsonReformat(valueStr));
899 res.append(valueStr);
904 if (valueBuf==0)
return "null";
905 std::string res(
"[");
906 uint8_t* ptr = (uint8_t*) valueBuf->SegmentPtr();
907 for (
unsigned n=0;n<valueBuf->SegmentSize();n++) {
908 if (n>0) res.append(
",");
914 case kind_reference: {
915 if (valueRef==0)
return "null";
917 return "\"<Refernce>\"";
925 std::vector<std::string> res;
928 case kind_none:
break;
933 case kind_double: res.push_back(AsStr());
break;
935 for (int64_t n=0; n<valueInt;n++)
940 for (int64_t n=0; n<valueInt;n++)
941 res.push_back(
dabc::format(
"%lu", (
long unsigned) arrUInt[n]));
944 case kind_arrdouble: {
945 for (int64_t n=0; n<valueInt;n++)
950 if (!StrToStrVect(valueStr, res))
951 res.push_back(valueStr);
956 for (int64_t n=0;n<valueInt;n++) {
962 case kind_buffer:
break;
963 case kind_reference:
break;
985 int len = strlen(str);
987 if ((len<2) || (str[0]!=
'[') || (str[len-1]!=
']'))
return false;
989 const char* pos = str + 1;
992 while (*pos==
' ') pos++;
993 if ((*pos==
'\'') || (*pos ==
'\"')) {
994 const char* p1 = strchr(pos+1, *pos);
996 if (verbose)
EOUT(
"Error syntax in array %s after char:%u - closing quote not found ", str, (
unsigned) (pos - str));
1000 vect.push_back(std::string(pos+1, p1 - pos - 1));
1003 const char* p1 = strpbrk(pos+1,
",]");
1005 if (verbose)
EOUT(
"Error syntax in array %s after char:%u - ',' or ']' not found ", str, (
unsigned) (pos - str));
1010 while ((p1 - spaces > pos + 1) && (*(p1-spaces-1)==
' ')) spaces++;
1011 vect.push_back(std::string(pos, p1 - pos - spaces));
1014 while (*pos==
' ') pos++;
1017 if (*pos==
']')
break;
1020 if (verbose)
EOUT(
"Error syntax in array %s char:%u - expected ',' ", str, (
unsigned) (pos - str));
1032 switch (src.
fKind) {
1033 case kind_none:
return SetNull();
1034 case kind_bool:
return SetBool(src.
valueInt!=0);
1035 case kind_int:
return SetInt(src.
valueInt);
1036 case kind_datime:
return SetDatime(src.
valueUInt);
1037 case kind_uint:
return SetUInt(src.
valueUInt);
1038 case kind_double:
return SetDouble(src.
valueDouble);
1039 case kind_arrint:
return SetArrInt(src.
valueInt, (int64_t*) src.
arrInt);
1040 case kind_arruint:
return SetArrUInt(src.
valueInt, (uint64_t*) src.
arrUInt);
1041 case kind_arrdouble:
return SetArrDouble(src.
valueInt, (
double*) src.
arrDouble);
1042 case kind_string:
return SetStr(src.
valueStr);
1044 case kind_buffer:
return SetBuffer(*src.
valueBuf);
1045 case kind_reference:
return SetReference(*src.
valueRef);
1053 if (cannot_modify())
return false;
1054 if (fKind == kind_none)
return modified(
false);
1062 if (cannot_modify())
return false;
1064 if ((fKind == kind_bool) && (valueInt == (v ? 1 : 0)))
return modified(
false);
1068 valueInt = v ? 1 : 0;
1075 if (cannot_modify())
return false;
1076 if ((fKind == kind_int) && (valueInt == v))
return modified(
false);
1085 if (cannot_modify())
return false;
1086 if ((fKind == kind_datime) && (valueUInt == v))
return modified(
false);
1089 fKind = kind_datime;
1103 if (cannot_modify())
return false;
1105 if ((fKind == kind_uint) && (valueUInt == v))
return modified(
false);
1116 if (cannot_modify())
return false;
1118 if ((fKind == kind_double) && (valueDouble == v))
return modified(
false);
1121 fKind = kind_double;
1129 if (cannot_modify())
return false;
1131 if ((fKind == kind_string) && (v==valueStr))
return modified(
false);
1134 size_t len = v.length();
1135 valueStr = (
char*) malloc(len+1);
1136 if (!valueStr)
return false;
1138 fKind = kind_string;
1139 strncpy(valueStr, v.c_str(), len+1);
1146 if (cannot_modify())
return false;
1148 if ((fKind == kind_string) && v && (strcmp(v,valueStr)==0))
return modified(
false);
1151 size_t len = !v ? 0 : strlen(v);
1152 valueStr = (
char*) malloc(len+1);
1153 if (!valueStr)
return false;
1155 fKind = kind_string;
1156 if (v) strncpy(valueStr, v, len+1);
1164 if (cannot_modify())
return false;
1166 if ((fKind == kind_arrstr) && (valueInt == (int64_t) vect.size())) {
1167 std::vector<std::string> vect0 = AsStrVect();
1168 if (vect0.size() == vect.size()) {
1170 for (
unsigned n=0;n<vect.size();n++)
1171 if (vect[n]!=vect0[n]) diff =
true;
1172 if (!diff)
return modified(
false);
1179 for (
unsigned n=0;n<vect.size();n++)
1180 len += vect[n].length()+1;
1181 valueStr = (
char *) malloc(len);
1182 if (!valueStr)
return false;
1184 fKind = kind_arrstr;
1185 valueInt = (int64_t) vect.size();
1189 for (
unsigned n=0;n<vect.size();n++) {
1190 strncpy(p, vect[n].c_str(), vect[n].length()+1);
1191 p += vect[n].length()+1;
1199 if (cannot_modify())
return false;
1203 fKind = kind_buffer;
1212 if (cannot_modify())
return false;
1216 fKind = kind_reference;
1226 if (cannot_modify() || (size<=0)) {
1227 if (owner)
delete[] arr;
1231 if ((fKind == kind_arrint) && (size==valueInt))
1232 if (memcmp(arrInt, arr, size*
sizeof(int64_t))==0)
1234 if (owner)
delete[] arr;
1235 return modified(
false);
1239 fKind = kind_arrint;
1244 arrInt =
new int64_t[size];
1245 memcpy(arrInt, arr, size*
sizeof(int64_t));
1255 arr =
new int64_t[v.size()];
1256 for (
unsigned n=0;n<v.size();n++)
1259 return SetArrInt(v.size(), arr,
true);
1265 if (cannot_modify())
return false;
1266 if (size<=0)
return false;
1268 if ((fKind == kind_arruint) && (valueInt == size))
1269 if (memcmp(arrUInt, arr, size*
sizeof(uint64_t))==0) {
1270 if (owner)
delete [] arr;
1271 return modified(
false);
1275 fKind = kind_arruint;
1280 arrUInt =
new uint64_t[size];
1281 memcpy(arrUInt, arr, size*
sizeof(uint64_t));
1291 arr =
new uint64_t[v.size()];
1292 for (
unsigned n=0;n<v.size();n++)
1295 return SetArrUInt(v.size(), arr,
true);
1303 arr =
new double[v.size()];
1304 for (
unsigned n=0;n<v.size();n++)
1308 return SetArrDouble(v.size(), arr,
true);
1314 if (cannot_modify())
return false;
1315 if (size<=0)
return false;
1317 if ((fKind == kind_arrdouble) && (valueInt == size))
1318 if (memcmp(arrDouble, arr, size*
sizeof(
double))==0) {
1319 if (owner)
delete[] arr;
1320 return modified(
false);
1324 fKind = kind_arrdouble;
1329 arrDouble =
new double[size];
1330 memcpy(arrDouble, arr, size*
sizeof(
double));
1338 if (cannot_modify())
return false;
1339 if (size<0)
return false;
1342 SetArrStrDirect(size, arr, owner);
1349 fKind = kind_arrstr;
1355 const char* p = arr;
1356 for (
unsigned n=0;n<size;n++) {
1357 int len = strlen(p);
1361 valueStr = (
char*) malloc(fullsize);
1363 memcpy(valueStr, arr, fullsize);
1384 return fMap.find(name) != fMap.end();
1389 FieldsMap::iterator iter = fMap.find(name);
1390 if (iter==fMap.end())
return false;
1399 if (n>=fMap.size())
return "";
1401 for (FieldsMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
1402 if (n==0)
return iter->first;
1411 if (fChanged)
return true;
1413 for (FieldsMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++)
1414 if (iter->second.IsModified())
return true;
1424 for (
auto &&fld: fMap) {
1425 if (fld.second.IsModified())
1426 if (fld.first.find(prefix)==0)
return true;
1436 for (
auto &&fld: fMap)
1437 fld.second.SetModified(
false);
1444 for (FieldsMap::iterator iter = fMap.begin(); iter!=fMap.end(); iter++)
1453 Stream(s, nameprefix);
1459 if (name.empty())
return false;
1461 if (name[0]==
'#')
return false;
1463 return prefix.empty() || (name.find(prefix) == 0);
1469 uint32_t storesz(0), storenum(0), storevers(0);
1472 uint64_t pos = s.
size();
1475 sz = s.
is_real() ? StoreSize(nameprefix) : 0;
1478 for (FieldsMap::iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
1479 if (match_prefix(iter->first, nameprefix)) storenum++;
1485 for (FieldsMap::iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
1486 if (!match_prefix(iter->first, nameprefix))
continue;
1488 iter->second.Stream(s);
1499 sz = ((uint64_t) storesz)*8;
1502 storenum = storenum & 0xffffff;
1505 for (FieldsMap::iterator iter = fMap.begin(); iter!=fMap.end(); iter++)
1506 iter->second.fTouched =
false;
1508 for (uint32_t n=0;n<storenum;n++) {
1516 FieldsMap::iterator iter = fMap.begin();
1518 while (iter!=fMap.end()) {
1519 if (iter->second.fTouched) { iter++;
continue; }
1520 if (!match_prefix(iter->first, nameprefix)) { iter++;
continue; }
1531 for (FieldsMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
1533 if (iter->first.empty() || (iter->first[0]==
'#'))
continue;
1536 if (iter->first.find_first_of(
" #&\"\'!@%^*()=-\\/|~.,") != std::string::npos)
continue;
1538 res.
SetField(iter->first.c_str(), iter->second.AsJson().c_str());
1545 for (FieldsMap::const_iterator iter = src.
fMap.begin(); iter!=src.
fMap.end(); iter++)
1546 if (overwrite || !HasField(iter->first))
1547 fMap[iter->first] = iter->second;
1552 std::vector<std::string> delfields;
1554 for (FieldsMap::iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
1555 if (iter->second.IsProtected())
continue;
1556 if (!src.
HasField(iter->first)) delfields.push_back(iter->first);
1559 for (
unsigned n=0;n<delfields.size();n++)
1560 RemoveField(delfields[n]);
1562 for (FieldsMap::iterator iter = src.
fMap.begin(); iter!=src.
fMap.end(); iter++) {
1566 fMap[iter->first].SetValue(iter->second);
1572 std::vector<std::string> delfields;
1574 for (
auto &&fld : current.
fMap) {
1575 if (!HasField(fld.first))
1576 delfields.push_back(fld.first);
1578 if (!fld.second.fModified) RemoveField(fld.first);
1582 if (delfields.size() > 0)
1583 Field(
"dabc:del").SetStrVect(delfields);
1588 for (FieldsMap::const_iterator iter = diff.
fMap.begin(); iter!=diff.
fMap.end(); iter++) {
1589 if (iter->first !=
"dabc:del") {
1590 fMap[iter->first] = iter->second;
1591 fMap[iter->first].fModified =
true;
1593 std::vector<std::string> delfields = iter->second.AsStrVect();
1594 for (
unsigned n=0;n<delfields.size();n++)
1595 RemoveField(delfields[n]);
1604 Object(0, name, flags | flAutoDestroy),
1610 Object(MakePair(parent, name), flags | flAutoDestroy),
1617 delete fFields; fFields = 0;
1636 DOUT1(
"%s : %s", ClassName(), GetName());
1638 for (
unsigned n=0;n<fFields->NumFields();n++) {
1639 std::string name = fFields->FieldName(n);
1640 std::string value = fFields->Field(name).AsStr();
1641 DOUT1(
" %s = %s", name.c_str(), value.c_str());
1649 bool res = fFields->SaveTo(store);
1662 if (SaveTo(store))
return store.
GetResult();
1670 if (SaveTo(store))
return store.
GetResult();
1682 uint64_t pos = s.
size();
1693 GetObject()->Fields().Stream(s);
1698 std::string objname;
1702 CreateRecord(objname);
1704 GetObject()->SetName(objname.c_str());
1706 GetObject()->Fields().Stream(s);
1721 if (res.
null())
return res;
1726 if (s.
size() != outs.
size()) {
EOUT(
"Stream sizes mismatch %u %u", (
unsigned) s.
size(), (
unsigned) outs.
size()); }
1737 if (buf.
null())
return false;
1741 if (!Stream(inps)) {
1742 EOUT(
"Cannot reconstruct record from the binary data!");
Reference on memory from memory pool.
unsigned SegmentSize(unsigned n=0) const
Returns size on the segment, no any boundary checks.
void SetTotalSize(BufferSize_t len)
Set total length of the buffer to specified value Size cannot be bigger than original size of the buf...
static Buffer CreateBuffer(BufferSize_t sz)
This static method create independent buffer for any other memory pools Therefore it can be used in s...
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Class for holding GMT time with precision of nanoseconds.
std::string AsJSString(int ndecimal=3) const
convert string into sec.frac format, can be interpret directly in JavaScript ISO 8601 standard is use...
uint64_t AsJSDate() const
Return date and time in JS format - number of millisecond since 1.1.1970.
class, used for direct store of records in JSON/XML form
void CloseNode(const char *nodename)
void SetField(const char *name, const char *value)
void BeforeNextChild(const char *basename=0)
void CreateNode(const char *nodename)
Base class for most of the DABC classes.
Container for records fields.
virtual ~RecordContainer()
RecordFieldsMap * TakeFieldsMap()
Remove map and returns to the user.
RecordContainer(const std::string &name, unsigned flags=flIsOwner)
void SetFieldsMap(RecordFieldsMap *newmap)
Replaces existing fields map.
virtual bool SaveTo(HStore &store, bool create_node=true)
virtual void Print(int lvl=0)
Print object content on debug output.
bool SetArrUInt(int64_t size, uint64_t *arr, bool owner=false)
Set as array, if owner flag specified, one get ownership over array and do not need to create copy.
bool fTouched
! when true, field was modified at least once
bool SetArrInt(int64_t size, int64_t *arr, bool owner=false)
Set as array, if owner flag specified, one get ownership over array and do not need to create copy.
void SetArrStrDirect(int64_t size, char *arr, bool owner=false)
bool SetVectInt(const std::vector< int64_t > &v)
Reference * valueRef
! buffer object
bool SetStr(const std::string &v)
bool SetDatime(uint64_t v)
uint64_t * arrUInt
! int array, size in valueInt
std::vector< uint64_t > AsUIntVect() const
static std::string JsonReformat(const std::string &str)
std::vector< std::string > AsStrVect() const
uint64_t valueUInt
scalar int type
uint64_t AsUInt(uint64_t dflt=0) const
dabc::Reference AsReference() const
double * arrDouble
! uint array, size in valueInt
std::vector< int64_t > AsIntVect() const
bool SetVectUInt(const std::vector< uint64_t > &v)
dabc::Buffer AsBuffer() const
bool SetArrDouble(int64_t size, double *arr, bool owner=false)
Set as array, if owner flag specified, one get ownership over array and do not need to create copy.
double valueDouble
scalar unsigned int type
std::string AsJson() const
Returns field value in JSON format.
bool SetReference(const Reference &ref)
bool SetStrVect(const std::vector< std::string > &vect)
bool AsBool(bool dflt=false) const
std::string AsStr(const std::string &dflt="") const
bool SetVectDouble(const std::vector< double > &v)
static bool NeedJsonReformat(const std::string &str)
int64_t AsInt(int64_t dflt=0) const
double AsDouble(double dflt=0.) const
bool SetArrStr(int64_t size, char *arr, bool owner=false)
Sets as array of string, placed one after another in memory.
std::vector< double > AsDoubleVect() const
bool SetValue(const RecordField &src)
char * valueStr
! double array, size in valueInt
bool SetBuffer(const Buffer &buf)
Buffer * valueBuf
! string or array of strings
static bool StrToStrVect(const char *str, std::vector< std::string > &vect, bool verbose=true)
void release()
! when true, field will not be automatically deleted when full list updated from other hierarchy
RecordFieldsMap * Clone()
Create complete copy of fields map.
virtual ~RecordFieldsMap()
std::string FieldName(unsigned n) const
uint64_t StoreSize(const std::string &nameprefix="")
void ApplyDiff(const RecordFieldsMap &diff)
Apply diff map One should use fields, generated with MakeAsDiffTo call.
bool WasChanged() const
Return true if any field was changed or map was modified (removed filed)
void CopyFrom(const RecordFieldsMap &src, bool overwrite=true)
Copy fields from source map.
bool HasField(const std::string &name) const
void MakeAsDiffTo(const RecordFieldsMap &src)
In the map only modified fields are remained Also dabc:delete field can appear which marks all remove...
void MoveFrom(RecordFieldsMap &src)
Move fields from source map, delete no longer existing (except protected)
RecordField & Field(const std::string &name)
Direct access to the fields.
void ClearChangeFlags()
Clear all change flags.
bool WasChangedWith(const std::string &prefix)
Returns true when fields with specified prefix were changed.
static bool match_prefix(const std::string &name, const std::string &prefix)
bool RemoveField(const std::string &name)
bool Stream(iostream &s, const std::string &nameprefix="")
bool SaveTo(HStore &res)
Save all field in json format.
dabc::Buffer SaveToBuffer()
bool ReadFromBuffer(const dabc::Buffer &buf)
std::string SaveToJson(unsigned mask=0)
Store record in JSON form.
std::string SaveToXml(unsigned mask=0)
Store record in XML form.
virtual void CreateRecord(const std::string &name)
Reference on the arbitrary object
void Release()
Releases reference on the object.
bool null() const
Returns true if reference contains nullptr.
class to stream binary data
virtual bool write(const void *src, uint64_t len)
bool write_uint32(uint32_t v)
bool write_int64(int64_t v)
virtual bool is_real() const
bool read_uint64(uint64_t &v)
bool read_double(double &v)
virtual bool read(void *tgt, uint64_t len)
bool read_uint32(uint32_t &v)
static uint64_t str_storesize(const std::string &str)
Returns bytes count, required to store string.
virtual uint64_t size() const
return number of bytes, written or read from the stream
bool skip_object()
Insted of reading object we read size and shift on that size Only can be done where size stored as 32...
bool write_uint64(uint64_t v)
bool read_int64(int64_t &v)
bool read_str(std::string &str)
Restore string from the stream.
bool write_double(double v)
virtual bool shift(uint64_t len)
bool write_str(const std::string &str)
Store string in the stream.
bool verify_size(uint64_t pos, uint64_t sz)
iostream class, which write and read data from memory
virtual bool write(const void *src, uint64_t len)
virtual bool shift(uint64_t len)
virtual bool read(void *tgt, uint64_t len)
virtual uint64_t size() const
return number of bytes, written or read from the stream
special class only to define how many data will be written to the stream
virtual uint64_t size() const
return number of bytes, written or read from the stream
bool str_to_double(const char *val, double *res)
Convert string to double value.
std::string format(const char *fmt,...)
const char * xmlTrueValue
bool str_to_lint(const char *val, long *res)
Convert string to long integer value.
bool str_to_luint(const char *val, long unsigned *res)
Convert string to long unsigned integer value One could use hexadecimal (in form 0xabc100) or decimal...
const char * xmlFalseValue