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#include <sstream>
16
19#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS awkward::BuilderOptions(1024, 1)
20
21namespace awkward {
22
23 namespace LayoutBuilder {
24
29 public:
30 BuilderSetId(size_t& id) : id_(id) {}
31
32 template <class CONTENT>
33 void operator()(CONTENT& content) {
34 content.builder.set_id(id_);
35 }
36
37 private:
38 size_t& id_;
39 };
40
48 template <std::size_t ENUM, typename BUILDER>
49 class Field {
50 public:
51 using Builder = BUILDER;
52
54 std::string
56 return std::to_string(index);
57 }
58
60 const std::size_t index = ENUM;
63 };
64
71 template <typename PRIMITIVE>
72 class Numpy {
73 public:
77 : data_(
79 size_t id = 0;
80 set_id(id);
81 }
82
89 : data_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
90 size_t id = 0;
91 set_id(id);
92 }
93
95 void
96 append(PRIMITIVE x) noexcept {
97 data_.append(x);
98 }
99
103 void
104 extend(PRIMITIVE* ptr, size_t size) noexcept {
105 data_.extend(ptr, size);
106 }
107
109 const std::string&
110 parameters() const noexcept {
111 return parameters_;
112 }
113
115 void
116 set_parameters(std::string parameter) noexcept {
117 parameters_ = parameter;
118 }
119
121 void
122 set_id(size_t& id) noexcept {
123 id_ = id;
124 id++;
125 }
126
128 void
129 clear() noexcept {
130 data_.clear();
131 }
132
134 size_t
135 length() const noexcept {
136 return data_.length();
137 }
138
140 bool
141 is_valid(std::string& /* error */) const noexcept {
142 return true;
143 }
144
146 void
147 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
148 noexcept {
149 names_nbytes["node" + std::to_string(id_) + "-data"] = data_.nbytes();
150 }
151
157 void
158 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
159 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
160 buffers["node" + std::to_string(id_) + "-data"]));
161 }
162
166 void
167 to_buffer(void* buffer, const char* name) const noexcept {
168 if (std::string(name) == std::string("node" + std::to_string(id_) + "-data")) {
169 data_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
170 }
171 }
172
177 void
178 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
179 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
180 buffers["node" + std::to_string(id_) + "-data"]));
181 }
182
185 std::string
186 form() const {
187 std::stringstream form_key;
188 form_key << "node" << id_;
189
190 std::string params("");
191 if (parameters_ == "") {
192 } else {
193 params = std::string(", \"parameters\": { " + parameters_ + " }");
194 }
195
196 if (std::is_arithmetic<PRIMITIVE>::value) {
197 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
198 type_to_name<PRIMITIVE>() + "\"" + params +
199 ", \"form_key\": \"" + form_key.str() + "\" }";
201 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
202 type_to_name<PRIMITIVE>() + "\"" + params +
203 ", \"form_key\": \"" + form_key.str() + "\" }";
204 } else {
205 throw std::runtime_error("type " +
206 std::string(typeid(PRIMITIVE).name()) +
207 "is not supported");
208 }
209 }
210
211 private:
214
216 std::string parameters_;
217
219 size_t id_;
220 };
221
236 template <typename PRIMITIVE, typename BUILDER>
238 public:
242 : offsets_(
244 offsets_.append(0);
245 size_t id = 0;
246 set_id(id);
247 }
248
255 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
256 offsets_.append(0);
257 size_t id = 0;
258 set_id(id);
259 }
260
262 BUILDER&
263 content() noexcept {
264 return content_;
265 }
266
268 BUILDER&
269 begin_list() noexcept {
270 return content_;
271 }
272
275 void
276 end_list() noexcept {
277 offsets_.append(content_.length());
278 }
279
281 const std::string&
282 parameters() const noexcept {
283 return parameters_;
284 }
285
287 void
288 set_parameters(std::string parameter) noexcept {
289 parameters_ = parameter;
290 }
291
293 void
294 set_id(size_t& id) noexcept {
295 id_ = id;
296 id++;
297 content_.set_id(id);
298 }
299
301 void
302 clear() noexcept {
303 offsets_.clear();
304 offsets_.append(0);
305 content_.clear();
306 }
307
309 size_t
310 length() const noexcept {
311 return offsets_.length() - 1;
312 }
313
315 bool
316 is_valid(std::string& error) const noexcept {
317 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
318 std::stringstream out;
319 out << "ListOffset node" << id_ << "has content length "
320 << content_.length() << "but last offset " << offsets_.last()
321 << "\n";
322 error.append(out.str());
323
324 return false;
325 } else {
326 return content_.is_valid(error);
327 }
328 }
329
332 void
333 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
334 noexcept {
335 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
336 offsets_.nbytes();
337 content_.buffer_nbytes(names_nbytes);
338 }
339
345 void
346 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
347 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
348 buffers["node" + std::to_string(id_) + "-offsets"]));
349 content_.to_buffers(buffers);
350 }
351
356 void
357 to_buffer(void* buffer, const char* name) const noexcept {
358 if (std::string(name) == std::string("node" + std::to_string(id_) + "-offsets")) {
359 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
360 }
361 content_.to_buffer(buffer, name);
362 }
363
368 void
369 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
370 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
371 buffers["node" + std::to_string(id_) + "-offsets"]));
372 content_.to_char_buffers(buffers);
373 }
374
377 std::string
378 form() const noexcept {
379 std::stringstream form_key;
380 form_key << "node" << id_;
381 std::string params("");
382 if (parameters_ == "") {
383 } else {
384 params = std::string(", \"parameters\": { " + parameters_ + " }");
385 }
386 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
388 "\", \"content\": " + content_.form() + params +
389 ", \"form_key\": \"" + form_key.str() + "\" }";
390 }
391
392 private:
397
399 BUILDER content_;
400
402 std::string parameters_;
403
405 size_t id_;
406 };
407
412 template<class PRIMITIVE>
413 class String : public ListOffset<PRIMITIVE, Numpy<uint8_t>> {
414 public:
415 String() : ListOffset<PRIMITIVE, Numpy<uint8_t>>() {
416 this->set_parameters(R"""("__array__": "string")""");
417 this->content().set_parameters(R"""("__array__": "char")""");
418 }
419
420 void append(const std::string& value) {
421 this->begin_list();
422 for (const auto& c: value) {
423 this->content().append(c);
424 }
425 this->end_list();
426 }
427 };
428
433 class Empty {
434 public:
437 size_t id = 0;
438 set_id(id);
439 }
440
441 void
442 set_id(size_t& /* id */) noexcept {}
443
444 void
445 clear() noexcept {}
446
448 size_t
449 length() const noexcept {
450 return 0;
451 }
452
454 bool
455 is_valid(std::string& /* error */) const noexcept {
456 return true;
457 }
458
459 void
460 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
461 noexcept {}
462
463 void
464 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
465
466 void
467 to_buffer(void* /* buffer */, const char* /* name */) const noexcept {}
468
473 void
474 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
475
478 std::string
479 form() const noexcept {
480 return "{ \"class\": \"EmptyArray\" }";
481 }
482 };
483
484
494 template <class MAP = std::map<std::size_t, std::string>,
495 typename... BUILDERS>
496 class Record {
497 public:
498 using RecordContents = typename std::tuple<BUILDERS...>;
499 using UserDefinedMap = MAP;
500
501 template <std::size_t INDEX>
502 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
503
506 size_t id = 0;
507 set_id(id);
508 map_fields(std::index_sequence_for<BUILDERS...>());
509 }
510
517 Record(UserDefinedMap user_defined_field_id_to_name_map)
518 : content_names_(user_defined_field_id_to_name_map) {
519 assert(content_names_.size() == fields_count_);
520 size_t id = 0;
521 set_id(id);
522 }
523
525 const std::vector<std::string>
526 fields() const noexcept {
527 if (content_names_.empty()) {
528 return fields_;
529 } else {
530 std::vector<std::string> result;
531 for (auto it : content_names_) {
532 result.emplace_back(it.second);
533 }
534 return result;
535 }
536 }
537
542 void
543 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
544 content_names_ = user_defined_field_id_to_name_map;
545 }
546
548 template <std::size_t INDEX>
549 typename RecordFieldType<INDEX>::Builder&
550 content() noexcept {
551 return std::get<INDEX>(contents).builder;
552 }
553
555 const std::string&
556 parameters() const noexcept {
557 return parameters_;
558 }
559
561 void
562 set_parameters(std::string parameter) noexcept {
563 parameters_ = parameter;
564 }
565
567 void set_id(size_t& id) noexcept {
568
569 id_ = id;
570 id++;
571
572 BuilderSetId bsi(id);
573 for (size_t i = 0; i < fields_count_; i++) {
574
575 visit_at(contents, i, bsi); // Here the functor will propagate `id`
576 }
577 }
578
584 public:
585 template <class CONTENT>
586 void operator()(CONTENT& content) const {
587 content.builder.clear();
588 }
589 };
590
591 void
592 clear() noexcept {
593 ClearBuilder clearBuilder; // instantiate the functor
594 for (size_t i = 0; i < fields_count_; i++) {
595 visit_at(contents, i, clearBuilder); // pass the functor instead of a lambda
596 }
597 }
598
599 size_t
600 length() const noexcept {
601 return (std::get<0>(contents).builder.length());
602 }
603
605 bool
606 is_valid(std::string& error) const noexcept {
607 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
608
609 int64_t length = -1;
610 std::vector<size_t> lengths = field_lengths(index_sequence);
611 for (size_t i = 0; i < lengths.size(); i++) {
612 if (length == -1) {
613 length = lengths[i];
614 }
615 else if (length != (int64_t)lengths[i]) {
616 std::stringstream out;
617 out << "Record node" << id_ << " has field \""
618 << fields().at(i) << "\" length " << lengths[i]
619 << " that differs from the first length " << length << "\n";
620 error.append(out.str());
621
622 return false;
623 }
624 }
625
626 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
627 return std::none_of(std::cbegin(valid_fields),
628 std::cend(valid_fields),
629 std::logical_not<bool>());
630 }
631
634 void
635 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
636 for (size_t i = 0; i < fields_count_; i++) {
637 visit_at(contents, i, [&names_nbytes](auto& content) {
638 content.builder.buffer_nbytes(names_nbytes);
639 });
640 }
641 }
642
648 void
649 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
650 for (size_t i = 0; i < fields_count_; i++) {
651 visit_at(contents, i, [&buffers](auto& content) {
652 content.builder.to_buffers(buffers);
653 });
654 }
655 }
656
659 void
660 to_buffer(void* buffer, const char* name) const noexcept {
661 for (size_t i = 0; i < fields_count_; i++) {
662 visit_at(contents, i, [buffer, name](auto& content) {
663 content.builder.to_buffer(buffer, name);
664 });
665 }
666 }
667
668
673 void
674 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
675 for (size_t i = 0; i < fields_count_; i++) {
676 visit_at(contents, i, [&buffers](auto& content) {
677 content.builder.to_char_buffers(buffers);
678 });
679 }
680 }
681
682
686 public:
687 // Constructor accepts any map type compatible with MAP
688 ContentsFormFunctor(std::stringstream& out, const UserDefinedMap& content_names)
689 : out_(out), content_names_(content_names) {}
690
691 // Template operator() to handle the content
692 template <class CONTENT>
693 void operator()(CONTENT& content) const {
694 size_t index = content.index; // Assuming CONTENT has an index
695 auto it = content_names_.find(index); // Lookup content name in the map
696
697 if (it != content_names_.end()) {
698 out_ << "\"" << it->second << "\": ";
699 } else {
700 out_ << "\"" << index << "\": "; // Fallback to index if not found
701 }
702
703 out_ << content.builder.form();
704 }
705
706 private:
707 std::stringstream& out_;
708 const UserDefinedMap& content_names_; // Store the map by reference
709 };
710
711
712 std::string form() const noexcept {
713 std::stringstream form_key;
714 form_key << "node" << id_;
715
716 std::string params("");
717 if (!parameters_.empty()) {
718 params = "\"parameters\": { " + parameters_ + " }, ";
719 }
720
721 std::stringstream out;
722 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
723
724 for (size_t i = 0; i < fields_count_; i++) {
725 if (i != 0) {
726 out << ", ";
727 }
728 ContentsFormFunctor contentsFormFunctor(out, content_names_);
729 visit_at(contents, i, contentsFormFunctor);
730 }
731
732 out << " }, ";
733 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
734 return out.str();
735 }
736
739
740 private:
743 template <std::size_t... S>
744 void
745 map_fields(std::index_sequence<S...>) noexcept {
746 fields_ = std::vector<std::string>(
747 {std::string(std::get<S>(contents).index_as_field())...});
748 }
749
752 template <std::size_t... S>
753 std::vector<size_t>
754 field_lengths(std::index_sequence<S...>) const noexcept {
755 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
756 }
757
759 template <std::size_t... S>
760 std::vector<bool>
761 field_is_valid(std::index_sequence<S...>, std::string& error) const
762 noexcept {
763 return std::vector<bool>(
764 {std::get<S>(contents).builder.is_valid(error)...});
765 }
766
768 std::vector<std::string> fields_;
769
771 UserDefinedMap content_names_;
772
774 std::string parameters_;
775
777 size_t id_;
778
780 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
781 };
782
789 template <typename... BUILDERS>
790 class Tuple {
791 using TupleContents = typename std::tuple<BUILDERS...>;
792
793 template <std::size_t INDEX>
794 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
795
796 public:
799 size_t id = 0;
800 set_id(id);
801 }
802
804 template <std::size_t INDEX>
805 TupleContentType<INDEX>&
806 content() noexcept {
807 return std::get<INDEX>(contents);
808 }
809
811 const std::string&
812 parameters() const noexcept {
813 return parameters_;
814 }
815
817 void
818 set_parameters(std::string parameter) noexcept {
819 parameters_ = parameter;
820 }
821
823 void
824 set_id(size_t& id) noexcept {
825 id_ = id;
826 id++;
827 for (size_t i = 0; i < fields_count_; i++) {
828 visit_at(contents, i, [&id](auto& content) {
829 content.set_id(id);
830 });
831 }
832 }
833
834
838 void
839 clear() noexcept {
840 for (size_t i = 0; i < fields_count_; i++) {
841 visit_at(contents, i, [](auto& content) {
842 content.clear();
843 });
844 }
845 }
846
848 size_t
849 length() const noexcept {
850 return (std::get<0>(contents).length());
851 }
852
854 bool
855 is_valid(std::string& error) const noexcept {
856 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
857
858 int64_t length = -1;
859 std::vector<size_t> lengths = content_lengths(index_sequence);
860 for (size_t i = 0; i < lengths.size(); i++) {
861 if (length == -1) {
862 length = (int64_t)lengths[i];
863 }
864 else if (length != (int64_t)lengths[i]) {
865 std::stringstream out;
866 out << "Record node" << id_ << " has index \"" << i << "\" length "
867 << lengths[i] << " that differs from the first length "
868 << length << "\n";
869 error.append(out.str());
870
871 return false;
872 }
873 }
874
875 std::vector<bool> valid_fields =
876 content_is_valid(index_sequence, error);
877 return std::none_of(std::cbegin(valid_fields),
878 std::cend(valid_fields),
879 std::logical_not<bool>());
880 }
881
884 void
885 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
886 for (size_t i = 0; i < fields_count_; i++) {
887 visit_at(contents, i, [&names_nbytes](auto& content) {
888 content.buffer_nbytes(names_nbytes);
889 });
890 }
891 }
892
893
899 void
900 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
901 for (size_t i = 0; i < fields_count_; i++) {
902 visit_at(contents, i, [&buffers](auto& content) {
903 content.to_buffers(buffers);
904 });
905 }
906 }
907
908
912 void
913 to_buffer(void* buffer, const char* name) const noexcept {
914 for (size_t i = 0; i < fields_count_; i++) {
915 visit_at(contents, i, [buffer, name](auto& content) {
916 content.to_buffer(buffer, name);
917 });
918 }
919 }
920
921
926 void
927 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
928 for (size_t i = 0; i < fields_count_; i++) {
929 visit_at(contents, i, [&buffers](auto& content) {
930 content.to_char_buffers(buffers);
931 });
932 }
933 }
934
938 public:
939 ContentsFormFunctor(std::stringstream& out)
940 : out_(out) {}
941
942 // Template operator() to handle each content
943 template <class CONTENT>
944 void operator()(CONTENT& content) const {
945 out_ << content.form();
946 }
947
948 private:
949 std::stringstream& out_; // Reference to the output stringstream
950 };
951
952
953 std::string
954 form() const noexcept {
955 std::stringstream form_key;
956 form_key << "node" << id_;
957 std::string params("");
958 if (!parameters_.empty()) {
959 params = "\"parameters\": { " + parameters_ + " }, ";
960 }
961 std::stringstream out;
962 out << "{ \"class\": \"RecordArray\", \"contents\": [";
963 for (size_t i = 0; i < fields_count_; i++) {
964 if (i != 0) {
965 out << ", ";
966 }
967 ContentsFormFunctor contentsFormFunctor(out);
968 visit_at(contents, i, contentsFormFunctor);
969 }
970 out << "], ";
971 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
972 return out.str();
973 }
974
976 TupleContents contents;
977
978 private:
981 template <std::size_t... S>
982 std::vector<size_t>
983 content_lengths(std::index_sequence<S...>) const noexcept {
984 return std::vector<size_t>({std::get<S>(contents).length()...});
985 }
986
988 template <std::size_t... S>
989 std::vector<bool>
990 content_is_valid(std::index_sequence<S...>, std::string& error) const
991 noexcept {
992 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
993 }
994
996 std::string parameters_;
997
999 size_t id_;
1000
1002 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
1003 };
1004
1018 template <unsigned SIZE, typename BUILDER>
1019 class Regular {
1020 public:
1022 Regular() : length_(0) {
1023 size_t id = 0;
1024 set_id(id);
1025 }
1026
1028 BUILDER&
1029 content() noexcept {
1030 return content_;
1031 }
1032
1035 BUILDER&
1036 begin_list() noexcept {
1037 return content_;
1038 }
1039
1041 void
1042 end_list() noexcept {
1043 length_++;
1044 }
1045
1047 const std::string&
1048 parameters() const noexcept {
1049 return parameters_;
1050 }
1051
1053 void
1054 set_parameters(std::string parameter) noexcept {
1055 parameters_ = parameter;
1056 }
1057
1059 void
1060 set_id(size_t& id) noexcept {
1061 id_ = id;
1062 id++;
1063 content_.set_id(id);
1064 }
1065
1067 void
1068 clear() noexcept {
1069 length_ = 0;
1070 content_.clear();
1071 }
1072
1074 size_t
1075 length() const noexcept {
1076 return length_;
1077 }
1078
1080 bool
1081 is_valid(std::string& error) const noexcept {
1082 if (content_.length() != length_ * size_) {
1083 std::stringstream out;
1084 out << "Regular node" << id_ << "has content length "
1085 << content_.length() << ", but length " << length_ << " and size "
1086 << size_ << "\n";
1087 error.append(out.str());
1088
1089 return false;
1090 } else {
1091 return content_.is_valid(error);
1092 }
1093 }
1094
1097 void
1098 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1099 noexcept {
1100 content_.buffer_nbytes(names_nbytes);
1101 }
1102
1108 void
1109 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1110 content_.to_buffers(buffers);
1111 }
1112
1116 void
1117 to_buffer(void* buffer, const char* name) const noexcept {
1118 content_.to_buffer(buffer, name);
1119 }
1120
1125 void
1126 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1127 content_.to_char_buffers(buffers);
1128 }
1129
1132 std::string
1133 form() const noexcept {
1134 std::stringstream form_key;
1135 form_key << "node" << id_;
1136 std::string params("");
1137 if (parameters_ == "") {
1138 } else {
1139 params = std::string(", \"parameters\": { " + parameters_ + " }");
1140 }
1141 return "{ \"class\": \"RegularArray\", \"content\": " +
1142 content_.form() + ", \"size\": " + std::to_string(size_) +
1143 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1144 }
1145
1146 private:
1148 BUILDER content_;
1149
1151 std::string parameters_;
1152
1154 size_t id_;
1155
1157 size_t length_;
1158
1160 size_t size_ = SIZE;
1161 };
1162
1163
1173 template <typename PRIMITIVE, typename BUILDER>
1174 class Indexed {
1175 public:
1179 : index_(
1181 max_index_(0) {
1182 size_t id = 0;
1183 set_id(id);
1184 }
1185
1192 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1193 max_index_(0) {
1194 size_t id = 0;
1195 set_id(id);
1196 }
1197
1199 BUILDER&
1200 content() noexcept {
1201 return content_;
1202 }
1203
1206 BUILDER&
1207 append_index() noexcept {
1208 return append_index(content_.length());
1209 }
1210
1213 BUILDER&
1214 append_index(size_t i) noexcept {
1215 index_.append(i);
1216 if (i > max_index_) {
1217 max_index_ = i;
1218 } else if (i < 0) {
1219 max_index_ = UINTMAX_MAX;
1220 }
1221 return content_;
1222 }
1223
1228 BUILDER&
1229 extend_index(size_t size) noexcept {
1230 size_t start = content_.length();
1231 size_t stop = start + size;
1232 if (stop - 1 > max_index_) {
1233 max_index_ = stop - 1;
1234 }
1235 for (size_t i = start; i < stop; i++) {
1236 index_.append(i);
1237 }
1238 return content_;
1239 }
1240
1242 const std::string&
1243 parameters() const noexcept {
1244 return parameters_;
1245 }
1246
1248 void
1249 set_parameters(std::string parameter) noexcept {
1250 parameters_ = parameter;
1251 }
1252
1254 void
1255 set_id(size_t& id) noexcept {
1256 id_ = id;
1257 id++;
1258 content_.set_id(id);
1259 }
1260
1263 void
1264 clear() noexcept {
1265 max_index_ = 0;
1266 index_.clear();
1267 content_.clear();
1268 }
1269
1271 size_t
1272 length() const noexcept {
1273 return index_.length();
1274 }
1275
1278 void
1279 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1280 noexcept {
1281 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1282 content_.buffer_nbytes(names_nbytes);
1283 }
1284
1286 bool
1287 is_valid(std::string& error) const noexcept {
1288
1289 if (max_index_ == UINTMAX_MAX) {
1290 std::stringstream out;
1291 out << "Indexed node" << id_ << " has a negative index\n";
1292 error.append(out.str());
1293 return false;
1294 } else if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1295 } else if (max_index_ >= content_.length()) {
1296 std::stringstream out;
1297 out << "Indexed node" << id_ << " has index " << max_index_
1298 << " but content has length "
1299 << content_.length() << "\n";
1300 error.append(out.str());
1301 return false;
1302 }
1303 return content_.is_valid(error);
1304 }
1305
1311 void
1312 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1313 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1314 buffers["node" + std::to_string(id_) + "-index"]));
1315 content_.to_buffers(buffers);
1316 }
1317
1322 void
1323 to_buffer(void* buffer, const char* name) const noexcept {
1324 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1325 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1326 }
1327 content_.to_buffer(buffer, name);
1328 }
1329
1334 void
1335 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1336 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1337 buffers["node" + std::to_string(id_) + "-index"]));
1338 content_.to_char_buffers(buffers);
1339 }
1340
1343 std::string
1344 form() const noexcept {
1345 std::stringstream form_key;
1346 form_key << "node" << id_;
1347 std::string params("");
1348 if (parameters_ == "") {
1349 } else {
1350 params = std::string(", \"parameters\": { " + parameters_ + " }");
1351 }
1352 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1354 "\", \"content\": " + content_.form() + params +
1355 ", \"form_key\": \"" + form_key.str() + "\" }";
1356 }
1357
1358 private:
1363
1365 BUILDER content_;
1366
1368 std::string parameters_;
1369
1371 size_t id_;
1372
1374 size_t max_index_;
1375 };
1376
1387 template <typename PRIMITIVE, typename BUILDER>
1389 public:
1393 : index_(
1395 max_index_(0) {
1396 size_t id = 0;
1397 set_id(id);
1398 }
1399
1406 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1407 max_index_(0) {
1408 size_t id = 0;
1409 set_id(id);
1410 }
1411
1413 BUILDER&
1414 content() noexcept {
1415 return content_;
1416 }
1417
1420 BUILDER&
1421 append_valid() noexcept {
1422 return append_valid(content_.length());
1423 }
1424
1427 BUILDER&
1428 append_valid(size_t i) noexcept {
1429 index_.append(i);
1430 if (i > max_index_) {
1431 max_index_ = i;
1432 }
1433 return content_;
1434 }
1435
1440 BUILDER&
1441 extend_valid(size_t size) noexcept {
1442 size_t start = content_.length();
1443 size_t stop = start + size;
1444 size_t last_valid = stop - 1;
1445 if (last_valid > max_index_) {
1446 max_index_ = last_valid;
1447 }
1448 for (size_t i = start; i < stop; i++) {
1449 index_.append(i);
1450 }
1451 return content_;
1452 }
1453
1455 void
1456 append_invalid() noexcept {
1457 index_.append(-1);
1458 }
1459
1463 void
1464 extend_invalid(size_t size) noexcept {
1465 for (size_t i = 0; i < size; i++) {
1466 index_.append(-1);
1467 }
1468 }
1469
1471 const std::string&
1472 parameters() const noexcept {
1473 return parameters_;
1474 }
1475
1477 void
1478 set_parameters(std::string parameter) noexcept {
1479 parameters_ = parameter;
1480 }
1481
1483 void
1484 set_id(size_t& id) noexcept {
1485 id_ = id;
1486 id++;
1487 content_.set_id(id);
1488 }
1489
1492 void
1493 clear() noexcept {
1494 index_.clear();
1495 content_.clear();
1496 }
1497
1499 size_t
1500 length() const noexcept {
1501 return index_.length();
1502 }
1503
1505 bool
1506 is_valid(std::string& error) const noexcept {
1507 if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1508 } else if (max_index_ >= content_.length()) {
1509 std::stringstream out;
1510 out << "IndexedOption node" << id_ << " has index " << max_index_
1511 << " but content has length "
1512 << content_.length() << "\n";
1513 error.append(out.str());
1514
1515 return false;
1516 }
1517 return content_.is_valid(error);
1518 }
1519
1522 void
1523 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1524 noexcept {
1525 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1526 content_.buffer_nbytes(names_nbytes);
1527 }
1528
1534 void
1535 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1536 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1537 buffers["node" + std::to_string(id_) + "-index"]));
1538 content_.to_buffers(buffers);
1539 }
1540
1545 void
1546 to_buffer(void* buffer, const char* name) const noexcept {
1547 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1548 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1549 }
1550 content_.to_buffer(buffer, name);
1551 }
1552
1557 void
1558 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1559 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1560 buffers["node" + std::to_string(id_) + "-index"]));
1561 content_.to_char_buffers(buffers);
1562 }
1563
1566 std::string
1567 form() const noexcept {
1568 std::stringstream form_key;
1569 form_key << "node" << id_;
1570 std::string params("");
1571 if (parameters_ == "") {
1572 } else {
1573 params = std::string(", \"parameters\": { " + parameters_ + " }");
1574 }
1575 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1577 "\", \"content\": " + content_.form() + params +
1578 ", \"form_key\": \"" + form_key.str() + "\" }";
1579 }
1580
1581 private:
1586
1588 BUILDER content_;
1589
1591 std::string parameters_;
1592
1594 size_t id_;
1595
1597 size_t max_index_;
1598 };
1599
1611 template <typename BUILDER>
1612 class Unmasked {
1613 public:
1616 size_t id = 0;
1617 set_id(id);
1618 }
1619
1621 BUILDER&
1622 content() noexcept {
1623 return content_;
1624 }
1625
1627 const std::string&
1628 parameters() const noexcept {
1629 return parameters_;
1630 }
1631
1633 void
1634 set_parameters(std::string parameter) noexcept {
1635 parameters_ = parameter;
1636 }
1637
1639 void
1640 set_id(size_t& id) noexcept {
1641 id_ = id;
1642 id++;
1643 content_.set_id(id);
1644 }
1645
1647 void
1648 clear() noexcept {
1649 content_.clear();
1650 }
1651
1653 size_t
1654 length() const noexcept {
1655 return content_.length();
1656 }
1657
1659 bool
1660 is_valid(std::string& error) const noexcept {
1661 return content_.is_valid(error);
1662 }
1663
1666 void
1667 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1668 noexcept {
1669 content_.buffer_nbytes(names_nbytes);
1670 }
1671
1677 void
1678 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1679 content_.to_buffers(buffers);
1680 }
1681
1685 void
1686 to_buffer(void* buffer, const char* name) const noexcept {
1687 content_.to_buffer(buffer, name);
1688 }
1689
1694 void
1695 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1696 content_.to_char_buffers(buffers);
1697 }
1698
1701 std::string
1702 form() const noexcept {
1703 std::stringstream form_key;
1704 form_key << "node" << id_;
1705 std::string params("");
1706 if (parameters_ == "") {
1707 } else {
1708 params = std::string(", \"parameters\": { " + parameters_ + " }");
1709 }
1710 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1711 content_.form() + params + ", \"form_key\": \"" +
1712 form_key.str() + "\" }";
1713 }
1714
1715 private:
1717 BUILDER content_;
1718
1720 std::string parameters_;
1721
1723 size_t id_;
1724 };
1725
1742 template <bool VALID_WHEN, typename BUILDER>
1744 public:
1749 size_t id = 0;
1750 set_id(id);
1751 }
1752
1759 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1760 size_t id = 0;
1761 set_id(id);
1762 }
1763
1765 BUILDER&
1766 content() noexcept {
1767 return content_;
1768 }
1769
1771 bool
1772 valid_when() const noexcept {
1773 return valid_when_;
1774 }
1775
1779 BUILDER&
1780 append_valid() noexcept {
1781 mask_.append(valid_when_);
1782 return content_;
1783 }
1784
1790 BUILDER&
1791 extend_valid(size_t size) noexcept {
1792 for (size_t i = 0; i < size; i++) {
1793 mask_.append(valid_when_);
1794 }
1795 return content_;
1796 }
1797
1801 BUILDER&
1802 append_invalid() noexcept {
1803 mask_.append(!valid_when_);
1804 return content_;
1805 }
1806
1812 BUILDER&
1813 extend_invalid(size_t size) noexcept {
1814 for (size_t i = 0; i < size; i++) {
1815 mask_.append(!valid_when_);
1816 }
1817 return content_;
1818 }
1819
1821 const std::string&
1822 parameters() const noexcept {
1823 return parameters_;
1824 }
1825
1827 void
1828 set_parameters(std::string parameter) noexcept {
1829 parameters_ = parameter;
1830 }
1831
1833 void
1834 set_id(size_t& id) noexcept {
1835 id_ = id;
1836 id++;
1837 content_.set_id(id);
1838 }
1839
1842 void
1843 clear() noexcept {
1844 mask_.clear();
1845 content_.clear();
1846 }
1847
1849 size_t
1850 length() const noexcept {
1851 return mask_.length();
1852 }
1853
1855 bool
1856 is_valid(std::string& error) const noexcept {
1857 if (content_.length() != mask_.length()) {
1858 std::stringstream out;
1859 out << "ByteMasked node" << id_ << "has content length "
1860 << content_.length() << "but mask length " << mask_.length()
1861 << "\n";
1862 error.append(out.str());
1863
1864 return false;
1865 } else {
1866 return content_.is_valid(error);
1867 }
1868 }
1869
1872 void
1873 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1874 noexcept {
1875 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1876 content_.buffer_nbytes(names_nbytes);
1877 }
1878
1884 void
1885 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1886 mask_.concatenate(reinterpret_cast<int8_t*>(
1887 buffers["node" + std::to_string(id_) + "-mask"]));
1888 content_.to_buffers(buffers);
1889 }
1890
1895 void
1896 to_buffer(void* buffer, const char* name) const noexcept {
1897 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
1898 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
1899 }
1900 content_.to_buffer(buffer, name);
1901 }
1902
1907 void
1908 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1909 mask_.concatenate(reinterpret_cast<int8_t*>(
1910 buffers["node" + std::to_string(id_) + "-mask"]));
1911 content_.to_char_buffers(buffers);
1912 }
1913
1916 std::string
1917 form() const noexcept {
1918 std::stringstream form_key, form_valid_when;
1919 form_key << "node" << id_;
1920 form_valid_when << std::boolalpha << valid_when_;
1921 std::string params("");
1922 if (parameters_ == "") {
1923 } else {
1924 params = std::string(", \"parameters\": { " + parameters_ + " }");
1925 }
1926 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1927 "\"content\": " +
1928 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1929 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1930 }
1931
1932 private:
1937
1939 BUILDER content_;
1940
1942 std::string parameters_;
1943
1945 size_t id_;
1946
1948 bool valid_when_ = VALID_WHEN;
1949 };
1950
1967 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1969 public:
1974 current_byte_(uint8_t(0)),
1975 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1976 current_index_(0) {
1977 size_t id = 0;
1978 set_id(id);
1979 if (lsb_order_) {
1980 for (size_t i = 0; i < 8; i++) {
1981 cast_[i] = 1 << i;
1982 }
1983 } else {
1984 for (size_t i = 0; i < 8; i++) {
1985 cast_[i] = 128 >> i;
1986 }
1987 }
1988 }
1989
1996 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
1997 current_byte_(uint8_t(0)),
1998 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1999 current_index_(0) {
2000 size_t id = 0;
2001 set_id(id);
2002 if (lsb_order_) {
2003 for (size_t i = 0; i < 8; i++) {
2004 cast_[i] = 1 << i;
2005 }
2006 } else {
2007 for (size_t i = 0; i < 8; i++) {
2008 cast_[i] = 128 >> i;
2009 }
2010 }
2011 }
2012
2014 BUILDER&
2015 content() noexcept {
2016 return content_;
2017 }
2018
2020 bool
2021 valid_when() const noexcept {
2022 return valid_when_;
2023 }
2024
2027 bool
2028 lsb_order() const noexcept {
2029 return lsb_order_;
2030 }
2031
2036 BUILDER&
2037 append_valid() noexcept {
2038 append_begin();
2039 current_byte_ |= cast_[current_index_];
2040 append_end();
2041 return content_;
2042 }
2043
2050 BUILDER&
2051 extend_valid(size_t size) noexcept {
2052 for (size_t i = 0; i < size; i++) {
2053 append_valid();
2054 }
2055 return content_;
2056 }
2057
2061 BUILDER&
2062 append_invalid() noexcept {
2063 append_begin();
2064 append_end();
2065 return content_;
2066 }
2067
2073 BUILDER&
2074 extend_invalid(size_t size) noexcept {
2075 for (size_t i = 0; i < size; i++) {
2077 }
2078 return content_;
2079 }
2080
2082 const std::string&
2083 parameters() const noexcept {
2084 return parameters_;
2085 }
2086
2088 void
2089 set_parameters(std::string parameter) noexcept {
2090 parameters_ = parameter;
2091 }
2092
2094 void
2095 set_id(size_t& id) noexcept {
2096 id_ = id;
2097 id++;
2098 content_.set_id(id);
2099 }
2100
2103 void
2104 clear() noexcept {
2105 mask_.clear();
2106 content_.clear();
2107 current_byte_ = 0;
2108 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2109 current_index_ = 0;
2110 }
2111
2113 size_t
2114 length() const noexcept {
2115 return mask_.length() > 0 ?
2116 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2117 }
2118
2120 bool
2121 is_valid(std::string& error) const noexcept {
2122 if (content_.length() != length()) {
2123 std::stringstream out;
2124 out << "BitMasked node" << id_ << "has content length "
2125 << content_.length() << "but bit mask length " << mask_.length()
2126 << "\n";
2127 error.append(out.str());
2128
2129 return false;
2130 } else {
2131 return content_.is_valid(error);
2132 }
2133 }
2134
2137 void
2138 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2139 noexcept {
2140 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2141 content_.buffer_nbytes(names_nbytes);
2142 }
2143
2149 void
2150 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2151 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2152 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2153 mask_.append(reinterpret_cast<uint8_t*>(
2154 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2155 content_.to_buffers(buffers);
2156 }
2157
2162 void
2163 to_buffer(void* buffer, const char* name) const noexcept {
2164 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2165 mask_.concatenate_from(reinterpret_cast<uint8_t*>(buffer), 0, 1);
2166 mask_.append(reinterpret_cast<uint8_t*>(buffer), mask_.length() - 1, 0, 1);
2167 }
2168 content_.to_buffer(buffer, name);
2169 }
2170
2175 void
2176 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2177 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2178 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2179 mask_.append(reinterpret_cast<uint8_t*>(
2180 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2181 content_.to_char_buffers(buffers);
2182 }
2183
2186 std::string
2187 form() const noexcept {
2188 std::stringstream form_key, form_valid_when, form_lsb_order;
2189 form_key << "node" << id_;
2190 form_valid_when << std::boolalpha << valid_when_;
2191 form_lsb_order << std::boolalpha << lsb_order_;
2192 std::string params("");
2193 if (parameters_ == "") {
2194 } else {
2195 params = std::string(", \"parameters\": { " + parameters_ + " }");
2196 }
2197 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2198 "\"content\": " +
2199 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2200 ", \"lsb_order\": " + form_lsb_order.str() + params +
2201 ", \"form_key\": \"" + form_key.str() + "\" }";
2202 }
2203
2204 private:
2208 void
2209 append_begin() {
2210 if (current_index_ == 8) {
2211 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2212 current_byte_ = uint8_t(0);
2213 current_index_ = 0;
2214 }
2215 }
2216
2222 void
2223 append_end() {
2224 current_index_ += 1;
2225 if (valid_when_) {
2226 current_byte_ref_ = current_byte_;
2227 } else {
2228 current_byte_ref_ = ~current_byte_;
2229 }
2230 }
2231
2235 GrowableBuffer<uint8_t> mask_;
2236
2238 BUILDER content_;
2239
2241 std::string parameters_;
2242
2244 size_t id_;
2245
2247 uint8_t current_byte_;
2248
2250 uint8_t& current_byte_ref_;
2251
2253 size_t current_index_;
2254
2256 uint8_t cast_[8];
2257
2259 bool valid_when_ = VALID_WHEN;
2260
2263 bool lsb_order_ = LSB_ORDER;
2264 };
2265
2281 template <typename TAGS, typename INDEX, typename... BUILDERS>
2282 class Union {
2283 public:
2284 using Contents = typename std::tuple<BUILDERS...>;
2285
2286 template <std::size_t I>
2287 using ContentType = std::tuple_element_t<I, Contents>;
2288
2294 size_t id = 0;
2295 set_id(id);
2296 }
2297
2304 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2305 index_(awkward::GrowableBuffer<INDEX>(options)) {
2306 size_t id = 0;
2307 set_id(id);
2308 }
2309
2310 template <std::size_t I>
2312 content() noexcept {
2313 return std::get<I>(contents_);
2314 }
2315
2318 template <std::size_t TAG>
2320 append_content() noexcept {
2321 auto& which_content = std::get<TAG>(contents_);
2322 INDEX next_index = which_content.length();
2323
2324 TAGS tag = (TAGS)TAG;
2325 tags_.append(tag);
2326 index_.append(next_index);
2327
2328 return which_content;
2329 }
2330
2332 const std::string&
2333 parameters() const noexcept {
2334 return parameters_;
2335 }
2336
2338 void
2339 set_parameters(std::string parameter) noexcept {
2340 parameters_ = parameter;
2341 }
2342
2344 void
2345 set_id(size_t& id) noexcept {
2346 id_ = id;
2347 id++;
2348 for (size_t i = 0; i < contents_count_; i++) {
2349 visit_at(contents_, i, [&id](auto& content) {
2350 content.set_id(id);
2351 });
2352 }
2353 }
2354
2355
2358 void
2359 clear() noexcept {
2360 tags_.clear();
2361 index_.clear();
2362
2363 for (size_t i = 0; i < contents_count_; i++) {
2364 visit_at(contents_, i, [](auto& content) {
2365 content.clear();
2366 });
2367 }
2368 }
2369
2370
2372 size_t
2373 length() const noexcept {
2374 return tags_.length();
2375 }
2376
2378 bool
2379 is_valid(std::string& error) const noexcept {
2380 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2381
2382 std::vector<size_t> lengths = content_lengths(index_sequence);
2383 std::unique_ptr<INDEX[]> index_ptr(new INDEX[index_.length()]);
2384 index_.concatenate(index_ptr.get());
2385 std::unique_ptr<TAGS[]> tags_ptr(new TAGS[tags_.length()]);
2386 tags_.concatenate(tags_ptr.get());
2387 for (size_t i = 0; i < index_.length(); i++) {
2388 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2389 std::stringstream out;
2390 out << "Union node" << id_ << " has index " << index_ptr.get()[i]
2391 << " at position " << i << " but content has length "
2392 << lengths[tags_ptr.get()[i]] << "\n";
2393 error.append(out.str());
2394
2395 return false;
2396 }
2397 }
2398
2399 std::vector<bool> valid_contents =
2400 content_is_valid(index_sequence, error);
2401 return std::none_of(std::cbegin(valid_contents),
2402 std::cend(valid_contents),
2403 std::logical_not<bool>());
2404 }
2405
2408 void
2409 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
2410 // Store the size of tags and index buffers
2411 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2412 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2413
2414 for (size_t i = 0; i < contents_count_; i++) {
2415 visit_at(contents_, i, [&names_nbytes](auto& content) {
2416 content.buffer_nbytes(names_nbytes);
2417 });
2418 }
2419 }
2420
2421
2427 void
2428 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2429 // Concatenate tags and index buffers
2430 tags_.concatenate(reinterpret_cast<TAGS*>(
2431 buffers["node" + std::to_string(id_) + "-tags"]));
2432 index_.concatenate(reinterpret_cast<INDEX*>(
2433 buffers["node" + std::to_string(id_) + "-index"]));
2434
2435 for (size_t i = 0; i < contents_count_; i++) {
2436 visit_at(contents_, i, [&buffers](auto& content) {
2437 content.to_buffers(buffers);
2438 });
2439 }
2440 }
2441
2442
2447 void
2448 to_buffer(void* buffer, const char* name) const noexcept {
2449 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2450 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2451 }
2452 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2453 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2454 }
2455
2456 for (size_t i = 0; i < contents_count_; i++) {
2457 visit_at(contents_, i, [buffer, name](auto& content) {
2458 content.to_buffer(buffer, name);
2459 });
2460 }
2461 }
2462
2463
2468 void
2469 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2470 // Concatenate tags and index buffers
2471 tags_.concatenate(reinterpret_cast<TAGS*>(
2472 buffers["node" + std::to_string(id_) + "-tags"]));
2473 index_.concatenate(reinterpret_cast<INDEX*>(
2474 buffers["node" + std::to_string(id_) + "-index"]));
2475
2476 for (size_t i = 0; i < contents_count_; i++) {
2477 visit_at(contents_, i, [&buffers](auto& content) {
2478 content.to_char_buffers(buffers);
2479 });
2480 }
2481 }
2482
2483
2487 public:
2488 ContentsFormFunctor(std::stringstream& out)
2489 : out_(out) {}
2490
2491 // Template operator() to handle each content
2492 template <class CONTENT>
2493 void operator()(CONTENT& content) const {
2494 out_ << content.form();
2495 }
2496
2497 private:
2498 std::stringstream& out_; // Reference to the output stringstream
2499 };
2500
2501
2502 std::string
2503 form() const noexcept {
2504 std::stringstream form_key;
2505 form_key << "node" << id_;
2506 std::string params("");
2507 if (!parameters_.empty()) {
2508 params = "\"parameters\": { " + parameters_ + " }, ";
2509 }
2510 std::stringstream out;
2511 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2512 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2513 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2514 for (size_t i = 0; i < contents_count_; i++) {
2515 if (i != 0) {
2516 out << ", ";
2517 }
2518 ContentsFormFunctor contentsFormFunctor(out);
2519 visit_at(contents_, i, contentsFormFunctor);
2520 }
2521 out << "], ";
2522 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2523 return out.str();
2524 }
2525
2526
2527 private:
2530 template <std::size_t... S>
2531 std::vector<size_t>
2532 content_lengths(std::index_sequence<S...>) const {
2533 return std::vector<size_t>({std::get<S>(contents_).length()...});
2534 }
2535
2537 template <std::size_t... S>
2538 std::vector<bool>
2539 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2540 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2541 }
2542
2546 GrowableBuffer<TAGS> tags_;
2547
2551 GrowableBuffer<INDEX> index_;
2552
2554 Contents contents_;
2555
2557 std::string parameters_;
2558
2560 size_t id_;
2561
2563 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2564 };
2565
2566 } // namespace LayoutBuilder
2567} // namespace awkward
2568
2569#endif // AWKWARD_LAYOUTBUILDER_H_
#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS
Object of BuilderOptions which sets the values of the default options.
Definition LayoutBuilder.h:19
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:2021
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2104
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2028
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2062
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:2051
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:2187
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2083
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2089
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2015
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2114
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:2176
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2095
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2121
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1995
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:2037
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:2138
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2074
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:2163
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1972
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:2150
Functor for setting the ids of all nodes in a layout tree.
Definition LayoutBuilder.h:28
BuilderSetId(size_t &id)
Definition LayoutBuilder.h:30
void operator()(CONTENT &content)
Definition LayoutBuilder.h:33
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1772
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1843
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1802
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1791
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:1917
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1822
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1747
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1828
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1766
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1758
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1850
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:1908
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1834
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1856
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1780
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:1873
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1813
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:1896
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:1885
void clear() noexcept
Definition LayoutBuilder.h:445
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:455
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:479
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:464
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:467
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:436
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:442
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:449
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:460
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:474
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:49
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:55
BUILDER Builder
Definition LayoutBuilder.h:51
const std::size_t index
Definition LayoutBuilder.h:60
Builder builder
Definition LayoutBuilder.h:62
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1493
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1464
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:1441
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:1567
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1472
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1478
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1405
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1414
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:1428
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1500
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:1558
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1484
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1506
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1392
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1421
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:1523
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1456
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:1546
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:1535
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1264
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:1344
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1191
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1243
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1178
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1207
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1249
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1200
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:1229
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1272
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:1335
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1255
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1287
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:1279
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:1323
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:1312
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:1214
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:302
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:269
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:241
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:378
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:282
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:288
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:263
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:310
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:369
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:294
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:316
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:276
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:333
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:357
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:254
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:346
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:72
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:129
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:141
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:88
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:110
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:116
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:135
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:178
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:96
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
Definition LayoutBuilder.h:76
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:122
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:147
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:104
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:167
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:158
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:186
Clears the builder contents.
Definition LayoutBuilder.h:583
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:586
ContentsFormFunctor(std::stringstream &out, const UserDefinedMap &content_names)
Definition LayoutBuilder.h:688
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:693
void clear() noexcept
Definition LayoutBuilder.h:592
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:505
MAP UserDefinedMap
Definition LayoutBuilder.h:499
std::string form() const noexcept
Definition LayoutBuilder.h:712
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:550
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:502
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:517
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:556
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:498
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:562
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:600
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:674
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:567
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:606
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:635
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:543
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:660
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:526
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:649
RecordContents contents
Definition LayoutBuilder.h:738
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1068
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:1036
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:1133
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1048
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1054
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1029
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1075
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:1126
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1060
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1081
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:1042
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:1098
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:1117
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:1022
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:1109
void append(const std::string &value)
Definition LayoutBuilder.h:420
String()
Definition LayoutBuilder.h:415
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:944
ContentsFormFunctor(std::stringstream &out)
Definition LayoutBuilder.h:939
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:839
TupleContents contents
Definition LayoutBuilder.h:976
std::string form() const noexcept
Definition LayoutBuilder.h:954
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:798
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:812
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:818
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:849
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:927
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:806
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:824
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:855
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:885
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:913
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:900
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2493
ContentsFormFunctor(std::stringstream &out)
Definition LayoutBuilder.h:2488
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2359
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:2303
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2284
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2287
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:2320
std::string form() const noexcept
Definition LayoutBuilder.h:2503
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2333
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2339
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2373
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:2469
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2291
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2312
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2345
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2379
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:2409
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:2448
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:2428
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1648
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1615
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:1702
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1628
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1634
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1622
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1654
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:1695
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1640
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1660
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:1667
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:1686
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:1678
Definition LayoutBuilder.h:23
Definition ArrayBuilder.h:14
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:94
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:242
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:24
Definition utils.h:147