Loading...
Searching...
No Matches
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
28 public:
29 BuilderSetId(size_t& id) : id_(id) {}
30
31 template <class CONTENT>
32 void operator()(CONTENT& content) {
33 content.builder.set_id(id_);
34 }
35
36 private:
37 size_t& id_;
38 };
39
47 template <std::size_t ENUM, typename BUILDER>
48 class Field {
49 public:
50 using Builder = BUILDER;
51
53 std::string
55 return std::to_string(index);
56 }
57
59 const std::size_t index = ENUM;
62 };
63
70 template <typename PRIMITIVE>
71 class Numpy {
72 public:
76 : data_(
78 size_t id = 0;
79 set_id(id);
80 }
81
88 : data_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
89 size_t id = 0;
90 set_id(id);
91 }
92
94 void
95 append(PRIMITIVE x) noexcept {
96 data_.append(x);
97 }
98
102 void
103 extend(PRIMITIVE* ptr, size_t size) noexcept {
104 data_.extend(ptr, size);
105 }
106
108 const std::string&
109 parameters() const noexcept {
110 return parameters_;
111 }
112
114 void
115 set_parameters(std::string parameter) noexcept {
116 parameters_ = parameter;
117 }
118
120 void
121 set_id(size_t& id) noexcept {
122 id_ = id;
123 id++;
124 }
125
127 void
128 clear() noexcept {
129 data_.clear();
130 }
131
133 size_t
134 length() const noexcept {
135 return data_.length();
136 }
137
139 bool
140 is_valid(std::string& /* error */) const noexcept {
141 return true;
142 }
143
145 void
146 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
147 noexcept {
148 names_nbytes["node" + std::to_string(id_) + "-data"] = data_.nbytes();
149 }
150
156 void
157 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
158 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
159 buffers["node" + std::to_string(id_) + "-data"]));
160 }
161
165 void
166 to_buffer(void* buffer, const char* name) const noexcept {
167 if (std::string(name) == std::string("node" + std::to_string(id_) + "-data")) {
168 data_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
169 }
170 }
171
176 void
177 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
178 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
179 buffers["node" + std::to_string(id_) + "-data"]));
180 }
181
184 std::string
185 form() const {
186 std::stringstream form_key;
187 form_key << "node" << id_;
188
189 std::string params("");
190 if (parameters_ == "") {
191 } else {
192 params = std::string(", \"parameters\": { " + parameters_ + " }");
193 }
194
195 if (std::is_arithmetic<PRIMITIVE>::value) {
196 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
197 type_to_name<PRIMITIVE>() + "\"" + params +
198 ", \"form_key\": \"" + form_key.str() + "\" }";
200 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
201 type_to_name<PRIMITIVE>() + "\"" + params +
202 ", \"form_key\": \"" + form_key.str() + "\" }";
203 } else {
204 throw std::runtime_error("type " +
205 std::string(typeid(PRIMITIVE).name()) +
206 "is not supported");
207 }
208 }
209
210 private:
213
215 std::string parameters_;
216
218 size_t id_;
219 };
220
235 template <typename PRIMITIVE, typename BUILDER>
237 public:
241 : offsets_(
243 offsets_.append(0);
244 size_t id = 0;
245 set_id(id);
246 }
247
254 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
255 offsets_.append(0);
256 size_t id = 0;
257 set_id(id);
258 }
259
261 BUILDER&
262 content() noexcept {
263 return content_;
264 }
265
267 BUILDER&
268 begin_list() noexcept {
269 return content_;
270 }
271
274 void
275 end_list() noexcept {
276 offsets_.append(content_.length());
277 }
278
280 const std::string&
281 parameters() const noexcept {
282 return parameters_;
283 }
284
286 void
287 set_parameters(std::string parameter) noexcept {
288 parameters_ = parameter;
289 }
290
292 void
293 set_id(size_t& id) noexcept {
294 id_ = id;
295 id++;
296 content_.set_id(id);
297 }
298
300 void
301 clear() noexcept {
302 offsets_.clear();
303 offsets_.append(0);
304 content_.clear();
305 }
306
308 size_t
309 length() const noexcept {
310 return offsets_.length() - 1;
311 }
312
314 bool
315 is_valid(std::string& error) const noexcept {
316 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
317 std::stringstream out;
318 out << "ListOffset node" << id_ << "has content length "
319 << content_.length() << "but last offset " << offsets_.last()
320 << "\n";
321 error.append(out.str());
322
323 return false;
324 } else {
325 return content_.is_valid(error);
326 }
327 }
328
331 void
332 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
333 noexcept {
334 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
335 offsets_.nbytes();
336 content_.buffer_nbytes(names_nbytes);
337 }
338
344 void
345 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
346 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
347 buffers["node" + std::to_string(id_) + "-offsets"]));
348 content_.to_buffers(buffers);
349 }
350
355 void
356 to_buffer(void* buffer, const char* name) const noexcept {
357 if (std::string(name) == std::string("node" + std::to_string(id_) + "-offsets")) {
358 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
359 }
360 content_.to_buffer(buffer, name);
361 }
362
367 void
368 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
369 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
370 buffers["node" + std::to_string(id_) + "-offsets"]));
371 content_.to_char_buffers(buffers);
372 }
373
376 std::string
377 form() const noexcept {
378 std::stringstream form_key;
379 form_key << "node" << id_;
380 std::string params("");
381 if (parameters_ == "") {
382 } else {
383 params = std::string(", \"parameters\": { " + parameters_ + " }");
384 }
385 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
387 "\", \"content\": " + content_.form() + params +
388 ", \"form_key\": \"" + form_key.str() + "\" }";
389 }
390
391 private:
396
398 BUILDER content_;
399
401 std::string parameters_;
402
404 size_t id_;
405 };
406
411 template<class PRIMITIVE>
412 class String : public ListOffset<PRIMITIVE, Numpy<uint8_t>> {
413 public:
414 String() : ListOffset<PRIMITIVE, Numpy<uint8_t>>() {
415 this->set_parameters(R"""("__array__": "string")""");
416 this->content().set_parameters(R"""("__array__": "char")""");
417 }
418
419 void append(const std::string& value) {
420 this->begin_list();
421 for (const auto& c: value) {
422 this->content().append(c);
423 }
424 this->end_list();
425 }
426 };
427
432 class Empty {
433 public:
436 size_t id = 0;
437 set_id(id);
438 }
439
440 void
441 set_id(size_t& /* id */) noexcept {}
442
443 void
444 clear() noexcept {}
445
447 size_t
448 length() const noexcept {
449 return 0;
450 }
451
453 bool
454 is_valid(std::string& /* error */) const noexcept {
455 return true;
456 }
457
458 void
459 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
460 noexcept {}
461
462 void
463 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
464
465 void
466 to_buffer(void* /* buffer */, const char* /* name */) const noexcept {}
467
472 void
473 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
474
477 std::string
478 form() const noexcept {
479 return "{ \"class\": \"EmptyArray\" }";
480 }
481 };
482
483
493 template <class MAP = std::map<std::size_t, std::string>,
494 typename... BUILDERS>
495 class Record {
496 public:
497 using RecordContents = typename std::tuple<BUILDERS...>;
498 using UserDefinedMap = MAP;
499
500 template <std::size_t INDEX>
501 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
502
505 size_t id = 0;
506 set_id(id);
507 map_fields(std::index_sequence_for<BUILDERS...>());
508 }
509
516 Record(UserDefinedMap user_defined_field_id_to_name_map)
517 : content_names_(user_defined_field_id_to_name_map) {
518 assert(content_names_.size() == fields_count_);
519 size_t id = 0;
520 set_id(id);
521 }
522
524 const std::vector<std::string>
525 fields() const noexcept {
526 if (content_names_.empty()) {
527 return fields_;
528 } else {
529 std::vector<std::string> result;
530 for (auto it : content_names_) {
531 result.emplace_back(it.second);
532 }
533 return result;
534 }
535 }
536
541 void
542 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
543 content_names_ = user_defined_field_id_to_name_map;
544 }
545
547 template <std::size_t INDEX>
548 typename RecordFieldType<INDEX>::Builder&
549 content() noexcept {
550 return std::get<INDEX>(contents).builder;
551 }
552
554 const std::string&
555 parameters() const noexcept {
556 return parameters_;
557 }
558
560 void
561 set_parameters(std::string parameter) noexcept {
562 parameters_ = parameter;
563 }
564
566 void set_id(size_t& id) noexcept {
567
568 id_ = id;
569 id++;
570
571 BuilderSetId bsi(id);
572 for (size_t i = 0; i < fields_count_; i++) {
573
574 visit_at(contents, i, bsi); // Here the functor will propagate `id`
575 }
576 }
577
583 public:
584 template <class CONTENT>
585 void operator()(CONTENT& content) const {
586 content.builder.clear();
587 }
588 };
589
590 void
591 clear() noexcept {
592 ClearBuilder clearBuilder; // instantiate the functor
593 for (size_t i = 0; i < fields_count_; i++) {
594 visit_at(contents, i, clearBuilder); // pass the functor instead of a lambda
595 }
596 }
597
598 size_t
599 length() const noexcept {
600 return (std::get<0>(contents).builder.length());
601 }
602
604 bool
605 is_valid(std::string& error) const noexcept {
606 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
607
608 int64_t length = -1;
609 std::vector<size_t> lengths = field_lengths(index_sequence);
610 for (size_t i = 0; i < lengths.size(); i++) {
611 if (length == -1) {
612 length = lengths[i];
613 }
614 else if (length != (int64_t)lengths[i]) {
615 std::stringstream out;
616 out << "Record node" << id_ << " has field \""
617 << fields().at(i) << "\" length " << lengths[i]
618 << " that differs from the first length " << length << "\n";
619 error.append(out.str());
620
621 return false;
622 }
623 }
624
625 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
626 return std::none_of(std::cbegin(valid_fields),
627 std::cend(valid_fields),
628 std::logical_not<bool>());
629 }
630
633 void
634 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
635 for (size_t i = 0; i < fields_count_; i++) {
636 visit_at(contents, i, [&names_nbytes](auto& content) {
637 content.builder.buffer_nbytes(names_nbytes);
638 });
639 }
640 }
641
647 void
648 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
649 for (size_t i = 0; i < fields_count_; i++) {
650 visit_at(contents, i, [&buffers](auto& content) {
651 content.builder.to_buffers(buffers);
652 });
653 }
654 }
655
658 void
659 to_buffer(void* buffer, const char* name) const noexcept {
660 for (size_t i = 0; i < fields_count_; i++) {
661 visit_at(contents, i, [buffer, name](auto& content) {
662 content.builder.to_buffer(buffer, name);
663 });
664 }
665 }
666
667
672 void
673 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
674 for (size_t i = 0; i < fields_count_; i++) {
675 visit_at(contents, i, [&buffers](auto& content) {
676 content.builder.to_char_buffers(buffers);
677 });
678 }
679 }
680
681
685 public:
686 // Modify the constructor to accept a std::map instead of a std::vector
687 ContentsFormFunctor(std::stringstream& out, const std::map<size_t, std::string>& content_names)
688 : out_(out), content_names_(content_names) {}
689
690 // Template operator() to handle the content
691 template <class CONTENT>
692 void operator()(CONTENT& content) const {
693 size_t index = content.index; // Assuming CONTENT has an index
694 auto it = content_names_.find(index); // Lookup content name in the map
695
696 if (it != content_names_.end()) {
697 out_ << "\"" << it->second << "\": ";
698 } else {
699 out_ << "\"" << index << "\": "; // Fallback to index if not found
700 }
701
702 out_ << content.builder.form();
703 }
704
705 private:
706 std::stringstream& out_;
707 const std::map<size_t, std::string>& content_names_; // Store the map by reference
708 };
709
710
711 std::string form() const noexcept {
712 std::stringstream form_key;
713 form_key << "node" << id_;
714
715 std::string params("");
716 if (!parameters_.empty()) {
717 params = "\"parameters\": { " + parameters_ + " }, ";
718 }
719
720 std::stringstream out;
721 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
722
723 for (size_t i = 0; i < fields_count_; i++) {
724 if (i != 0) {
725 out << ", ";
726 }
727 ContentsFormFunctor contentsFormFunctor(out, content_names_);
728 visit_at(contents, i, contentsFormFunctor);
729 }
730
731 out << " }, ";
732 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
733 return out.str();
734 }
735
738
739 private:
742 template <std::size_t... S>
743 void
744 map_fields(std::index_sequence<S...>) noexcept {
745 fields_ = std::vector<std::string>(
746 {std::string(std::get<S>(contents).index_as_field())...});
747 }
748
751 template <std::size_t... S>
752 std::vector<size_t>
753 field_lengths(std::index_sequence<S...>) const noexcept {
754 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
755 }
756
758 template <std::size_t... S>
759 std::vector<bool>
760 field_is_valid(std::index_sequence<S...>, std::string& error) const
761 noexcept {
762 return std::vector<bool>(
763 {std::get<S>(contents).builder.is_valid(error)...});
764 }
765
767 std::vector<std::string> fields_;
768
770 UserDefinedMap content_names_;
771
773 std::string parameters_;
774
776 size_t id_;
777
779 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
780 };
781
788 template <typename... BUILDERS>
789 class Tuple {
790 using TupleContents = typename std::tuple<BUILDERS...>;
791
792 template <std::size_t INDEX>
793 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
794
795 public:
798 size_t id = 0;
799 set_id(id);
800 }
801
803 template <std::size_t INDEX>
804 TupleContentType<INDEX>&
805 content() noexcept {
806 return std::get<INDEX>(contents);
807 }
808
810 const std::string&
811 parameters() const noexcept {
812 return parameters_;
813 }
814
816 void
817 set_parameters(std::string parameter) noexcept {
818 parameters_ = parameter;
819 }
820
822 void
823 set_id(size_t& id) noexcept {
824 id_ = id;
825 id++;
826 for (size_t i = 0; i < fields_count_; i++) {
827 visit_at(contents, i, [&id](auto& content) {
828 content.set_id(id);
829 });
830 }
831 }
832
833
837 void
838 clear() noexcept {
839 for (size_t i = 0; i < fields_count_; i++) {
840 visit_at(contents, i, [](auto& content) {
841 content.clear();
842 });
843 }
844 }
845
847 size_t
848 length() const noexcept {
849 return (std::get<0>(contents).length());
850 }
851
853 bool
854 is_valid(std::string& error) const noexcept {
855 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
856
857 int64_t length = -1;
858 std::vector<size_t> lengths = content_lengths(index_sequence);
859 for (size_t i = 0; i < lengths.size(); i++) {
860 if (length == -1) {
861 length = (int64_t)lengths[i];
862 }
863 else if (length != (int64_t)lengths[i]) {
864 std::stringstream out;
865 out << "Record node" << id_ << " has index \"" << i << "\" length "
866 << lengths[i] << " that differs from the first length "
867 << length << "\n";
868 error.append(out.str());
869
870 return false;
871 }
872 }
873
874 std::vector<bool> valid_fields =
875 content_is_valid(index_sequence, error);
876 return std::none_of(std::cbegin(valid_fields),
877 std::cend(valid_fields),
878 std::logical_not<bool>());
879 }
880
883 void
884 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
885 for (size_t i = 0; i < fields_count_; i++) {
886 visit_at(contents, i, [&names_nbytes](auto& content) {
887 content.buffer_nbytes(names_nbytes);
888 });
889 }
890 }
891
892
898 void
899 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
900 for (size_t i = 0; i < fields_count_; i++) {
901 visit_at(contents, i, [&buffers](auto& content) {
902 content.to_buffers(buffers);
903 });
904 }
905 }
906
907
911 void
912 to_buffer(void* buffer, const char* name) const noexcept {
913 for (size_t i = 0; i < fields_count_; i++) {
914 visit_at(contents, i, [buffer, name](auto& content) {
915 content.to_buffer(buffer, name);
916 });
917 }
918 }
919
920
925 void
926 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
927 for (size_t i = 0; i < fields_count_; i++) {
928 visit_at(contents, i, [&buffers](auto& content) {
929 content.to_char_buffers(buffers);
930 });
931 }
932 }
933
937 public:
938 ContentsFormFunctor(std::stringstream& out)
939 : out_(out) {}
940
941 // Template operator() to handle each content
942 template <class CONTENT>
943 void operator()(CONTENT& content) const {
944 out_ << content.form();
945 }
946
947 private:
948 std::stringstream& out_; // Reference to the output stringstream
949 };
950
951
952 std::string
953 form() const noexcept {
954 std::stringstream form_key;
955 form_key << "node" << id_;
956 std::string params("");
957 if (!parameters_.empty()) {
958 params = "\"parameters\": { " + parameters_ + " }, ";
959 }
960 std::stringstream out;
961 out << "{ \"class\": \"RecordArray\", \"contents\": [";
962 for (size_t i = 0; i < fields_count_; i++) {
963 if (i != 0) {
964 out << ", ";
965 }
966 ContentsFormFunctor contentsFormFunctor(out);
967 visit_at(contents, i, contentsFormFunctor);
968 }
969 out << "], ";
970 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
971 return out.str();
972 }
973
975 TupleContents contents;
976
977 private:
980 template <std::size_t... S>
981 std::vector<size_t>
982 content_lengths(std::index_sequence<S...>) const noexcept {
983 return std::vector<size_t>({std::get<S>(contents).length()...});
984 }
985
987 template <std::size_t... S>
988 std::vector<bool>
989 content_is_valid(std::index_sequence<S...>, std::string& error) const
990 noexcept {
991 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
992 }
993
995 std::string parameters_;
996
998 size_t id_;
999
1001 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
1002 };
1003
1017 template <unsigned SIZE, typename BUILDER>
1018 class Regular {
1019 public:
1021 Regular() : length_(0) {
1022 size_t id = 0;
1023 set_id(id);
1024 }
1025
1027 BUILDER&
1028 content() noexcept {
1029 return content_;
1030 }
1031
1034 BUILDER&
1035 begin_list() noexcept {
1036 return content_;
1037 }
1038
1040 void
1041 end_list() noexcept {
1042 length_++;
1043 }
1044
1046 const std::string&
1047 parameters() const noexcept {
1048 return parameters_;
1049 }
1050
1052 void
1053 set_parameters(std::string parameter) noexcept {
1054 parameters_ = parameter;
1055 }
1056
1058 void
1059 set_id(size_t& id) noexcept {
1060 id_ = id;
1061 id++;
1062 content_.set_id(id);
1063 }
1064
1066 void
1067 clear() noexcept {
1068 length_ = 0;
1069 content_.clear();
1070 }
1071
1073 size_t
1074 length() const noexcept {
1075 return length_;
1076 }
1077
1079 bool
1080 is_valid(std::string& error) const noexcept {
1081 if (content_.length() != length_ * size_) {
1082 std::stringstream out;
1083 out << "Regular node" << id_ << "has content length "
1084 << content_.length() << ", but length " << length_ << " and size "
1085 << size_ << "\n";
1086 error.append(out.str());
1087
1088 return false;
1089 } else {
1090 return content_.is_valid(error);
1091 }
1092 }
1093
1096 void
1097 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1098 noexcept {
1099 content_.buffer_nbytes(names_nbytes);
1100 }
1101
1107 void
1108 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1109 content_.to_buffers(buffers);
1110 }
1111
1115 void
1116 to_buffer(void* buffer, const char* name) const noexcept {
1117 content_.to_buffer(buffer, name);
1118 }
1119
1124 void
1125 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1126 content_.to_char_buffers(buffers);
1127 }
1128
1131 std::string
1132 form() const noexcept {
1133 std::stringstream form_key;
1134 form_key << "node" << id_;
1135 std::string params("");
1136 if (parameters_ == "") {
1137 } else {
1138 params = std::string(", \"parameters\": { " + parameters_ + " }");
1139 }
1140 return "{ \"class\": \"RegularArray\", \"content\": " +
1141 content_.form() + ", \"size\": " + std::to_string(size_) +
1142 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1143 }
1144
1145 private:
1147 BUILDER content_;
1148
1150 std::string parameters_;
1151
1153 size_t id_;
1154
1156 size_t length_;
1157
1159 size_t size_ = SIZE;
1160 };
1161
1162
1172 template <typename PRIMITIVE, typename BUILDER>
1173 class Indexed {
1174 public:
1178 : index_(
1180 max_index_(0) {
1181 size_t id = 0;
1182 set_id(id);
1183 }
1184
1191 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1192 max_index_(0) {
1193 size_t id = 0;
1194 set_id(id);
1195 }
1196
1198 BUILDER&
1199 content() noexcept {
1200 return content_;
1201 }
1202
1205 BUILDER&
1206 append_index() noexcept {
1207 return append_index(content_.length());
1208 }
1209
1212 BUILDER&
1213 append_index(size_t i) noexcept {
1214 index_.append(i);
1215 if (i > max_index_) {
1216 max_index_ = i;
1217 } else if (i < 0) {
1218 max_index_ = UINTMAX_MAX;
1219 }
1220 return content_;
1221 }
1222
1227 BUILDER&
1228 extend_index(size_t size) noexcept {
1229 size_t start = content_.length();
1230 size_t stop = start + size;
1231 if (stop - 1 > max_index_) {
1232 max_index_ = stop - 1;
1233 }
1234 for (size_t i = start; i < stop; i++) {
1235 index_.append(i);
1236 }
1237 return content_;
1238 }
1239
1241 const std::string&
1242 parameters() const noexcept {
1243 return parameters_;
1244 }
1245
1247 void
1248 set_parameters(std::string parameter) noexcept {
1249 parameters_ = parameter;
1250 }
1251
1253 void
1254 set_id(size_t& id) noexcept {
1255 id_ = id;
1256 id++;
1257 content_.set_id(id);
1258 }
1259
1262 void
1263 clear() noexcept {
1264 max_index_ = 0;
1265 index_.clear();
1266 content_.clear();
1267 }
1268
1270 size_t
1271 length() const noexcept {
1272 return index_.length();
1273 }
1274
1277 void
1278 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1279 noexcept {
1280 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1281 content_.buffer_nbytes(names_nbytes);
1282 }
1283
1285 bool
1286 is_valid(std::string& error) const noexcept {
1287
1288 if (max_index_ == UINTMAX_MAX) {
1289 std::stringstream out;
1290 out << "Indexed node" << id_ << " has a negative index\n";
1291 error.append(out.str());
1292 return false;
1293 } else if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1294 } else if (max_index_ >= content_.length()) {
1295 std::stringstream out;
1296 out << "Indexed node" << id_ << " has index " << max_index_
1297 << " but content has length "
1298 << content_.length() << "\n";
1299 error.append(out.str());
1300 return false;
1301 }
1302 return content_.is_valid(error);
1303 }
1304
1310 void
1311 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1312 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1313 buffers["node" + std::to_string(id_) + "-index"]));
1314 content_.to_buffers(buffers);
1315 }
1316
1321 void
1322 to_buffer(void* buffer, const char* name) const noexcept {
1323 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1324 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1325 }
1326 content_.to_buffer(buffer, name);
1327 }
1328
1333 void
1334 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1335 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1336 buffers["node" + std::to_string(id_) + "-index"]));
1337 content_.to_char_buffers(buffers);
1338 }
1339
1342 std::string
1343 form() const noexcept {
1344 std::stringstream form_key;
1345 form_key << "node" << id_;
1346 std::string params("");
1347 if (parameters_ == "") {
1348 } else {
1349 params = std::string(", \"parameters\": { " + parameters_ + " }");
1350 }
1351 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1353 "\", \"content\": " + content_.form() + params +
1354 ", \"form_key\": \"" + form_key.str() + "\" }";
1355 }
1356
1357 private:
1362
1364 BUILDER content_;
1365
1367 std::string parameters_;
1368
1370 size_t id_;
1371
1373 size_t max_index_;
1374 };
1375
1386 template <typename PRIMITIVE, typename BUILDER>
1388 public:
1392 : index_(
1394 max_index_(0) {
1395 size_t id = 0;
1396 set_id(id);
1397 }
1398
1405 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1406 max_index_(0) {
1407 size_t id = 0;
1408 set_id(id);
1409 }
1410
1412 BUILDER&
1413 content() noexcept {
1414 return content_;
1415 }
1416
1419 BUILDER&
1420 append_valid() noexcept {
1421 return append_valid(content_.length());
1422 }
1423
1426 BUILDER&
1427 append_valid(size_t i) noexcept {
1428 index_.append(i);
1429 if (i > max_index_) {
1430 max_index_ = i;
1431 }
1432 return content_;
1433 }
1434
1439 BUILDER&
1440 extend_valid(size_t size) noexcept {
1441 size_t start = content_.length();
1442 size_t stop = start + size;
1443 size_t last_valid = stop - 1;
1444 if (last_valid > max_index_) {
1445 max_index_ = last_valid;
1446 }
1447 for (size_t i = start; i < stop; i++) {
1448 index_.append(i);
1449 }
1450 return content_;
1451 }
1452
1454 void
1455 append_invalid() noexcept {
1456 index_.append(-1);
1457 }
1458
1462 void
1463 extend_invalid(size_t size) noexcept {
1464 for (size_t i = 0; i < size; i++) {
1465 index_.append(-1);
1466 }
1467 }
1468
1470 const std::string&
1471 parameters() const noexcept {
1472 return parameters_;
1473 }
1474
1476 void
1477 set_parameters(std::string parameter) noexcept {
1478 parameters_ = parameter;
1479 }
1480
1482 void
1483 set_id(size_t& id) noexcept {
1484 id_ = id;
1485 id++;
1486 content_.set_id(id);
1487 }
1488
1491 void
1492 clear() noexcept {
1493 index_.clear();
1494 content_.clear();
1495 }
1496
1498 size_t
1499 length() const noexcept {
1500 return index_.length();
1501 }
1502
1504 bool
1505 is_valid(std::string& error) const noexcept {
1506 if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1507 } else if (max_index_ >= content_.length()) {
1508 std::stringstream out;
1509 out << "IndexedOption node" << id_ << " has index " << max_index_
1510 << " but content has length "
1511 << content_.length() << "\n";
1512 error.append(out.str());
1513
1514 return false;
1515 }
1516 return content_.is_valid(error);
1517 }
1518
1521 void
1522 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1523 noexcept {
1524 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1525 content_.buffer_nbytes(names_nbytes);
1526 }
1527
1533 void
1534 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1535 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1536 buffers["node" + std::to_string(id_) + "-index"]));
1537 content_.to_buffers(buffers);
1538 }
1539
1544 void
1545 to_buffer(void* buffer, const char* name) const noexcept {
1546 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1547 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1548 }
1549 content_.to_buffer(buffer, name);
1550 }
1551
1556 void
1557 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1558 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1559 buffers["node" + std::to_string(id_) + "-index"]));
1560 content_.to_char_buffers(buffers);
1561 }
1562
1565 std::string
1566 form() const noexcept {
1567 std::stringstream form_key;
1568 form_key << "node" << id_;
1569 std::string params("");
1570 if (parameters_ == "") {
1571 } else {
1572 params = std::string(", \"parameters\": { " + parameters_ + " }");
1573 }
1574 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1576 "\", \"content\": " + content_.form() + params +
1577 ", \"form_key\": \"" + form_key.str() + "\" }";
1578 }
1579
1580 private:
1585
1587 BUILDER content_;
1588
1590 std::string parameters_;
1591
1593 size_t id_;
1594
1596 size_t max_index_;
1597 };
1598
1610 template <typename BUILDER>
1611 class Unmasked {
1612 public:
1615 size_t id = 0;
1616 set_id(id);
1617 }
1618
1620 BUILDER&
1621 content() noexcept {
1622 return content_;
1623 }
1624
1626 const std::string&
1627 parameters() const noexcept {
1628 return parameters_;
1629 }
1630
1632 void
1633 set_parameters(std::string parameter) noexcept {
1634 parameters_ = parameter;
1635 }
1636
1638 void
1639 set_id(size_t& id) noexcept {
1640 id_ = id;
1641 id++;
1642 content_.set_id(id);
1643 }
1644
1646 void
1647 clear() noexcept {
1648 content_.clear();
1649 }
1650
1652 size_t
1653 length() const noexcept {
1654 return content_.length();
1655 }
1656
1658 bool
1659 is_valid(std::string& error) const noexcept {
1660 return content_.is_valid(error);
1661 }
1662
1665 void
1666 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1667 noexcept {
1668 content_.buffer_nbytes(names_nbytes);
1669 }
1670
1676 void
1677 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1678 content_.to_buffers(buffers);
1679 }
1680
1684 void
1685 to_buffer(void* buffer, const char* name) const noexcept {
1686 content_.to_buffer(buffer, name);
1687 }
1688
1693 void
1694 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1695 content_.to_char_buffers(buffers);
1696 }
1697
1700 std::string
1701 form() const noexcept {
1702 std::stringstream form_key;
1703 form_key << "node" << id_;
1704 std::string params("");
1705 if (parameters_ == "") {
1706 } else {
1707 params = std::string(", \"parameters\": { " + parameters_ + " }");
1708 }
1709 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1710 content_.form() + params + ", \"form_key\": \"" +
1711 form_key.str() + "\" }";
1712 }
1713
1714 private:
1716 BUILDER content_;
1717
1719 std::string parameters_;
1720
1722 size_t id_;
1723 };
1724
1741 template <bool VALID_WHEN, typename BUILDER>
1743 public:
1748 size_t id = 0;
1749 set_id(id);
1750 }
1751
1758 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1759 size_t id = 0;
1760 set_id(id);
1761 }
1762
1764 BUILDER&
1765 content() noexcept {
1766 return content_;
1767 }
1768
1770 bool
1771 valid_when() const noexcept {
1772 return valid_when_;
1773 }
1774
1778 BUILDER&
1779 append_valid() noexcept {
1780 mask_.append(valid_when_);
1781 return content_;
1782 }
1783
1789 BUILDER&
1790 extend_valid(size_t size) noexcept {
1791 for (size_t i = 0; i < size; i++) {
1792 mask_.append(valid_when_);
1793 }
1794 return content_;
1795 }
1796
1800 BUILDER&
1801 append_invalid() noexcept {
1802 mask_.append(!valid_when_);
1803 return content_;
1804 }
1805
1811 BUILDER&
1812 extend_invalid(size_t size) noexcept {
1813 for (size_t i = 0; i < size; i++) {
1814 mask_.append(!valid_when_);
1815 }
1816 return content_;
1817 }
1818
1820 const std::string&
1821 parameters() const noexcept {
1822 return parameters_;
1823 }
1824
1826 void
1827 set_parameters(std::string parameter) noexcept {
1828 parameters_ = parameter;
1829 }
1830
1832 void
1833 set_id(size_t& id) noexcept {
1834 id_ = id;
1835 id++;
1836 content_.set_id(id);
1837 }
1838
1841 void
1842 clear() noexcept {
1843 mask_.clear();
1844 content_.clear();
1845 }
1846
1848 size_t
1849 length() const noexcept {
1850 return mask_.length();
1851 }
1852
1854 bool
1855 is_valid(std::string& error) const noexcept {
1856 if (content_.length() != mask_.length()) {
1857 std::stringstream out;
1858 out << "ByteMasked node" << id_ << "has content length "
1859 << content_.length() << "but mask length " << mask_.length()
1860 << "\n";
1861 error.append(out.str());
1862
1863 return false;
1864 } else {
1865 return content_.is_valid(error);
1866 }
1867 }
1868
1871 void
1872 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1873 noexcept {
1874 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1875 content_.buffer_nbytes(names_nbytes);
1876 }
1877
1883 void
1884 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1885 mask_.concatenate(reinterpret_cast<int8_t*>(
1886 buffers["node" + std::to_string(id_) + "-mask"]));
1887 content_.to_buffers(buffers);
1888 }
1889
1894 void
1895 to_buffer(void* buffer, const char* name) const noexcept {
1896 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
1897 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
1898 }
1899 content_.to_buffer(buffer, name);
1900 }
1901
1906 void
1907 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1908 mask_.concatenate(reinterpret_cast<int8_t*>(
1909 buffers["node" + std::to_string(id_) + "-mask"]));
1910 content_.to_char_buffers(buffers);
1911 }
1912
1915 std::string
1916 form() const noexcept {
1917 std::stringstream form_key, form_valid_when;
1918 form_key << "node" << id_;
1919 form_valid_when << std::boolalpha << valid_when_;
1920 std::string params("");
1921 if (parameters_ == "") {
1922 } else {
1923 params = std::string(", \"parameters\": { " + parameters_ + " }");
1924 }
1925 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1926 "\"content\": " +
1927 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1928 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1929 }
1930
1931 private:
1936
1938 BUILDER content_;
1939
1941 std::string parameters_;
1942
1944 size_t id_;
1945
1947 bool valid_when_ = VALID_WHEN;
1948 };
1949
1966 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1968 public:
1973 current_byte_(uint8_t(0)),
1974 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1975 current_index_(0) {
1976 size_t id = 0;
1977 set_id(id);
1978 if (lsb_order_) {
1979 for (size_t i = 0; i < 8; i++) {
1980 cast_[i] = 1 << i;
1981 }
1982 } else {
1983 for (size_t i = 0; i < 8; i++) {
1984 cast_[i] = 128 >> i;
1985 }
1986 }
1987 }
1988
1995 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
1996 current_byte_(uint8_t(0)),
1997 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1998 current_index_(0) {
1999 size_t id = 0;
2000 set_id(id);
2001 if (lsb_order_) {
2002 for (size_t i = 0; i < 8; i++) {
2003 cast_[i] = 1 << i;
2004 }
2005 } else {
2006 for (size_t i = 0; i < 8; i++) {
2007 cast_[i] = 128 >> i;
2008 }
2009 }
2010 }
2011
2013 BUILDER&
2014 content() noexcept {
2015 return content_;
2016 }
2017
2019 bool
2020 valid_when() const noexcept {
2021 return valid_when_;
2022 }
2023
2026 bool
2027 lsb_order() const noexcept {
2028 return lsb_order_;
2029 }
2030
2035 BUILDER&
2036 append_valid() noexcept {
2037 append_begin();
2038 current_byte_ |= cast_[current_index_];
2039 append_end();
2040 return content_;
2041 }
2042
2049 BUILDER&
2050 extend_valid(size_t size) noexcept {
2051 for (size_t i = 0; i < size; i++) {
2052 append_valid();
2053 }
2054 return content_;
2055 }
2056
2060 BUILDER&
2061 append_invalid() noexcept {
2062 append_begin();
2063 append_end();
2064 return content_;
2065 }
2066
2072 BUILDER&
2073 extend_invalid(size_t size) noexcept {
2074 for (size_t i = 0; i < size; i++) {
2076 }
2077 return content_;
2078 }
2079
2081 const std::string&
2082 parameters() const noexcept {
2083 return parameters_;
2084 }
2085
2087 void
2088 set_parameters(std::string parameter) noexcept {
2089 parameters_ = parameter;
2090 }
2091
2093 void
2094 set_id(size_t& id) noexcept {
2095 id_ = id;
2096 id++;
2097 content_.set_id(id);
2098 }
2099
2102 void
2103 clear() noexcept {
2104 mask_.clear();
2105 content_.clear();
2106 current_byte_ = 0;
2107 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2108 current_index_ = 0;
2109 }
2110
2112 size_t
2113 length() const noexcept {
2114 return mask_.length() > 0 ?
2115 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2116 }
2117
2119 bool
2120 is_valid(std::string& error) const noexcept {
2121 if (content_.length() != length()) {
2122 std::stringstream out;
2123 out << "BitMasked node" << id_ << "has content length "
2124 << content_.length() << "but bit mask length " << mask_.length()
2125 << "\n";
2126 error.append(out.str());
2127
2128 return false;
2129 } else {
2130 return content_.is_valid(error);
2131 }
2132 }
2133
2136 void
2137 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2138 noexcept {
2139 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2140 content_.buffer_nbytes(names_nbytes);
2141 }
2142
2148 void
2149 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2150 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2151 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2152 mask_.append(reinterpret_cast<uint8_t*>(
2153 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2154 content_.to_buffers(buffers);
2155 }
2156
2161 void
2162 to_buffer(void* buffer, const char* name) const noexcept {
2163 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2164 mask_.concatenate_from(reinterpret_cast<uint8_t*>(buffer), 0, 1);
2165 mask_.append(reinterpret_cast<uint8_t*>(buffer), mask_.length() - 1, 0, 1);
2166 }
2167 content_.to_buffer(buffer, name);
2168 }
2169
2174 void
2175 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2176 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2177 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2178 mask_.append(reinterpret_cast<uint8_t*>(
2179 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2180 content_.to_char_buffers(buffers);
2181 }
2182
2185 std::string
2186 form() const noexcept {
2187 std::stringstream form_key, form_valid_when, form_lsb_order;
2188 form_key << "node" << id_;
2189 form_valid_when << std::boolalpha << valid_when_;
2190 form_lsb_order << std::boolalpha << lsb_order_;
2191 std::string params("");
2192 if (parameters_ == "") {
2193 } else {
2194 params = std::string(", \"parameters\": { " + parameters_ + " }");
2195 }
2196 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2197 "\"content\": " +
2198 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2199 ", \"lsb_order\": " + form_lsb_order.str() + params +
2200 ", \"form_key\": \"" + form_key.str() + "\" }";
2201 }
2202
2203 private:
2207 void
2208 append_begin() {
2209 if (current_index_ == 8) {
2210 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2211 current_byte_ = uint8_t(0);
2212 current_index_ = 0;
2213 }
2214 }
2215
2221 void
2222 append_end() {
2223 current_index_ += 1;
2224 if (valid_when_) {
2225 current_byte_ref_ = current_byte_;
2226 } else {
2227 current_byte_ref_ = ~current_byte_;
2228 }
2229 }
2230
2234 GrowableBuffer<uint8_t> mask_;
2235
2237 BUILDER content_;
2238
2240 std::string parameters_;
2241
2243 size_t id_;
2244
2246 uint8_t current_byte_;
2247
2249 uint8_t& current_byte_ref_;
2250
2252 size_t current_index_;
2253
2255 uint8_t cast_[8];
2256
2258 bool valid_when_ = VALID_WHEN;
2259
2262 bool lsb_order_ = LSB_ORDER;
2263 };
2264
2280 template <typename TAGS, typename INDEX, typename... BUILDERS>
2281 class Union {
2282 public:
2283 using Contents = typename std::tuple<BUILDERS...>;
2284
2285 template <std::size_t I>
2286 using ContentType = std::tuple_element_t<I, Contents>;
2287
2293 size_t id = 0;
2294 set_id(id);
2295 }
2296
2303 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2304 index_(awkward::GrowableBuffer<INDEX>(options)) {
2305 size_t id = 0;
2306 set_id(id);
2307 }
2308
2309 template <std::size_t I>
2311 content() noexcept {
2312 return std::get<I>(contents_);
2313 }
2314
2317 template <std::size_t TAG>
2319 append_content() noexcept {
2320 auto& which_content = std::get<TAG>(contents_);
2321 INDEX next_index = which_content.length();
2322
2323 TAGS tag = (TAGS)TAG;
2324 tags_.append(tag);
2325 index_.append(next_index);
2326
2327 return which_content;
2328 }
2329
2331 const std::string&
2332 parameters() const noexcept {
2333 return parameters_;
2334 }
2335
2337 void
2338 set_parameters(std::string parameter) noexcept {
2339 parameters_ = parameter;
2340 }
2341
2343 void
2344 set_id(size_t& id) noexcept {
2345 id_ = id;
2346 id++;
2347 for (size_t i = 0; i < contents_count_; i++) {
2348 visit_at(contents_, i, [&id](auto& content) {
2349 content.set_id(id);
2350 });
2351 }
2352 }
2353
2354
2357 void
2358 clear() noexcept {
2359 tags_.clear();
2360 index_.clear();
2361
2362 for (size_t i = 0; i < contents_count_; i++) {
2363 visit_at(contents_, i, [](auto& content) {
2364 content.clear();
2365 });
2366 }
2367 }
2368
2369
2371 size_t
2372 length() const noexcept {
2373 return tags_.length();
2374 }
2375
2377 bool
2378 is_valid(std::string& error) const noexcept {
2379 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2380
2381 std::vector<size_t> lengths = content_lengths(index_sequence);
2382 std::unique_ptr<INDEX[]> index_ptr(new INDEX[index_.length()]);
2383 index_.concatenate(index_ptr.get());
2384 std::unique_ptr<TAGS[]> tags_ptr(new TAGS[tags_.length()]);
2385 tags_.concatenate(tags_ptr.get());
2386 for (size_t i = 0; i < index_.length(); i++) {
2387 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2388 std::stringstream out;
2389 out << "Union node" << id_ << " has index " << index_ptr.get()[i]
2390 << " at position " << i << " but content has length "
2391 << lengths[tags_ptr.get()[i]] << "\n";
2392 error.append(out.str());
2393
2394 return false;
2395 }
2396 }
2397
2398 std::vector<bool> valid_contents =
2399 content_is_valid(index_sequence, error);
2400 return std::none_of(std::cbegin(valid_contents),
2401 std::cend(valid_contents),
2402 std::logical_not<bool>());
2403 }
2404
2407 void
2408 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
2409 // Store the size of tags and index buffers
2410 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2411 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2412
2413 for (size_t i = 0; i < contents_count_; i++) {
2414 visit_at(contents_, i, [&names_nbytes](auto& content) {
2415 content.buffer_nbytes(names_nbytes);
2416 });
2417 }
2418 }
2419
2420
2426 void
2427 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2428 // Concatenate tags and index buffers
2429 tags_.concatenate(reinterpret_cast<TAGS*>(
2430 buffers["node" + std::to_string(id_) + "-tags"]));
2431 index_.concatenate(reinterpret_cast<INDEX*>(
2432 buffers["node" + std::to_string(id_) + "-index"]));
2433
2434 for (size_t i = 0; i < contents_count_; i++) {
2435 visit_at(contents_, i, [&buffers](auto& content) {
2436 content.to_buffers(buffers);
2437 });
2438 }
2439 }
2440
2441
2446 void
2447 to_buffer(void* buffer, const char* name) const noexcept {
2448 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2449 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2450 }
2451 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2452 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2453 }
2454
2455 for (size_t i = 0; i < contents_count_; i++) {
2456 visit_at(contents_, i, [buffer, name](auto& content) {
2457 content.to_buffer(buffer, name);
2458 });
2459 }
2460 }
2461
2462
2467 void
2468 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2469 // Concatenate tags and index buffers
2470 tags_.concatenate(reinterpret_cast<TAGS*>(
2471 buffers["node" + std::to_string(id_) + "-tags"]));
2472 index_.concatenate(reinterpret_cast<INDEX*>(
2473 buffers["node" + std::to_string(id_) + "-index"]));
2474
2475 for (size_t i = 0; i < contents_count_; i++) {
2476 visit_at(contents_, i, [&buffers](auto& content) {
2477 content.to_char_buffers(buffers);
2478 });
2479 }
2480 }
2481
2482
2486 public:
2487 ContentsFormFunctor(std::stringstream& out)
2488 : out_(out) {}
2489
2490 // Template operator() to handle each content
2491 template <class CONTENT>
2492 void operator()(CONTENT& content) const {
2493 out_ << content.form();
2494 }
2495
2496 private:
2497 std::stringstream& out_; // Reference to the output stringstream
2498 };
2499
2500
2501 std::string
2502 form() const noexcept {
2503 std::stringstream form_key;
2504 form_key << "node" << id_;
2505 std::string params("");
2506 if (!parameters_.empty()) {
2507 params = ", \"parameters\": { " + parameters_ + " }";
2508 }
2509 std::stringstream out;
2510 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2511 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2512 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2513 for (size_t i = 0; i < contents_count_; i++) {
2514 if (i != 0) {
2515 out << ", ";
2516 }
2517 ContentsFormFunctor contentsFormFunctor(out);
2518 visit_at(contents_, i, contentsFormFunctor);
2519 }
2520 out << "], ";
2521 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2522 return out.str();
2523 }
2524
2525
2526 private:
2529 template <std::size_t... S>
2530 std::vector<size_t>
2531 content_lengths(std::index_sequence<S...>) const {
2532 return std::vector<size_t>({std::get<S>(contents_).length()...});
2533 }
2534
2536 template <std::size_t... S>
2537 std::vector<bool>
2538 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2539 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2540 }
2541
2545 GrowableBuffer<TAGS> tags_;
2546
2550 GrowableBuffer<INDEX> index_;
2551
2553 Contents contents_;
2554
2556 std::string parameters_;
2557
2559 size_t id_;
2560
2562 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2563 };
2564
2565 } // namespace LayoutBuilder
2566} // namespace awkward
2567
2568#endif // AWKWARD_LAYOUTBUILDER_H_
#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS
Object of BuilderOptions which sets the values of the default options.
Definition LayoutBuilder.h:18
Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels)...
Definition GrowableBuffer.h:250
PRIMITIVE & append_and_get_ref(PRIMITIVE datum)
Like append, but the type signature returns the reference to PRIMITIVE.
Definition GrowableBuffer.h:500
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:2020
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2103
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2027
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2061
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:2050
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:2186
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2082
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2088
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2014
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2113
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:2175
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2094
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2120
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1994
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:2036
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:2137
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2073
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:2162
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1971
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:2149
Functor for setting the ids of all nodes in a layout tree.
Definition LayoutBuilder.h:27
BuilderSetId(size_t &id)
Definition LayoutBuilder.h:29
void operator()(CONTENT &content)
Definition LayoutBuilder.h:32
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1771
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1842
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1801
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1790
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:1916
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1821
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1746
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1827
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1765
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1757
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1849
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:1907
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1833
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1855
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1779
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:1872
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1812
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:1895
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:1884
void clear() noexcept
Definition LayoutBuilder.h:444
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:454
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:478
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:463
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:466
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:435
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:441
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:448
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:459
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:473
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:48
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:54
BUILDER Builder
Definition LayoutBuilder.h:50
const std::size_t index
Definition LayoutBuilder.h:59
Builder builder
Definition LayoutBuilder.h:61
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1492
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1463
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:1440
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:1566
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1471
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1477
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1404
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1413
BUILDER & append_valid(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1427
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1499
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:1557
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1483
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1505
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1391
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1420
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:1522
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1455
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:1545
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:1534
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1263
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:1343
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1190
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1242
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1177
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1206
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1248
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1199
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:1228
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1271
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:1334
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1254
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1286
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:1278
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:1322
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:1311
BUILDER & append_index(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1213
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:301
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:268
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:240
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:377
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:281
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:287
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:262
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:309
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:368
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:293
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:315
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:275
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:332
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:356
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:253
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:345
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:71
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:128
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:140
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:87
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:109
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:115
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:134
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:177
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:95
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
Definition LayoutBuilder.h:75
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:121
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:146
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:103
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:166
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:157
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:185
Clears the builder contents.
Definition LayoutBuilder.h:582
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:585
ContentsFormFunctor(std::stringstream &out, const std::map< size_t, std::string > &content_names)
Definition LayoutBuilder.h:687
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:692
void clear() noexcept
Definition LayoutBuilder.h:591
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:504
MAP UserDefinedMap
Definition LayoutBuilder.h:498
std::string form() const noexcept
Definition LayoutBuilder.h:711
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:549
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:501
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:516
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:555
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:497
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:561
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:599
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:673
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:566
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:605
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:634
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:542
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:659
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:525
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:648
RecordContents contents
Definition LayoutBuilder.h:737
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1067
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:1035
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:1132
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1047
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1053
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1028
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1074
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:1125
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1059
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1080
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:1041
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:1097
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:1116
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:1021
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:1108
void append(const std::string &value)
Definition LayoutBuilder.h:419
String()
Definition LayoutBuilder.h:414
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:943
ContentsFormFunctor(std::stringstream &out)
Definition LayoutBuilder.h:938
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:838
TupleContents contents
Definition LayoutBuilder.h:975
std::string form() const noexcept
Definition LayoutBuilder.h:953
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:797
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:811
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:817
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:848
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:926
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:805
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:823
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:854
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:884
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:912
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:899
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2492
ContentsFormFunctor(std::stringstream &out)
Definition LayoutBuilder.h:2487
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2358
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:2302
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2283
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2286
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:2319
std::string form() const noexcept
Definition LayoutBuilder.h:2502
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2332
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2338
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2372
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:2468
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2290
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2311
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2344
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2378
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:2408
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:2447
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:2427
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1647
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1614
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:1701
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1627
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1633
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1621
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1653
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:1694
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1639
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1659
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:1666
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:1685
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:1677
Definition LayoutBuilder.h:22
Definition ArrayBuilder.h:14
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:93
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:241
Options< int64_t, double > BuilderOptions
Definition BuilderOptions.h:56
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition utils.h:23
Definition utils.h:146