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 }
1219 return content_;
1220 }
1221
1226 BUILDER&
1227 extend_index(size_t size) noexcept {
1228 if (size == 0) {
1229 return content_;
1230 }
1231 size_t start = content_.length();
1232 size_t stop = start + size;
1233 if (stop - 1 > max_index_) {
1234 max_index_ = stop - 1;
1235 }
1236 for (size_t i = start; i < stop; i++) {
1237 index_.append(i);
1238 }
1239 return content_;
1240 }
1241
1243 const std::string&
1244 parameters() const noexcept {
1245 return parameters_;
1246 }
1247
1249 void
1250 set_parameters(std::string parameter) noexcept {
1251 parameters_ = parameter;
1252 }
1253
1255 void
1256 set_id(size_t& id) noexcept {
1257 id_ = id;
1258 id++;
1259 content_.set_id(id);
1260 }
1261
1264 void
1265 clear() noexcept {
1266 max_index_ = 0;
1267 index_.clear();
1268 content_.clear();
1269 }
1270
1272 size_t
1273 length() const noexcept {
1274 return index_.length();
1275 }
1276
1279 void
1280 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1281 noexcept {
1282 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1283 content_.buffer_nbytes(names_nbytes);
1284 }
1285
1287 bool
1288 is_valid(std::string& error) const noexcept {
1289
1290 if (max_index_ == UINTMAX_MAX) {
1291 std::stringstream out;
1292 out << "Indexed node" << id_ << " has a negative index\n";
1293 error.append(out.str());
1294 return false;
1295 } else if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1296 } else if (max_index_ >= content_.length()) {
1297 std::stringstream out;
1298 out << "Indexed node" << id_ << " has index " << max_index_
1299 << " but content has length "
1300 << content_.length() << "\n";
1301 error.append(out.str());
1302 return false;
1303 }
1304 return content_.is_valid(error);
1305 }
1306
1312 void
1313 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1314 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1315 buffers["node" + std::to_string(id_) + "-index"]));
1316 content_.to_buffers(buffers);
1317 }
1318
1323 void
1324 to_buffer(void* buffer, const char* name) const noexcept {
1325 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1326 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1327 }
1328 content_.to_buffer(buffer, name);
1329 }
1330
1335 void
1336 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1337 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1338 buffers["node" + std::to_string(id_) + "-index"]));
1339 content_.to_char_buffers(buffers);
1340 }
1341
1344 std::string
1345 form() const noexcept {
1346 std::stringstream form_key;
1347 form_key << "node" << id_;
1348 std::string params("");
1349 if (parameters_ == "") {
1350 } else {
1351 params = std::string(", \"parameters\": { " + parameters_ + " }");
1352 }
1353 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1355 "\", \"content\": " + content_.form() + params +
1356 ", \"form_key\": \"" + form_key.str() + "\" }";
1357 }
1358
1359 private:
1364
1366 BUILDER content_;
1367
1369 std::string parameters_;
1370
1372 size_t id_;
1373
1375 size_t max_index_;
1376 };
1377
1388 template <typename PRIMITIVE, typename BUILDER>
1390 public:
1394 : index_(
1396 max_index_(0) {
1397 size_t id = 0;
1398 set_id(id);
1399 }
1400
1407 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1408 max_index_(0) {
1409 size_t id = 0;
1410 set_id(id);
1411 }
1412
1414 BUILDER&
1415 content() noexcept {
1416 return content_;
1417 }
1418
1421 BUILDER&
1422 append_valid() noexcept {
1423 return append_valid(content_.length());
1424 }
1425
1428 BUILDER&
1429 append_valid(size_t i) noexcept {
1430 index_.append(i);
1431 if (i > max_index_) {
1432 max_index_ = i;
1433 }
1434 return content_;
1435 }
1436
1441 BUILDER&
1442 extend_valid(size_t size) noexcept {
1443 if (size == 0) {
1444 return content_;
1445 }
1446 size_t start = content_.length();
1447 size_t stop = start + size;
1448 size_t last_valid = stop - 1;
1449 if (last_valid > max_index_) {
1450 max_index_ = last_valid;
1451 }
1452 for (size_t i = start; i < stop; i++) {
1453 index_.append(i);
1454 }
1455 return content_;
1456 }
1457
1459 void
1460 append_invalid() noexcept {
1461 index_.append(-1);
1462 }
1463
1467 void
1468 extend_invalid(size_t size) noexcept {
1469 for (size_t i = 0; i < size; i++) {
1470 index_.append(-1);
1471 }
1472 }
1473
1475 const std::string&
1476 parameters() const noexcept {
1477 return parameters_;
1478 }
1479
1481 void
1482 set_parameters(std::string parameter) noexcept {
1483 parameters_ = parameter;
1484 }
1485
1487 void
1488 set_id(size_t& id) noexcept {
1489 id_ = id;
1490 id++;
1491 content_.set_id(id);
1492 }
1493
1496 void
1497 clear() noexcept {
1498 index_.clear();
1499 content_.clear();
1500 }
1501
1503 size_t
1504 length() const noexcept {
1505 return index_.length();
1506 }
1507
1509 bool
1510 is_valid(std::string& error) const noexcept {
1511 if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1512 } else if (max_index_ >= content_.length()) {
1513 std::stringstream out;
1514 out << "IndexedOption node" << id_ << " has index " << max_index_
1515 << " but content has length "
1516 << content_.length() << "\n";
1517 error.append(out.str());
1518
1519 return false;
1520 }
1521 return content_.is_valid(error);
1522 }
1523
1526 void
1527 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1528 noexcept {
1529 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1530 content_.buffer_nbytes(names_nbytes);
1531 }
1532
1538 void
1539 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1540 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1541 buffers["node" + std::to_string(id_) + "-index"]));
1542 content_.to_buffers(buffers);
1543 }
1544
1549 void
1550 to_buffer(void* buffer, const char* name) const noexcept {
1551 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1552 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1553 }
1554 content_.to_buffer(buffer, name);
1555 }
1556
1561 void
1562 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1563 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1564 buffers["node" + std::to_string(id_) + "-index"]));
1565 content_.to_char_buffers(buffers);
1566 }
1567
1570 std::string
1571 form() const noexcept {
1572 std::stringstream form_key;
1573 form_key << "node" << id_;
1574 std::string params("");
1575 if (parameters_ == "") {
1576 } else {
1577 params = std::string(", \"parameters\": { " + parameters_ + " }");
1578 }
1579 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1581 "\", \"content\": " + content_.form() + params +
1582 ", \"form_key\": \"" + form_key.str() + "\" }";
1583 }
1584
1585 private:
1590
1592 BUILDER content_;
1593
1595 std::string parameters_;
1596
1598 size_t id_;
1599
1601 size_t max_index_;
1602 };
1603
1615 template <typename BUILDER>
1616 class Unmasked {
1617 public:
1620 size_t id = 0;
1621 set_id(id);
1622 }
1623
1625 BUILDER&
1626 content() noexcept {
1627 return content_;
1628 }
1629
1631 const std::string&
1632 parameters() const noexcept {
1633 return parameters_;
1634 }
1635
1637 void
1638 set_parameters(std::string parameter) noexcept {
1639 parameters_ = parameter;
1640 }
1641
1643 void
1644 set_id(size_t& id) noexcept {
1645 id_ = id;
1646 id++;
1647 content_.set_id(id);
1648 }
1649
1651 void
1652 clear() noexcept {
1653 content_.clear();
1654 }
1655
1657 size_t
1658 length() const noexcept {
1659 return content_.length();
1660 }
1661
1663 bool
1664 is_valid(std::string& error) const noexcept {
1665 return content_.is_valid(error);
1666 }
1667
1670 void
1671 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1672 noexcept {
1673 content_.buffer_nbytes(names_nbytes);
1674 }
1675
1681 void
1682 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1683 content_.to_buffers(buffers);
1684 }
1685
1689 void
1690 to_buffer(void* buffer, const char* name) const noexcept {
1691 content_.to_buffer(buffer, name);
1692 }
1693
1698 void
1699 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1700 content_.to_char_buffers(buffers);
1701 }
1702
1705 std::string
1706 form() const noexcept {
1707 std::stringstream form_key;
1708 form_key << "node" << id_;
1709 std::string params("");
1710 if (parameters_ == "") {
1711 } else {
1712 params = std::string(", \"parameters\": { " + parameters_ + " }");
1713 }
1714 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1715 content_.form() + params + ", \"form_key\": \"" +
1716 form_key.str() + "\" }";
1717 }
1718
1719 private:
1721 BUILDER content_;
1722
1724 std::string parameters_;
1725
1727 size_t id_;
1728 };
1729
1746 template <bool VALID_WHEN, typename BUILDER>
1748 public:
1753 size_t id = 0;
1754 set_id(id);
1755 }
1756
1763 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1764 size_t id = 0;
1765 set_id(id);
1766 }
1767
1769 BUILDER&
1770 content() noexcept {
1771 return content_;
1772 }
1773
1775 bool
1776 valid_when() const noexcept {
1777 return valid_when_;
1778 }
1779
1783 BUILDER&
1784 append_valid() noexcept {
1785 mask_.append(valid_when_);
1786 return content_;
1787 }
1788
1794 BUILDER&
1795 extend_valid(size_t size) noexcept {
1796 for (size_t i = 0; i < size; i++) {
1797 mask_.append(valid_when_);
1798 }
1799 return content_;
1800 }
1801
1805 BUILDER&
1806 append_invalid() noexcept {
1807 mask_.append(!valid_when_);
1808 return content_;
1809 }
1810
1816 BUILDER&
1817 extend_invalid(size_t size) noexcept {
1818 for (size_t i = 0; i < size; i++) {
1819 mask_.append(!valid_when_);
1820 }
1821 return content_;
1822 }
1823
1825 const std::string&
1826 parameters() const noexcept {
1827 return parameters_;
1828 }
1829
1831 void
1832 set_parameters(std::string parameter) noexcept {
1833 parameters_ = parameter;
1834 }
1835
1837 void
1838 set_id(size_t& id) noexcept {
1839 id_ = id;
1840 id++;
1841 content_.set_id(id);
1842 }
1843
1846 void
1847 clear() noexcept {
1848 mask_.clear();
1849 content_.clear();
1850 }
1851
1853 size_t
1854 length() const noexcept {
1855 return mask_.length();
1856 }
1857
1859 bool
1860 is_valid(std::string& error) const noexcept {
1861 if (content_.length() != mask_.length()) {
1862 std::stringstream out;
1863 out << "ByteMasked node" << id_ << "has content length "
1864 << content_.length() << "but mask length " << mask_.length()
1865 << "\n";
1866 error.append(out.str());
1867
1868 return false;
1869 } else {
1870 return content_.is_valid(error);
1871 }
1872 }
1873
1876 void
1877 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1878 noexcept {
1879 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1880 content_.buffer_nbytes(names_nbytes);
1881 }
1882
1888 void
1889 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1890 mask_.concatenate(reinterpret_cast<int8_t*>(
1891 buffers["node" + std::to_string(id_) + "-mask"]));
1892 content_.to_buffers(buffers);
1893 }
1894
1899 void
1900 to_buffer(void* buffer, const char* name) const noexcept {
1901 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
1902 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
1903 }
1904 content_.to_buffer(buffer, name);
1905 }
1906
1911 void
1912 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1913 mask_.concatenate(reinterpret_cast<int8_t*>(
1914 buffers["node" + std::to_string(id_) + "-mask"]));
1915 content_.to_char_buffers(buffers);
1916 }
1917
1920 std::string
1921 form() const noexcept {
1922 std::stringstream form_key, form_valid_when;
1923 form_key << "node" << id_;
1924 form_valid_when << std::boolalpha << valid_when_;
1925 std::string params("");
1926 if (parameters_ == "") {
1927 } else {
1928 params = std::string(", \"parameters\": { " + parameters_ + " }");
1929 }
1930 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1931 "\"content\": " +
1932 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1933 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1934 }
1935
1936 private:
1941
1943 BUILDER content_;
1944
1946 std::string parameters_;
1947
1949 size_t id_;
1950
1952 bool valid_when_ = VALID_WHEN;
1953 };
1954
1971 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1973 public:
1978 current_byte_(uint8_t(0)),
1979 current_index_(0) {
1980 size_t id = 0;
1981 set_id(id);
1982 if (lsb_order_) {
1983 for (size_t i = 0; i < 8; i++) {
1984 cast_[i] = 1 << i;
1985 }
1986 } else {
1987 for (size_t i = 0; i < 8; i++) {
1988 cast_[i] = 128 >> i;
1989 }
1990 }
1991 }
1992
1999 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
2000 current_byte_(uint8_t(0)),
2001 current_index_(0) {
2002 size_t id = 0;
2003 set_id(id);
2004 if (lsb_order_) {
2005 for (size_t i = 0; i < 8; i++) {
2006 cast_[i] = 1 << i;
2007 }
2008 } else {
2009 for (size_t i = 0; i < 8; i++) {
2010 cast_[i] = 128 >> i;
2011 }
2012 }
2013 }
2014
2016 BUILDER&
2017 content() noexcept {
2018 return content_;
2019 }
2020
2022 bool
2023 valid_when() const noexcept {
2024 return valid_when_;
2025 }
2026
2029 bool
2030 lsb_order() const noexcept {
2031 return lsb_order_;
2032 }
2033
2038 BUILDER&
2039 append_valid() noexcept {
2040 append_begin();
2041 current_byte_ |= cast_[current_index_];
2042 append_end();
2043 return content_;
2044 }
2045
2052 BUILDER&
2053 extend_valid(size_t size) noexcept {
2054 for (size_t i = 0; i < size; i++) {
2055 append_valid();
2056 }
2057 return content_;
2058 }
2059
2063 BUILDER&
2064 append_invalid() noexcept {
2065 append_begin();
2066 append_end();
2067 return content_;
2068 }
2069
2075 BUILDER&
2076 extend_invalid(size_t size) noexcept {
2077 for (size_t i = 0; i < size; i++) {
2079 }
2080 return content_;
2081 }
2082
2084 const std::string&
2085 parameters() const noexcept {
2086 return parameters_;
2087 }
2088
2090 void
2091 set_parameters(std::string parameter) noexcept {
2092 parameters_ = parameter;
2093 }
2094
2096 void
2097 set_id(size_t& id) noexcept {
2098 id_ = id;
2099 id++;
2100 content_.set_id(id);
2101 }
2102
2105 void
2106 clear() noexcept {
2107 mask_.clear();
2108 content_.clear();
2109 current_byte_ = 0;
2110 current_index_ = 0;
2111 }
2112
2117 size_t
2118 length() const noexcept {
2119 return mask_.length() * 8 + current_index_;
2120 }
2121
2123 size_t
2124 mask_nbytes() const noexcept {
2125 return mask_.length() + (current_index_ > 0 ? 1 : 0);
2126 }
2127
2129 bool
2130 is_valid(std::string& error) const noexcept {
2131 if (content_.length() != length()) {
2132 std::stringstream out;
2133 out << "BitMasked node" << id_ << "has content length "
2134 << content_.length() << "but bit mask length " << mask_.length()
2135 << "\n";
2136 error.append(out.str());
2137
2138 return false;
2139 } else {
2140 return content_.is_valid(error);
2141 }
2142 }
2143
2146 void
2147 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2148 noexcept {
2149 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_nbytes();
2150 content_.buffer_nbytes(names_nbytes);
2151 }
2152
2158 void
2159 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2160 write_mask(reinterpret_cast<uint8_t*>(
2161 buffers["node" + std::to_string(id_) + "-mask"]));
2162 content_.to_buffers(buffers);
2163 }
2164
2169 void
2170 to_buffer(void* buffer, const char* name) const noexcept {
2171 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2172 write_mask(reinterpret_cast<uint8_t*>(buffer));
2173 }
2174 content_.to_buffer(buffer, name);
2175 }
2176
2181 void
2182 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2183 write_mask(reinterpret_cast<uint8_t*>(
2184 buffers["node" + std::to_string(id_) + "-mask"]));
2185 content_.to_char_buffers(buffers);
2186 }
2187
2190 std::string
2191 form() const noexcept {
2192 std::stringstream form_key, form_valid_when, form_lsb_order;
2193 form_key << "node" << id_;
2194 form_valid_when << std::boolalpha << valid_when_;
2195 form_lsb_order << std::boolalpha << lsb_order_;
2196 std::string params("");
2197 if (parameters_ == "") {
2198 } else {
2199 params = std::string(", \"parameters\": { " + parameters_ + " }");
2200 }
2201 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2202 "\"content\": " +
2203 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2204 ", \"lsb_order\": " + form_lsb_order.str() + params +
2205 ", \"form_key\": \"" + form_key.str() + "\" }";
2206 }
2207
2208 private:
2209 // Byte is committed in append_end once eight bits are written; nothing
2210 // to do at the start of an element.
2211 void
2212 append_begin() {
2213 }
2214
2220 void
2221 append_end() {
2222 current_index_ += 1;
2223 if (current_index_ == 8) {
2224 mask_.append(valid_when_ ? current_byte_ : (uint8_t)(~current_byte_));
2225 current_byte_ = uint8_t(0);
2226 current_index_ = 0;
2227 }
2228 }
2229
2234 void
2235 write_mask(uint8_t* buffer) const noexcept {
2236 if (buffer == nullptr) {
2237 return;
2238 }
2239 if (mask_.length() > 0) {
2240 mask_.concatenate(buffer);
2241 }
2242 if (current_index_ > 0) {
2243 buffer[mask_.length()] =
2244 valid_when_ ? current_byte_ : (uint8_t)(~current_byte_);
2245 }
2246 }
2247
2251 GrowableBuffer<uint8_t> mask_;
2252
2254 BUILDER content_;
2255
2257 std::string parameters_;
2258
2260 size_t id_;
2261
2263 uint8_t current_byte_;
2264
2266 size_t current_index_;
2267
2269 uint8_t cast_[8];
2270
2272 bool valid_when_ = VALID_WHEN;
2273
2276 bool lsb_order_ = LSB_ORDER;
2277 };
2278
2294 template <typename TAGS, typename INDEX, typename... BUILDERS>
2295 class Union {
2296 public:
2297 using Contents = typename std::tuple<BUILDERS...>;
2298
2299 template <std::size_t I>
2300 using ContentType = std::tuple_element_t<I, Contents>;
2301
2307 size_t id = 0;
2308 set_id(id);
2309 }
2310
2317 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2318 index_(awkward::GrowableBuffer<INDEX>(options)) {
2319 size_t id = 0;
2320 set_id(id);
2321 }
2322
2323 template <std::size_t I>
2325 content() noexcept {
2326 return std::get<I>(contents_);
2327 }
2328
2331 template <std::size_t TAG>
2333 append_content() noexcept {
2334 auto& which_content = std::get<TAG>(contents_);
2335 INDEX next_index = which_content.length();
2336
2337 TAGS tag = (TAGS)TAG;
2338 tags_.append(tag);
2339 index_.append(next_index);
2340
2341 return which_content;
2342 }
2343
2345 const std::string&
2346 parameters() const noexcept {
2347 return parameters_;
2348 }
2349
2351 void
2352 set_parameters(std::string parameter) noexcept {
2353 parameters_ = parameter;
2354 }
2355
2357 void
2358 set_id(size_t& id) noexcept {
2359 id_ = id;
2360 id++;
2361 for (size_t i = 0; i < contents_count_; i++) {
2362 visit_at(contents_, i, [&id](auto& content) {
2363 content.set_id(id);
2364 });
2365 }
2366 }
2367
2368
2371 void
2372 clear() noexcept {
2373 tags_.clear();
2374 index_.clear();
2375
2376 for (size_t i = 0; i < contents_count_; i++) {
2377 visit_at(contents_, i, [](auto& content) {
2378 content.clear();
2379 });
2380 }
2381 }
2382
2383
2385 size_t
2386 length() const noexcept {
2387 return tags_.length();
2388 }
2389
2391 bool
2392 is_valid(std::string& error) const noexcept {
2393 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2394
2395 std::vector<size_t> lengths = content_lengths(index_sequence);
2396 std::unique_ptr<INDEX[]> index_ptr(new INDEX[index_.length()]);
2397 index_.concatenate(index_ptr.get());
2398 std::unique_ptr<TAGS[]> tags_ptr(new TAGS[tags_.length()]);
2399 tags_.concatenate(tags_ptr.get());
2400 for (size_t i = 0; i < index_.length(); i++) {
2401 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2402 std::stringstream out;
2403 out << "Union node" << id_ << " has index " << index_ptr.get()[i]
2404 << " at position " << i << " but content has length "
2405 << lengths[tags_ptr.get()[i]] << "\n";
2406 error.append(out.str());
2407
2408 return false;
2409 }
2410 }
2411
2412 std::vector<bool> valid_contents =
2413 content_is_valid(index_sequence, error);
2414 return std::none_of(std::cbegin(valid_contents),
2415 std::cend(valid_contents),
2416 std::logical_not<bool>());
2417 }
2418
2421 void
2422 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
2423 // Store the size of tags and index buffers
2424 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2425 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2426
2427 for (size_t i = 0; i < contents_count_; i++) {
2428 visit_at(contents_, i, [&names_nbytes](auto& content) {
2429 content.buffer_nbytes(names_nbytes);
2430 });
2431 }
2432 }
2433
2434
2440 void
2441 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2442 // Concatenate tags and index buffers
2443 tags_.concatenate(reinterpret_cast<TAGS*>(
2444 buffers["node" + std::to_string(id_) + "-tags"]));
2445 index_.concatenate(reinterpret_cast<INDEX*>(
2446 buffers["node" + std::to_string(id_) + "-index"]));
2447
2448 for (size_t i = 0; i < contents_count_; i++) {
2449 visit_at(contents_, i, [&buffers](auto& content) {
2450 content.to_buffers(buffers);
2451 });
2452 }
2453 }
2454
2455
2460 void
2461 to_buffer(void* buffer, const char* name) const noexcept {
2462 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2463 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2464 }
2465 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2466 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2467 }
2468
2469 for (size_t i = 0; i < contents_count_; i++) {
2470 visit_at(contents_, i, [buffer, name](auto& content) {
2471 content.to_buffer(buffer, name);
2472 });
2473 }
2474 }
2475
2476
2481 void
2482 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2483 // Concatenate tags and index buffers
2484 tags_.concatenate(reinterpret_cast<TAGS*>(
2485 buffers["node" + std::to_string(id_) + "-tags"]));
2486 index_.concatenate(reinterpret_cast<INDEX*>(
2487 buffers["node" + std::to_string(id_) + "-index"]));
2488
2489 for (size_t i = 0; i < contents_count_; i++) {
2490 visit_at(contents_, i, [&buffers](auto& content) {
2491 content.to_char_buffers(buffers);
2492 });
2493 }
2494 }
2495
2496
2500 public:
2501 ContentsFormFunctor(std::stringstream& out)
2502 : out_(out) {}
2503
2504 // Template operator() to handle each content
2505 template <class CONTENT>
2506 void operator()(CONTENT& content) const {
2507 out_ << content.form();
2508 }
2509
2510 private:
2511 std::stringstream& out_; // Reference to the output stringstream
2512 };
2513
2514
2515 std::string
2516 form() const noexcept {
2517 std::stringstream form_key;
2518 form_key << "node" << id_;
2519 std::string params("");
2520 if (!parameters_.empty()) {
2521 params = "\"parameters\": { " + parameters_ + " }, ";
2522 }
2523 std::stringstream out;
2524 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2525 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2526 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2527 for (size_t i = 0; i < contents_count_; i++) {
2528 if (i != 0) {
2529 out << ", ";
2530 }
2531 ContentsFormFunctor contentsFormFunctor(out);
2532 visit_at(contents_, i, contentsFormFunctor);
2533 }
2534 out << "], ";
2535 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2536 return out.str();
2537 }
2538
2539
2540 private:
2543 template <std::size_t... S>
2544 std::vector<size_t>
2545 content_lengths(std::index_sequence<S...>) const {
2546 return std::vector<size_t>({std::get<S>(contents_).length()...});
2547 }
2548
2550 template <std::size_t... S>
2551 std::vector<bool>
2552 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2553 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2554 }
2555
2559 GrowableBuffer<TAGS> tags_;
2560
2564 GrowableBuffer<INDEX> index_;
2565
2567 Contents contents_;
2568
2570 std::string parameters_;
2571
2573 size_t id_;
2574
2576 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2577 };
2578
2579 } // namespace LayoutBuilder
2580} // namespace awkward
2581
2582#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
void append(PRIMITIVE datum)
Inserts one datum into the panel, possibly triggering allocation of a new panel.
Definition GrowableBuffer.h:472
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:2023
size_t mask_nbytes() const noexcept
Number of bytes the mask occupies.
Definition LayoutBuilder.h:2124
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2106
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2030
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2064
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:2053
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:2191
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2085
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2091
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2017
size_t length() const noexcept
Current number of elements (bits) accumulated in the mask.
Definition LayoutBuilder.h:2118
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:2182
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2097
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2130
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1998
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:2039
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:2147
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2076
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:2170
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1976
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:2159
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:1776
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1847
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1806
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1795
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:1921
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1826
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1751
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1832
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1770
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1762
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1854
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:1912
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1838
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1860
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1784
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:1877
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1817
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:1900
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:1889
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:1497
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1468
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:1442
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:1571
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1476
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1482
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1406
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1415
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:1429
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1504
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:1562
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1488
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1510
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1393
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1422
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:1527
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1460
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:1550
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:1539
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1265
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:1345
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:1244
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:1250
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:1227
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1273
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:1336
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1256
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1288
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:1280
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:1324
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:1313
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:2506
ContentsFormFunctor(std::stringstream &out)
Definition LayoutBuilder.h:2501
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2372
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:2316
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2297
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2300
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:2333
std::string form() const noexcept
Definition LayoutBuilder.h:2516
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2346
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2352
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2386
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:2482
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2304
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2325
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2358
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2392
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:2422
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:2461
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:2441
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1652
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1619
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:1706
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1632
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1638
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1626
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1658
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:1699
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1644
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1664
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:1671
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:1690
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:1682
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