All Classes Namespaces Files Functions Variables Typedefs Macros Pages
LayoutBuilder.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
2
3#ifndef AWKWARD_LAYOUTBUILDER_H_
4#define AWKWARD_LAYOUTBUILDER_H_
5
8#include "awkward/utils.h"
9
10#include <map>
11#include <algorithm>
12#include <tuple>
13#include <string>
14#include <functional>
15
18#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS awkward::BuilderOptions(1024, 1)
19
20namespace awkward {
21
22 namespace LayoutBuilder {
23
31 template <std::size_t ENUM, typename BUILDER>
32 class Field {
33 public:
34 using Builder = BUILDER;
35
37 std::string
39 return std::to_string(index);
40 }
41
43 const std::size_t index = ENUM;
46 };
47
54 template <typename PRIMITIVE>
55 class Numpy {
56 public:
60 : data_(
62 size_t id = 0;
63 set_id(id);
64 }
65
72 : data_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
73 size_t id = 0;
74 set_id(id);
75 }
76
78 void
79 append(PRIMITIVE x) noexcept {
80 data_.append(x);
81 }
82
86 void
87 extend(PRIMITIVE* ptr, size_t size) noexcept {
88 data_.extend(ptr, size);
89 }
90
92 const std::string&
93 parameters() const noexcept {
94 return parameters_;
95 }
96
98 void
99 set_parameters(std::string parameter) noexcept {
100 parameters_ = parameter;
101 }
102
104 void
105 set_id(size_t& id) noexcept {
106 id_ = id;
107 id++;
108 }
109
111 void
112 clear() noexcept {
113 data_.clear();
114 }
115
117 size_t
118 length() const noexcept {
119 return data_.length();
120 }
121
123 bool
124 is_valid(std::string& /* error */) const noexcept {
125 return true;
126 }
127
129 void
130 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
131 noexcept {
132 names_nbytes["node" + std::to_string(id_) + "-data"] = data_.nbytes();
133 }
134
140 void
141 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
142 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
143 buffers["node" + std::to_string(id_) + "-data"]));
144 }
145
149 void
150 to_buffer(void* buffer, const char* name) const noexcept {
151 if (std::string(name) == std::string("node" + std::to_string(id_) + "-data")) {
152 data_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
153 }
154 }
155
160 void
161 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
162 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
163 buffers["node" + std::to_string(id_) + "-data"]));
164 }
165
168 std::string
169 form() const {
170 std::stringstream form_key;
171 form_key << "node" << id_;
172
173 std::string params("");
174 if (parameters_ == "") {
175 } else {
176 params = std::string(", \"parameters\": { " + parameters_ + " }");
177 }
178
179 if (std::is_arithmetic<PRIMITIVE>::value) {
180 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
181 type_to_name<PRIMITIVE>() + "\"" + params +
182 ", \"form_key\": \"" + form_key.str() + "\" }";
184 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
185 type_to_name<PRIMITIVE>() + "\"" + params +
186 ", \"form_key\": \"" + form_key.str() + "\" }";
187 } else {
188 throw std::runtime_error("type " +
189 std::string(typeid(PRIMITIVE).name()) +
190 "is not supported");
191 }
192 }
193
194 private:
197
199 std::string parameters_;
200
202 size_t id_;
203 };
204
219 template <typename PRIMITIVE, typename BUILDER>
221 public:
225 : offsets_(
227 offsets_.append(0);
228 size_t id = 0;
229 set_id(id);
230 }
231
238 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
239 offsets_.append(0);
240 size_t id = 0;
241 set_id(id);
242 }
243
245 BUILDER&
246 content() noexcept {
247 return content_;
248 }
249
251 BUILDER&
252 begin_list() noexcept {
253 return content_;
254 }
255
258 void
259 end_list() noexcept {
260 offsets_.append(content_.length());
261 }
262
264 const std::string&
265 parameters() const noexcept {
266 return parameters_;
267 }
268
270 void
271 set_parameters(std::string parameter) noexcept {
272 parameters_ = parameter;
273 }
274
276 void
277 set_id(size_t& id) noexcept {
278 id_ = id;
279 id++;
280 content_.set_id(id);
281 }
282
284 void
285 clear() noexcept {
286 offsets_.clear();
287 offsets_.append(0);
288 content_.clear();
289 }
290
292 size_t
293 length() const noexcept {
294 return offsets_.length() - 1;
295 }
296
298 bool
299 is_valid(std::string& error) const noexcept {
300 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
301 std::stringstream out;
302 out << "ListOffset node" << id_ << "has content length "
303 << content_.length() << "but last offset " << offsets_.last()
304 << "\n";
305 error.append(out.str());
306
307 return false;
308 } else {
309 return content_.is_valid(error);
310 }
311 }
312
315 void
316 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
317 noexcept {
318 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
319 offsets_.nbytes();
320 content_.buffer_nbytes(names_nbytes);
321 }
322
328 void
329 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
330 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
331 buffers["node" + std::to_string(id_) + "-offsets"]));
332 content_.to_buffers(buffers);
333 }
334
339 void
340 to_buffer(void* buffer, const char* name) const noexcept {
341 if (std::string(name) == std::string("node" + std::to_string(id_) + "-offsets")) {
342 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
343 }
344 content_.to_buffer(buffer, name);
345 }
346
351 void
352 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
353 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
354 buffers["node" + std::to_string(id_) + "-offsets"]));
355 content_.to_char_buffers(buffers);
356 }
357
360 std::string
361 form() const noexcept {
362 std::stringstream form_key;
363 form_key << "node" << id_;
364 std::string params("");
365 if (parameters_ == "") {
366 } else {
367 params = std::string(", \"parameters\": { " + parameters_ + " }");
368 }
369 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
370 type_to_numpy_like<PRIMITIVE>() +
371 "\", \"content\": " + content_.form() + params +
372 ", \"form_key\": \"" + form_key.str() + "\" }";
373 }
374
375 private:
380
382 BUILDER content_;
383
385 std::string parameters_;
386
388 size_t id_;
389 };
390
391
396 class Empty {
397 public:
400 size_t id = 0;
401 set_id(id);
402 }
403
404 void
405 set_id(size_t& /* id */) noexcept {}
406
407 void
408 clear() noexcept {}
409
411 size_t
412 length() const noexcept {
413 return 0;
414 }
415
417 bool
418 is_valid(std::string& /* error */) const noexcept {
419 return true;
420 }
421
422 void
423 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
424 noexcept {}
425
426 void
427 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
428
429 void
430 to_buffer(void* /* buffer */, const char* /* name */) const noexcept {}
431
436 void
437 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
438
441 std::string
442 form() const noexcept {
443 return "{ \"class\": \"EmptyArray\" }";
444 }
445
446 private:
448 size_t id_;
449 };
450
451
461 template <class MAP = std::map<std::size_t, std::string>,
462 typename... BUILDERS>
463 class Record {
464 public:
465 using RecordContents = typename std::tuple<BUILDERS...>;
466 using UserDefinedMap = MAP;
467
468 template <std::size_t INDEX>
469 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
470
473 size_t id = 0;
474 set_id(id);
475 map_fields(std::index_sequence_for<BUILDERS...>());
476 }
477
484 Record(UserDefinedMap user_defined_field_id_to_name_map)
485 : content_names_(user_defined_field_id_to_name_map) {
486 assert(content_names_.size() == fields_count_);
487 size_t id = 0;
488 set_id(id);
489 }
490
492 const std::vector<std::string>
493 fields() const noexcept {
494 if (content_names_.empty()) {
495 return fields_;
496 } else {
497 std::vector<std::string> result;
498 for (auto it : content_names_) {
499 result.emplace_back(it.second);
500 }
501 return result;
502 }
503 }
504
509 void
510 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
511 content_names_ = user_defined_field_id_to_name_map;
512 }
513
515 template <std::size_t INDEX>
516 typename RecordFieldType<INDEX>::Builder&
517 content() noexcept {
518 return std::get<INDEX>(contents).builder;
519 }
520
522 const std::string&
523 parameters() const noexcept {
524 return parameters_;
525 }
526
528 void
529 set_parameters(std::string parameter) noexcept {
530 parameters_ = parameter;
531 }
532
534 void
535 set_id(size_t& id) noexcept {
536 id_ = id;
537 id++;
538 for (size_t i = 0; i < fields_count_; i++) {
539 visit_at(contents, i, [&id](auto& content) {
540 content.builder.set_id(id);
541 });
542 }
543 }
544
549 void
550 clear() noexcept {
551 for (size_t i = 0; i < fields_count_; i++) {
552 visit_at(contents, i, [](auto& content) {
553 content.builder.clear();
554 });
555 }
556 }
557
559 size_t
560 length() const noexcept {
561 return (std::get<0>(contents).builder.length());
562 }
563
565 bool
566 is_valid(std::string& error) const noexcept {
567 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
568
569 int64_t length = -1;
570 std::vector<size_t> lengths = field_lengths(index_sequence);
571 for (size_t i = 0; i < lengths.size(); i++) {
572 if (length == -1) {
573 length = lengths[i];
574 }
575 else if (length != (int64_t)lengths[i]) {
576 std::stringstream out;
577 out << "Record node" << id_ << " has field \""
578 << fields().at(i) << "\" length " << lengths[i]
579 << " that differs from the first length " << length << "\n";
580 error.append(out.str());
581
582 return false;
583 }
584 }
585
586 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
587 return std::none_of(std::cbegin(valid_fields),
588 std::cend(valid_fields),
589 std::logical_not<bool>());
590 }
591
594 void
595 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
596 noexcept {
597 for (size_t i = 0; i < fields_count_; i++) {
598 visit_at(contents, i, [&names_nbytes](auto& content) {
599 content.builder.buffer_nbytes(names_nbytes);
600 });
601 }
602 }
603
609 void
610 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
611 for (size_t i = 0; i < fields_count_; i++) {
612 visit_at(contents, i, [&buffers](auto& content) {
613 content.builder.to_buffers(buffers);
614 });
615 }
616 }
617
621 void
622 to_buffer(void* buffer, const char* name) const noexcept {
623 for (size_t i = 0; i < fields_count_; i++) {
624 visit_at(contents, i, [&buffer, &name](auto& content) {
625 content.builder.to_buffer(buffer, name);
626 });
627 }
628 }
629
634 void
635 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
636 for (size_t i = 0; i < fields_count_; i++) {
637 visit_at(contents, i, [&buffers](auto& content) {
638 content.builder.to_char_buffers(buffers);
639 });
640 }
641 }
642
645 std::string
646 form() const noexcept {
647 std::stringstream form_key;
648 form_key << "node" << id_;
649 std::string params("");
650 if (parameters_ == "") {
651 } else {
652 params = std::string("\"parameters\": { " + parameters_ + " }, ");
653 }
654 std::stringstream out;
655 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
656 for (size_t i = 0; i < fields_count_; i++) {
657 if (i != 0) {
658 out << ", ";
659 }
660 auto contents_form = [&](auto& content) {
661 out << "\""
662 << (!content_names_.empty() ? content_names_.at(content.index)
663 : content.index_as_field())
664 << +"\": ";
665 out << content.builder.form();
666 };
667 visit_at(contents, i, contents_form);
668 }
669 out << " }, ";
670 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
671 return out.str();
672 }
673
676
677 private:
680 template <std::size_t... S>
681 void
682 map_fields(std::index_sequence<S...>) noexcept {
683 fields_ = std::vector<std::string>(
684 {std::string(std::get<S>(contents).index_as_field())...});
685 }
686
689 template <std::size_t... S>
690 std::vector<size_t>
691 field_lengths(std::index_sequence<S...>) const noexcept {
692 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
693 }
694
696 template <std::size_t... S>
697 std::vector<bool>
698 field_is_valid(std::index_sequence<S...>, std::string& error) const
699 noexcept {
700 return std::vector<bool>(
701 {std::get<S>(contents).builder.is_valid(error)...});
702 }
703
705 std::vector<std::string> fields_;
706
708 UserDefinedMap content_names_;
709
711 std::string parameters_;
712
714 size_t id_;
715
717 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
718 };
719
726 template <typename... BUILDERS>
727 class Tuple {
728 using TupleContents = typename std::tuple<BUILDERS...>;
729
730 template <std::size_t INDEX>
731 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
732
733 public:
736 size_t id = 0;
737 set_id(id);
738 }
739
741 template <std::size_t INDEX>
742 TupleContentType<INDEX>&
743 content() noexcept {
744 return std::get<INDEX>(contents);
745 }
746
748 const std::string&
749 parameters() const noexcept {
750 return parameters_;
751 }
752
754 void
755 set_parameters(std::string parameter) noexcept {
756 parameters_ = parameter;
757 }
758
760 void
761 set_id(size_t& id) noexcept {
762 id_ = id;
763 id++;
764 for (size_t i = 0; i < fields_count_; i++) {
765 visit_at(contents, i, [&id](auto& content) {
766 content.set_id(id);
767 });
768 }
769 }
770
774 void
775 clear() noexcept {
776 for (size_t i = 0; i < fields_count_; i++) {
777 visit_at(contents, i, [](auto& content) {
778 content.clear();
779 });
780 }
781 }
782
784 size_t
785 length() const noexcept {
786 return (std::get<0>(contents).length());
787 }
788
790 bool
791 is_valid(std::string& error) const noexcept {
792 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
793
794 int64_t length = -1;
795 std::vector<size_t> lengths = content_lengths(index_sequence);
796 for (size_t i = 0; i < lengths.size(); i++) {
797 if (length == -1) {
798 length = (int64_t)lengths[i];
799 }
800 else if (length != (int64_t)lengths[i]) {
801 std::stringstream out;
802 out << "Record node" << id_ << " has index \"" << i << "\" length "
803 << lengths[i] << " that differs from the first length "
804 << length << "\n";
805 error.append(out.str());
806
807 return false;
808 }
809 }
810
811 std::vector<bool> valid_fields =
812 content_is_valid(index_sequence, error);
813 return std::none_of(std::cbegin(valid_fields),
814 std::cend(valid_fields),
815 std::logical_not<bool>());
816 }
817
820 void
821 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
822 noexcept {
823 for (size_t i = 0; i < fields_count_; i++) {
824 visit_at(contents, i, [&names_nbytes](auto& content) {
825 content.buffer_nbytes(names_nbytes);
826 });
827 }
828 }
829
835 void
836 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
837 for (size_t i = 0; i < fields_count_; i++) {
838 visit_at(contents, i, [&buffers](auto& content) {
839 content.to_buffers(buffers);
840 });
841 }
842 }
843
847 void
848 to_buffer(void* buffer, const char* name) const noexcept {
849 for (size_t i = 0; i < fields_count_; i++) {
850 visit_at(contents, i, [&buffer, &name](auto& content) {
851 content.to_buffer(buffer, name);
852 });
853 }
854 }
855
860 void
861 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
862 for (size_t i = 0; i < fields_count_; i++) {
863 visit_at(contents, i, [&buffers](auto& content) {
864 content.to_char_buffers(buffers);
865 });
866 }
867 }
868
871 std::string
872 form() const noexcept {
873 std::stringstream form_key;
874 form_key << "node" << id_;
875 std::string params("");
876 if (parameters_ == "") {
877 } else {
878 params = std::string("\"parameters\": { " + parameters_ + " }, ");
879 }
880 std::stringstream out;
881 out << "{ \"class\": \"RecordArray\", \"contents\": [";
882 for (size_t i = 0; i < fields_count_; i++) {
883 if (i != 0) {
884 out << ", ";
885 }
886 auto contents_form = [&out](auto& content) {
887 out << content.form();
888 };
889 visit_at(contents, i, contents_form);
890 }
891 out << "], ";
892 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
893 return out.str();
894 }
895
897 TupleContents contents;
898
899 private:
902 template <std::size_t... S>
903 std::vector<size_t>
904 content_lengths(std::index_sequence<S...>) const noexcept {
905 return std::vector<size_t>({std::get<S>(contents).length()...});
906 }
907
909 template <std::size_t... S>
910 std::vector<bool>
911 content_is_valid(std::index_sequence<S...>, std::string& error) const
912 noexcept {
913 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
914 }
915
917 std::vector<int64_t> field_index_;
918
920 std::string parameters_;
921
923 size_t id_;
924
926 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
927 };
928
942 template <unsigned SIZE, typename BUILDER>
943 class Regular {
944 public:
946 Regular() : length_(0) {
947 size_t id = 0;
948 set_id(id);
949 }
950
952 BUILDER&
953 content() noexcept {
954 return content_;
955 }
956
959 BUILDER&
960 begin_list() noexcept {
961 return content_;
962 }
963
965 void
966 end_list() noexcept {
967 length_++;
968 }
969
971 const std::string&
972 parameters() const noexcept {
973 return parameters_;
974 }
975
977 void
978 set_parameters(std::string parameter) noexcept {
979 parameters_ = parameter;
980 }
981
983 void
984 set_id(size_t& id) noexcept {
985 id_ = id;
986 id++;
987 content_.set_id(id);
988 }
989
991 void
992 clear() noexcept {
993 length_ = 0;
994 content_.clear();
995 }
996
998 size_t
999 length() const noexcept {
1000 return length_;
1001 }
1002
1004 bool
1005 is_valid(std::string& error) const noexcept {
1006 if (content_.length() != length_ * size_) {
1007 std::stringstream out;
1008 out << "Regular node" << id_ << "has content length "
1009 << content_.length() << ", but length " << length_ << " and size "
1010 << size_ << "\n";
1011 error.append(out.str());
1012
1013 return false;
1014 } else {
1015 return content_.is_valid(error);
1016 }
1017 }
1018
1021 void
1022 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1023 noexcept {
1024 content_.buffer_nbytes(names_nbytes);
1025 }
1026
1032 void
1033 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1034 content_.to_buffers(buffers);
1035 }
1036
1040 void
1041 to_buffer(void* buffer, const char* name) const noexcept {
1042 content_.to_buffer(buffer, name);
1043 }
1044
1049 void
1050 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1051 content_.to_char_buffers(buffers);
1052 }
1053
1056 std::string
1057 form() const noexcept {
1058 std::stringstream form_key;
1059 form_key << "node" << id_;
1060 std::string params("");
1061 if (parameters_ == "") {
1062 } else {
1063 params = std::string(", \"parameters\": { " + parameters_ + " }");
1064 }
1065 return "{ \"class\": \"RegularArray\", \"content\": " +
1066 content_.form() + ", \"size\": " + std::to_string(size_) +
1067 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1068 }
1069
1070 private:
1072 BUILDER content_;
1073
1075 std::string parameters_;
1076
1078 size_t id_;
1079
1081 size_t length_;
1082
1084 size_t size_ = SIZE;
1085 };
1086
1087
1097 template <typename PRIMITIVE, typename BUILDER>
1098 class Indexed {
1099 public:
1103 : index_(
1105 size_t id = 0;
1106 set_id(id);
1107 }
1108
1115 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
1116 size_t id = 0;
1117 set_id(id);
1118 }
1119
1121 BUILDER&
1122 content() noexcept {
1123 return content_;
1124 }
1125
1128 BUILDER&
1129 append_index() noexcept {
1130 index_.append(content_.length());
1131 return content_;
1132 }
1133
1138 BUILDER&
1139 extend_index(size_t size) noexcept {
1140 size_t start = content_.length();
1141 size_t stop = start + size;
1142 for (size_t i = start; i < stop; i++) {
1143 index_.append(i);
1144 }
1145 return content_;
1146 }
1147
1149 const std::string&
1150 parameters() const noexcept {
1151 return parameters_;
1152 }
1153
1155 void
1156 set_parameters(std::string parameter) noexcept {
1157 parameters_ = parameter;
1158 }
1159
1161 void
1162 set_id(size_t& id) noexcept {
1163 id_ = id;
1164 id++;
1165 content_.set_id(id);
1166 }
1167
1170 void
1171 clear() noexcept {
1172 index_.clear();
1173 content_.clear();
1174 }
1175
1177 size_t
1178 length() const noexcept {
1179 return index_.length();
1180 }
1181
1184 void
1185 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1186 noexcept {
1187 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1188 content_.buffer_nbytes(names_nbytes);
1189 }
1190
1192 bool
1193 is_valid(std::string& error) const noexcept {
1194 if (content_.length() != index_.length()) {
1195 std::stringstream out;
1196 out << "Indexed node" << id_ << " has content length "
1197 << content_.length() << " but index has length " << index_.length()
1198 << "\n";
1199 error.append(out.str());
1200
1201 return false;
1202 } else {
1203 return content_.is_valid(error);
1204 }
1205 }
1206
1212 void
1213 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1214 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1215 buffers["node" + std::to_string(id_) + "-index"]));
1216 content_.to_buffers(buffers);
1217 }
1218
1223 void
1224 to_buffer(void* buffer, const char* name) const noexcept {
1225 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1226 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1227 }
1228 content_.to_buffer(buffer, name);
1229 }
1230
1235 void
1236 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1237 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1238 buffers["node" + std::to_string(id_) + "-index"]));
1239 content_.to_char_buffers(buffers);
1240 }
1241
1244 std::string
1245 form() const noexcept {
1246 std::stringstream form_key;
1247 form_key << "node" << id_;
1248 std::string params("");
1249 if (parameters_ == "") {
1250 } else {
1251 params = std::string(", \"parameters\": { " + parameters_ + " }");
1252 }
1253 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1254 type_to_numpy_like<PRIMITIVE>() +
1255 "\", \"content\": " + content_.form() + params +
1256 ", \"form_key\": \"" + form_key.str() + "\" }";
1257 }
1258
1259 private:
1264
1266 BUILDER content_;
1267
1269 std::string parameters_;
1270
1272 size_t id_;
1273 };
1274
1285 template <typename PRIMITIVE, typename BUILDER>
1287 public:
1291 : index_(
1293 last_valid_(-1) {
1294 size_t id = 0;
1295 set_id(id);
1296 }
1297
1304 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1305 last_valid_(-1) {
1306 size_t id = 0;
1307 set_id(id);
1308 }
1309
1311 BUILDER&
1312 content() noexcept {
1313 return content_;
1314 }
1315
1318 BUILDER&
1319 append_valid() noexcept {
1320 last_valid_ = content_.length();
1321 index_.append(last_valid_);
1322 return content_;
1323 }
1324
1329 BUILDER&
1330 extend_valid(size_t size) noexcept {
1331 size_t start = content_.length();
1332 size_t stop = start + size;
1333 last_valid_ = stop - 1;
1334 for (size_t i = start; i < stop; i++) {
1335 index_.append(i);
1336 }
1337 return content_;
1338 }
1339
1341 void
1342 append_invalid() noexcept {
1343 index_.append(-1);
1344 }
1345
1349 void
1350 extend_invalid(size_t size) noexcept {
1351 for (size_t i = 0; i < size; i++) {
1352 index_.append(-1);
1353 }
1354 }
1355
1357 const std::string&
1358 parameters() const noexcept {
1359 return parameters_;
1360 }
1361
1363 void
1364 set_parameters(std::string parameter) noexcept {
1365 parameters_ = parameter;
1366 }
1367
1369 void
1370 set_id(size_t& id) noexcept {
1371 id_ = id;
1372 id++;
1373 content_.set_id(id);
1374 }
1375
1378 void
1379 clear() noexcept {
1380 last_valid_ = -1;
1381 index_.clear();
1382 content_.clear();
1383 }
1384
1386 size_t
1387 length() const noexcept {
1388 return index_.length();
1389 }
1390
1392 bool
1393 is_valid(std::string& error) const noexcept {
1394 if (content_.length() != last_valid_ + 1) {
1395 std::stringstream out;
1396 out << "IndexedOption node" << id_ << " has content length "
1397 << content_.length() << " but last valid index is " << last_valid_
1398 << "\n";
1399 error.append(out.str());
1400
1401 return false;
1402 } else {
1403 return content_.is_valid(error);
1404 }
1405 }
1406
1409 void
1410 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1411 noexcept {
1412 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1413 content_.buffer_nbytes(names_nbytes);
1414 }
1415
1421 void
1422 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1423 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1424 buffers["node" + std::to_string(id_) + "-index"]));
1425 content_.to_buffers(buffers);
1426 }
1427
1432 void
1433 to_buffer(void* buffer, const char* name) const noexcept {
1434 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1435 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1436 }
1437 content_.to_buffer(buffer, name);
1438 }
1439
1444 void
1445 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1446 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1447 buffers["node" + std::to_string(id_) + "-index"]));
1448 content_.to_char_buffers(buffers);
1449 }
1450
1453 std::string
1454 form() const noexcept {
1455 std::stringstream form_key;
1456 form_key << "node" << id_;
1457 std::string params("");
1458 if (parameters_ == "") {
1459 } else {
1460 params = std::string(", \"parameters\": { " + parameters_ + " }");
1461 }
1462 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1463 type_to_numpy_like<PRIMITIVE>() +
1464 "\", \"content\": " + content_.form() + params +
1465 ", \"form_key\": \"" + form_key.str() + "\" }";
1466 }
1467
1468 private:
1473
1475 BUILDER content_;
1476
1478 std::string parameters_;
1479
1481 size_t id_;
1482
1484 size_t last_valid_;
1485 };
1486
1498 template <typename BUILDER>
1499 class Unmasked {
1500 public:
1503 size_t id = 0;
1504 set_id(id);
1505 }
1506
1508 BUILDER&
1509 content() noexcept {
1510 return content_;
1511 }
1512
1514 const std::string&
1515 parameters() const noexcept {
1516 return parameters_;
1517 }
1518
1520 void
1521 set_parameters(std::string parameter) noexcept {
1522 parameters_ = parameter;
1523 }
1524
1526 void
1527 set_id(size_t& id) noexcept {
1528 id_ = id;
1529 id++;
1530 content_.set_id(id);
1531 }
1532
1534 void
1535 clear() noexcept {
1536 content_.clear();
1537 }
1538
1540 size_t
1541 length() const noexcept {
1542 return content_.length();
1543 }
1544
1546 bool
1547 is_valid(std::string& error) const noexcept {
1548 return content_.is_valid(error);
1549 }
1550
1553 void
1554 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1555 noexcept {
1556 content_.buffer_nbytes(names_nbytes);
1557 }
1558
1564 void
1565 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1566 content_.to_buffers(buffers);
1567 }
1568
1572 void
1573 to_buffer(void* buffer, const char* name) const noexcept {
1574 content_.to_buffer(buffer, name);
1575 }
1576
1581 void
1582 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1583 content_.to_char_buffers(buffers);
1584 }
1585
1588 std::string
1589 form() const noexcept {
1590 std::stringstream form_key;
1591 form_key << "node" << id_;
1592 std::string params("");
1593 if (parameters_ == "") {
1594 } else {
1595 params = std::string(", \"parameters\": { " + parameters_ + " }");
1596 }
1597 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1598 content_.form() + params + ", \"form_key\": \"" +
1599 form_key.str() + "\" }";
1600 }
1601
1602 private:
1604 BUILDER content_;
1605
1607 std::string parameters_;
1608
1610 size_t id_;
1611 };
1612
1629 template <bool VALID_WHEN, typename BUILDER>
1631 public:
1636 size_t id = 0;
1637 set_id(id);
1638 }
1639
1646 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1647 size_t id = 0;
1648 set_id(id);
1649 }
1650
1652 BUILDER&
1653 content() noexcept {
1654 return content_;
1655 }
1656
1658 bool
1659 valid_when() const noexcept {
1660 return valid_when_;
1661 }
1662
1666 BUILDER&
1667 append_valid() noexcept {
1668 mask_.append(valid_when_);
1669 return content_;
1670 }
1671
1677 BUILDER&
1678 extend_valid(size_t size) noexcept {
1679 for (size_t i = 0; i < size; i++) {
1680 mask_.append(valid_when_);
1681 }
1682 return content_;
1683 }
1684
1688 BUILDER&
1689 append_invalid() noexcept {
1690 mask_.append(!valid_when_);
1691 return content_;
1692 }
1693
1699 BUILDER&
1700 extend_invalid(size_t size) noexcept {
1701 for (size_t i = 0; i < size; i++) {
1702 mask_.append(!valid_when_);
1703 }
1704 return content_;
1705 }
1706
1708 const std::string&
1709 parameters() const noexcept {
1710 return parameters_;
1711 }
1712
1714 void
1715 set_parameters(std::string parameter) noexcept {
1716 parameters_ = parameter;
1717 }
1718
1720 void
1721 set_id(size_t& id) noexcept {
1722 id_ = id;
1723 id++;
1724 content_.set_id(id);
1725 }
1726
1729 void
1730 clear() noexcept {
1731 mask_.clear();
1732 content_.clear();
1733 }
1734
1736 size_t
1737 length() const noexcept {
1738 return mask_.length();
1739 }
1740
1742 bool
1743 is_valid(std::string& error) const noexcept {
1744 if (content_.length() != mask_.length()) {
1745 std::stringstream out;
1746 out << "ByteMasked node" << id_ << "has content length "
1747 << content_.length() << "but mask length " << mask_.length()
1748 << "\n";
1749 error.append(out.str());
1750
1751 return false;
1752 } else {
1753 return content_.is_valid(error);
1754 }
1755 }
1756
1759 void
1760 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1761 noexcept {
1762 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1763 content_.buffer_nbytes(names_nbytes);
1764 }
1765
1771 void
1772 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1773 mask_.concatenate(reinterpret_cast<int8_t*>(
1774 buffers["node" + std::to_string(id_) + "-mask"]));
1775 content_.to_buffers(buffers);
1776 }
1777
1782 void
1783 to_buffer(void* buffer, const char* name) const noexcept {
1784 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
1785 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
1786 }
1787 content_.to_buffer(buffer, name);
1788 }
1789
1794 void
1795 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1796 mask_.concatenate(reinterpret_cast<int8_t*>(
1797 buffers["node" + std::to_string(id_) + "-mask"]));
1798 content_.to_char_buffers(buffers);
1799 }
1800
1803 std::string
1804 form() const noexcept {
1805 std::stringstream form_key, form_valid_when;
1806 form_key << "node" << id_;
1807 form_valid_when << std::boolalpha << valid_when_;
1808 std::string params("");
1809 if (parameters_ == "") {
1810 } else {
1811 params = std::string(", \"parameters\": { " + parameters_ + " }");
1812 }
1813 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1814 "\"content\": " +
1815 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1816 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1817 }
1818
1819 private:
1824
1826 BUILDER content_;
1827
1829 std::string parameters_;
1830
1832 size_t id_;
1833
1835 bool valid_when_ = VALID_WHEN;
1836 };
1837
1854 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1856 public:
1861 current_byte_(uint8_t(0)),
1862 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1863 current_index_(0) {
1864 size_t id = 0;
1865 set_id(id);
1866 if (lsb_order_) {
1867 for (size_t i = 0; i < 8; i++) {
1868 cast_[i] = 1 << i;
1869 }
1870 } else {
1871 for (size_t i = 0; i < 8; i++) {
1872 cast_[i] = 128 >> i;
1873 }
1874 }
1875 }
1876
1883 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
1884 current_byte_(uint8_t(0)),
1885 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1886 current_index_(0) {
1887 size_t id = 0;
1888 set_id(id);
1889 if (lsb_order_) {
1890 for (size_t i = 0; i < 8; i++) {
1891 cast_[i] = 1 << i;
1892 }
1893 } else {
1894 for (size_t i = 0; i < 8; i++) {
1895 cast_[i] = 128 >> i;
1896 }
1897 }
1898 }
1899
1901 BUILDER&
1902 content() noexcept {
1903 return content_;
1904 }
1905
1907 bool
1908 valid_when() const noexcept {
1909 return valid_when_;
1910 }
1911
1914 bool
1915 lsb_order() const noexcept {
1916 return lsb_order_;
1917 }
1918
1923 BUILDER&
1924 append_valid() noexcept {
1925 append_begin();
1926 current_byte_ |= cast_[current_index_];
1927 append_end();
1928 return content_;
1929 }
1930
1937 BUILDER&
1938 extend_valid(size_t size) noexcept {
1939 for (size_t i = 0; i < size; i++) {
1940 append_valid();
1941 }
1942 return content_;
1943 }
1944
1948 BUILDER&
1949 append_invalid() noexcept {
1950 append_begin();
1951 append_end();
1952 return content_;
1953 }
1954
1960 BUILDER&
1961 extend_invalid(size_t size) noexcept {
1962 for (size_t i = 0; i < size; i++) {
1964 }
1965 return content_;
1966 }
1967
1969 const std::string&
1970 parameters() const noexcept {
1971 return parameters_;
1972 }
1973
1975 void
1976 set_parameters(std::string parameter) noexcept {
1977 parameters_ = parameter;
1978 }
1979
1981 void
1982 set_id(size_t& id) noexcept {
1983 id_ = id;
1984 id++;
1985 content_.set_id(id);
1986 }
1987
1990 void
1991 clear() noexcept {
1992 mask_.clear();
1993 content_.clear();
1994 current_byte_ = 0;
1995 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
1996 current_index_ = 0;
1997 }
1998
2000 size_t
2001 length() const noexcept {
2002 return mask_.length() > 0 ?
2003 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2004 }
2005
2007 bool
2008 is_valid(std::string& error) const noexcept {
2009 if (content_.length() != length()) {
2010 std::stringstream out;
2011 out << "BitMasked node" << id_ << "has content length "
2012 << content_.length() << "but bit mask length " << mask_.length()
2013 << "\n";
2014 error.append(out.str());
2015
2016 return false;
2017 } else {
2018 return content_.is_valid(error);
2019 }
2020 }
2021
2024 void
2025 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2026 noexcept {
2027 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2028 content_.buffer_nbytes(names_nbytes);
2029 }
2030
2036 void
2037 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2038 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2039 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2040 mask_.append(reinterpret_cast<uint8_t*>(
2041 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2042 content_.to_buffers(buffers);
2043 }
2044
2049 void
2050 to_buffer(void* buffer, const char* name) const noexcept {
2051 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2052 mask_.concatenate_from(reinterpret_cast<uint8_t*>(buffer), 0, 1);
2053 mask_.append(reinterpret_cast<uint8_t*>(buffer), mask_.length() - 1, 0, 1);
2054 }
2055 content_.to_buffer(buffer, name);
2056 }
2057
2062 void
2063 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2064 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2065 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2066 mask_.append(reinterpret_cast<uint8_t*>(
2067 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2068 content_.to_char_buffers(buffers);
2069 }
2070
2073 std::string
2074 form() const noexcept {
2075 std::stringstream form_key, form_valid_when, form_lsb_order;
2076 form_key << "node" << id_;
2077 form_valid_when << std::boolalpha << valid_when_;
2078 form_lsb_order << std::boolalpha << lsb_order_;
2079 std::string params("");
2080 if (parameters_ == "") {
2081 } else {
2082 params = std::string(", \"parameters\": { " + parameters_ + " }");
2083 }
2084 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2085 "\"content\": " +
2086 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2087 ", \"lsb_order\": " + form_lsb_order.str() + params +
2088 ", \"form_key\": \"" + form_key.str() + "\" }";
2089 }
2090
2091 private:
2095 void
2096 append_begin() {
2097 if (current_index_ == 8) {
2098 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2099 current_byte_ = uint8_t(0);
2100 current_index_ = 0;
2101 }
2102 }
2103
2109 void
2110 append_end() {
2111 current_index_ += 1;
2112 if (valid_when_) {
2113 current_byte_ref_ = current_byte_;
2114 } else {
2115 current_byte_ref_ = ~current_byte_;
2116 }
2117 }
2118
2122 GrowableBuffer<uint8_t> mask_;
2123
2125 BUILDER content_;
2126
2128 std::string parameters_;
2129
2131 size_t id_;
2132
2134 uint8_t current_byte_;
2135
2137 uint8_t& current_byte_ref_;
2138
2140 size_t current_index_;
2141
2143 uint8_t cast_[8];
2144
2146 bool valid_when_ = VALID_WHEN;
2147
2150 bool lsb_order_ = LSB_ORDER;
2151 };
2152
2168 template <typename TAGS, typename INDEX, typename... BUILDERS>
2169 class Union {
2170 public:
2171 using Contents = typename std::tuple<BUILDERS...>;
2172
2173 template <std::size_t I>
2174 using ContentType = std::tuple_element_t<I, Contents>;
2175
2181 size_t id = 0;
2182 set_id(id);
2183 for (size_t i = 0; i < contents_count_; i++) {
2184 last_valid_index_[i] = -1;
2185 }
2186 }
2187
2194 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2195 index_(awkward::GrowableBuffer<INDEX>(options)) {
2196 size_t id = 0;
2197 set_id(id);
2198 for (size_t i = 0; i < contents_count_; i++) {
2199 last_valid_index_[i] = -1;
2200 }
2201 }
2202
2203 template <std::size_t I>
2204 ContentType<I>&
2205 content() noexcept {
2206 return std::get<I>(contents_);
2207 }
2208
2211 template <std::size_t TAG>
2212 ContentType<TAG>&
2213 append_content() noexcept {
2214 auto& which_content = std::get<TAG>(contents_);
2215 INDEX next_index = which_content.length();
2216
2217 TAGS tag = (TAGS)TAG;
2218 last_valid_index_[tag] = next_index;
2219 tags_.append(tag);
2220 index_.append(next_index);
2221
2222 return which_content;
2223 }
2224
2226 const std::string&
2227 parameters() const noexcept {
2228 return parameters_;
2229 }
2230
2232 void
2233 set_parameters(std::string parameter) noexcept {
2234 parameters_ = parameter;
2235 }
2236
2238 void
2239 set_id(size_t& id) noexcept {
2240 id_ = id;
2241 id++;
2242 auto contents_id = [&id](auto& content) {
2243 content.set_id(id);
2244 };
2245 for (size_t i = 0; i < contents_count_; i++) {
2246 visit_at(contents_, i, contents_id);
2247 }
2248 }
2249
2254 void
2255 clear() noexcept {
2256 for (size_t i = 0; i < contents_count_; i++) {
2257 last_valid_index_[i] = -1;
2258 }
2259 tags_.clear();
2260 index_.clear();
2261 auto clear_contents = [](auto& content) {
2262 content.clear();
2263 };
2264 for (size_t i = 0; i < contents_count_; i++) {
2265 visit_at(contents_, i, clear_contents);
2266 }
2267 }
2268
2270 size_t
2271 length() const noexcept {
2272 return tags_.length();
2273 }
2274
2276 bool
2277 is_valid(std::string& error) const noexcept {
2278 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2279
2280 std::vector<size_t> lengths = content_lengths(index_sequence);
2281 for (size_t tag = 0; tag < contents_count_; tag++) {
2282 if (lengths[tag] != last_valid_index_[tag] + 1) {
2283 std::stringstream out;
2284 out << "Union node" << id_ << " has content length " << lengths[tag]
2285 << " but index length " << last_valid_index_[tag] << "\n";
2286 error.append(out.str());
2287
2288 return false;
2289 }
2290 }
2291
2292 std::vector<bool> valid_contents =
2293 content_is_valid(index_sequence, error);
2294 return std::none_of(std::cbegin(valid_contents),
2295 std::cend(valid_contents),
2296 std::logical_not<bool>());
2297 }
2298
2301 void
2302 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2303 noexcept {
2304 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2305
2306 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2307 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2308
2309 for (size_t i = 0; i < contents_count_; i++) {
2310 visit_at(contents_, i, [&names_nbytes](auto& content) {
2311 content.buffer_nbytes(names_nbytes);
2312 });
2313 }
2314 }
2315
2321 void
2322 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2323 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2324
2325 tags_.concatenate(reinterpret_cast<TAGS*>(
2326 buffers["node" + std::to_string(id_) + "-tags"]));
2327 index_.concatenate(reinterpret_cast<INDEX*>(
2328 buffers["node" + std::to_string(id_) + "-index"]));
2329
2330 for (size_t i = 0; i < contents_count_; i++) {
2331 visit_at(contents_, i, [&buffers](auto& content) {
2332 content.to_buffers(buffers);
2333 });
2334 }
2335 }
2336
2341 void
2342 to_buffer(void* buffer, const char* name) const noexcept {
2343 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2344
2345 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2346 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2347 }
2348 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2349 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2350 }
2351
2352 for (size_t i = 0; i < contents_count_; i++) {
2353 visit_at(contents_, i, [&buffer, &name](auto& content) {
2354 content.to_buffer(buffer, name);
2355 });
2356 }
2357 }
2358
2363 void
2364 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2365 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2366
2367 tags_.concatenate(reinterpret_cast<TAGS*>(
2368 buffers["node" + std::to_string(id_) + "-tags"]));
2369 index_.concatenate(reinterpret_cast<INDEX*>(
2370 buffers["node" + std::to_string(id_) + "-index"]));
2371
2372 for (size_t i = 0; i < contents_count_; i++) {
2373 visit_at(contents_, i, [&buffers](auto& content) {
2374 content.to_char_buffers(buffers);
2375 });
2376 }
2377 }
2378
2381 std::string
2382 form() const noexcept {
2383 std::stringstream form_key;
2384 form_key << "node" << id_;
2385 std::string params("");
2386 if (parameters_ == "") {
2387 } else {
2388 params = std::string(", \"parameters\": { " + parameters_ + " }");
2389 }
2390 std::stringstream out;
2391 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2392 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2393 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2394 for (size_t i = 0; i < contents_count_; i++) {
2395 if (i != 0) {
2396 out << ", ";
2397 }
2398 auto contents_form = [&](auto& content) {
2399 out << content.form();
2400 };
2401 visit_at(contents_, i, contents_form);
2402 }
2403 out << "], ";
2404 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2405 return out.str();
2406 }
2407
2408 private:
2411 template <std::size_t... S>
2412 std::vector<size_t>
2413 content_lengths(std::index_sequence<S...>) const {
2414 return std::vector<size_t>({std::get<S>(contents_).length()...});
2415 }
2416
2418 template <std::size_t... S>
2419 std::vector<bool>
2420 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2421 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2422 }
2423
2427 GrowableBuffer<TAGS> tags_;
2428
2432 GrowableBuffer<INDEX> index_;
2433
2435 Contents contents_;
2436
2438 std::string parameters_;
2439
2441 size_t id_;
2442
2444 size_t last_valid_index_[sizeof...(BUILDERS)];
2445
2447 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2448 };
2449
2450 } // namespace LayoutBuilder
2451} // namespace awkward
2452
2453#endif // AWKWARD_LAYOUTBUILDER_H_
#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS
Object of BuilderOptions which sets the values of the default options.
Definition LayoutBuilder.h:18
virtual const std::string to_buffers(BuffersContainer &container, int64_t &form_key_id) const =0
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
virtual void clear()=0
Removes all accumulated data without resetting the type knowledge.
virtual const BuilderPtr index(int64_t index)=0
Sets the pointer to a given tuple field index; the next command will fill that slot.
Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels)...
Definition GrowableBuffer.h:233
void concatenate_from(PRIMITIVE *external_pointer, size_t to, size_t from) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:517
size_t nbytes() const
Currently used number of bytes.
Definition GrowableBuffer.h:440
void concatenate(PRIMITIVE *external_pointer) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:492
PRIMITIVE & append_and_get_ref(PRIMITIVE datum)
Like append, but the type signature returns the reference to PRIMITIVE.
Definition GrowableBuffer.h:484
size_t length() const
Currently used number of elements.
Definition GrowableBuffer.h:408
void append(PRIMITIVE datum)
Inserts one datum into the panel, possibly triggering allocation of a new panel.
Definition GrowableBuffer.h:450
void clear()
Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.
Definition GrowableBuffer.h:421
Builds a BitMaskedArray in which mask values are packed into a bitmap.
Definition LayoutBuilder.h:1855
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1908
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1991
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:1915
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:1949
BUILDER & extend_valid(size_t size) noexcept
Sets size number of bits in the mask. If current_byte_ and cast_: 0 indicates null,...
Definition LayoutBuilder.h:1938
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2074
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1970
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1976
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1902
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2001
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2063
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1982
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2008
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1882
BUILDER & append_valid() noexcept
Sets a bit in the mask. If current_byte_ and cast_: 0 indicates null, 1 indicates valid and vice vers...
Definition LayoutBuilder.h:1924
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2025
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:1961
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:2050
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1859
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2037
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1630
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1659
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1730
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1689
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1678
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1804
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1709
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1634
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1715
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1653
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1645
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1737
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1795
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1721
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1743
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1667
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1760
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1700
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1783
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1772
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:396
void clear() noexcept
Definition LayoutBuilder.h:408
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:418
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:442
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:427
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:430
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:399
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:405
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:412
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:423
void to_char_buffers(std::map< std::string, uint8_t * > &) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:437
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:32
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:38
BUILDER Builder
Definition LayoutBuilder.h:34
const std::size_t index
The index of a Record field.
Definition LayoutBuilder.h:43
Builder builder
The content type of field in a Record.
Definition LayoutBuilder.h:45
Builds an IndexedOptionArray which consists of an index buffer. The negative values in the index are ...
Definition LayoutBuilder.h:1286
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1379
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1350
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid index in the index buffer and returns the reference to the builder conte...
Definition LayoutBuilder.h:1330
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1454
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1358
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1364
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1303
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1312
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1387
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1445
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1370
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1393
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1290
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1319
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1410
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1342
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1433
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1422
Builds an IndexedArray which consists of an index buffer.
Definition LayoutBuilder.h:1098
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1171
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1245
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1114
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1150
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1102
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1129
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1156
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1122
BUILDER & extend_index(size_t size) noexcept
Inserts size number indices in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1139
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1178
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1236
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1162
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1193
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1185
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1224
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1213
Builds a ListOffsetArray which describes unequal-length lists (often called a "jagged" or "ragged" ar...
Definition LayoutBuilder.h:220
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:285
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:252
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:224
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:361
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:265
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:271
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:246
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:293
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:352
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:277
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:299
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:259
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:316
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:340
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:237
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:329
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:55
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:112
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:124
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:71
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:93
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:99
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:118
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:161
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:79
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
Definition LayoutBuilder.h:59
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:105
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the name and size (in bytes) of the buffer.
Definition LayoutBuilder.h:130
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:87
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:150
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a user-defined pointer.
Definition LayoutBuilder.h:141
std::string form() const
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:169
Builds a RecordArray which represents an array of records, which can be of same or different types....
Definition LayoutBuilder.h:463
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:550
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:472
MAP UserDefinedMap
Definition LayoutBuilder.h:466
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:646
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:517
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:469
Record(UserDefinedMap user_defined_field_id_to_name_map)
Creates a new Record layout builder, taking a user-defined map with enumerated type field ID as keys ...
Definition LayoutBuilder.h:484
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:523
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:465
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:529
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:560
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:635
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:535
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:566
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:595
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:510
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:622
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:493
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:610
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:675
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:943
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:992
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:960
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1057
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:972
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:978
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:953
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:999
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1050
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:984
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1005
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:966
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1022
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1041
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:946
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1033
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:727
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:775
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:897
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:872
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:735
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:749
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:755
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:785
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:861
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:743
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:761
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:791
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:821
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:848
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:836
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:2169
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2255
Union(const awkward::BuilderOptions &options)
Creates a new Union layout builder by allocating new tags and index buffers, taking options from Buil...
Definition LayoutBuilder.h:2193
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2171
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2174
ContentType< TAG > & append_content() noexcept
Inserts the current tag in the tags buffer and the next index in the index buffer and returns the ref...
Definition LayoutBuilder.h:2213
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2382
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2227
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2233
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2271
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2364
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2178
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2205
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2239
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2277
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2302
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffers to user-defined pointers if the g...
Definition LayoutBuilder.h:2342
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2322
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1499
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1535
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1502
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1589
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1515
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1521
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1509
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1541
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1582
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1527
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1547
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1554
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1573
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1565
Definition ArrayBuilder.h:14
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:263
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20
Definition utils.h:168
std::map< std::size_t, std::string > UserDefinedMap
Definition test_1494-layout-builder.cpp:39