Loading...
Searching...
No Matches
LayoutBuilder.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
2
3#ifndef AWKWARD_LAYOUTBUILDER_H_
4#define AWKWARD_LAYOUTBUILDER_H_
5
8#include "awkward/utils.h"
9
10#include <map>
11#include <algorithm>
12#include <tuple>
13#include <string>
14#include <functional>
15
18#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS awkward::BuilderOptions(1024, 1)
19
20namespace awkward {
21
22 namespace LayoutBuilder {
23
28 public:
29 BuilderSetId(size_t& id) : id_(id) {}
30
31 template <class CONTENT>
32 void operator()(CONTENT& content) {
33 content.builder.set_id(id_);
34 }
35
36 private:
37 size_t& id_;
38 };
39
47 template <std::size_t ENUM, typename BUILDER>
48 class Field {
49 public:
50 using Builder = BUILDER;
51
53 std::string
55 return std::to_string(index);
56 }
57
59 const std::size_t index = ENUM;
62 };
63
70 template <typename PRIMITIVE>
71 class Numpy {
72 public:
76 : data_(
78 size_t id = 0;
79 set_id(id);
80 }
81
88 : data_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
89 size_t id = 0;
90 set_id(id);
91 }
92
94 void
95 append(PRIMITIVE x) noexcept {
96 data_.append(x);
97 }
98
102 void
103 extend(PRIMITIVE* ptr, size_t size) noexcept {
104 data_.extend(ptr, size);
105 }
106
108 const std::string&
109 parameters() const noexcept {
110 return parameters_;
111 }
112
114 void
115 set_parameters(std::string parameter) noexcept {
116 parameters_ = parameter;
117 }
118
120 void
121 set_id(size_t& id) noexcept {
122 id_ = id;
123 id++;
124 }
125
127 void
128 clear() noexcept {
129 data_.clear();
130 }
131
133 size_t
134 length() const noexcept {
135 return data_.length();
136 }
137
139 bool
140 is_valid(std::string& /* error */) const noexcept {
141 return true;
142 }
143
145 void
146 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
147 noexcept {
148 names_nbytes["node" + std::to_string(id_) + "-data"] = data_.nbytes();
149 }
150
156 void
157 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
158 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
159 buffers["node" + std::to_string(id_) + "-data"]));
160 }
161
165 void
166 to_buffer(void* buffer, const char* name) const noexcept {
167 if (std::string(name) == std::string("node" + std::to_string(id_) + "-data")) {
168 data_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
169 }
170 }
171
176 void
177 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
178 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
179 buffers["node" + std::to_string(id_) + "-data"]));
180 }
181
184 std::string
185 form() const {
186 std::stringstream form_key;
187 form_key << "node" << id_;
188
189 std::string params("");
190 if (parameters_ == "") {
191 } else {
192 params = std::string(", \"parameters\": { " + parameters_ + " }");
193 }
194
195 if (std::is_arithmetic<PRIMITIVE>::value) {
196 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
197 type_to_name<PRIMITIVE>() + "\"" + params +
198 ", \"form_key\": \"" + form_key.str() + "\" }";
200 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
201 type_to_name<PRIMITIVE>() + "\"" + params +
202 ", \"form_key\": \"" + form_key.str() + "\" }";
203 } else {
204 throw std::runtime_error("type " +
205 std::string(typeid(PRIMITIVE).name()) +
206 "is not supported");
207 }
208 }
209
210 private:
213
215 std::string parameters_;
216
218 size_t id_;
219 };
220
235 template <typename PRIMITIVE, typename BUILDER>
237 public:
241 : offsets_(
243 offsets_.append(0);
244 size_t id = 0;
245 set_id(id);
246 }
247
254 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
255 offsets_.append(0);
256 size_t id = 0;
257 set_id(id);
258 }
259
261 BUILDER&
262 content() noexcept {
263 return content_;
264 }
265
267 BUILDER&
268 begin_list() noexcept {
269 return content_;
270 }
271
274 void
275 end_list() noexcept {
276 offsets_.append(content_.length());
277 }
278
280 const std::string&
281 parameters() const noexcept {
282 return parameters_;
283 }
284
286 void
287 set_parameters(std::string parameter) noexcept {
288 parameters_ = parameter;
289 }
290
292 void
293 set_id(size_t& id) noexcept {
294 id_ = id;
295 id++;
296 content_.set_id(id);
297 }
298
300 void
301 clear() noexcept {
302 offsets_.clear();
303 offsets_.append(0);
304 content_.clear();
305 }
306
308 size_t
309 length() const noexcept {
310 return offsets_.length() - 1;
311 }
312
314 bool
315 is_valid(std::string& error) const noexcept {
316 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
317 std::stringstream out;
318 out << "ListOffset node" << id_ << "has content length "
319 << content_.length() << "but last offset " << offsets_.last()
320 << "\n";
321 error.append(out.str());
322
323 return false;
324 } else {
325 return content_.is_valid(error);
326 }
327 }
328
331 void
332 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
333 noexcept {
334 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
335 offsets_.nbytes();
336 content_.buffer_nbytes(names_nbytes);
337 }
338
344 void
345 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
346 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
347 buffers["node" + std::to_string(id_) + "-offsets"]));
348 content_.to_buffers(buffers);
349 }
350
355 void
356 to_buffer(void* buffer, const char* name) const noexcept {
357 if (std::string(name) == std::string("node" + std::to_string(id_) + "-offsets")) {
358 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
359 }
360 content_.to_buffer(buffer, name);
361 }
362
367 void
368 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
369 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
370 buffers["node" + std::to_string(id_) + "-offsets"]));
371 content_.to_char_buffers(buffers);
372 }
373
376 std::string
377 form() const noexcept {
378 std::stringstream form_key;
379 form_key << "node" << id_;
380 std::string params("");
381 if (parameters_ == "") {
382 } else {
383 params = std::string(", \"parameters\": { " + parameters_ + " }");
384 }
385 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
386 type_to_numpy_like<PRIMITIVE>() +
387 "\", \"content\": " + content_.form() + params +
388 ", \"form_key\": \"" + form_key.str() + "\" }";
389 }
390
391 private:
396
398 BUILDER content_;
399
401 std::string parameters_;
402
404 size_t id_;
405 };
406
411 template<class PRIMITIVE>
412 class String : public ListOffset<PRIMITIVE, Numpy<uint8_t>> {
413 public:
414 String() : ListOffset<PRIMITIVE, Numpy<uint8_t>>() {
415 this->set_parameters(R"""("__array__": "string")""");
416 this->content().set_parameters(R"""("__array__": "char")""");
417 }
418
419 void append(const std::string& value) {
420 this->begin_list();
421 for (const auto& c: value) {
422 this->content().append(c);
423 }
424 this->end_list();
425 }
426 };
427
432 class Empty {
433 public:
436 size_t id = 0;
437 set_id(id);
438 }
439
440 void
441 set_id(size_t& /* id */) noexcept {}
442
443 void
444 clear() noexcept {}
445
447 size_t
448 length() const noexcept {
449 return 0;
450 }
451
453 bool
454 is_valid(std::string& /* error */) const noexcept {
455 return true;
456 }
457
458 void
459 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
460 noexcept {}
461
462 void
463 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
464
465 void
466 to_buffer(void* /* buffer */, const char* /* name */) const noexcept {}
467
472 void
473 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
474
477 std::string
478 form() const noexcept {
479 return "{ \"class\": \"EmptyArray\" }";
480 }
481
482 private:
484 size_t id_;
485 };
486
487
497 template <class MAP = std::map<std::size_t, std::string>,
498 typename... BUILDERS>
499 class Record {
500 public:
501 using RecordContents = typename std::tuple<BUILDERS...>;
502 using UserDefinedMap = MAP;
503
504 template <std::size_t INDEX>
505 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
506
509 size_t id = 0;
510 set_id(id);
511 map_fields(std::index_sequence_for<BUILDERS...>());
512 }
513
520 Record(UserDefinedMap user_defined_field_id_to_name_map)
521 : content_names_(user_defined_field_id_to_name_map) {
522 assert(content_names_.size() == fields_count_);
523 size_t id = 0;
524 set_id(id);
525 }
526
528 const std::vector<std::string>
529 fields() const noexcept {
530 if (content_names_.empty()) {
531 return fields_;
532 } else {
533 std::vector<std::string> result;
534 for (auto it : content_names_) {
535 result.emplace_back(it.second);
536 }
537 return result;
538 }
539 }
540
545 void
546 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
547 content_names_ = user_defined_field_id_to_name_map;
548 }
549
551 template <std::size_t INDEX>
552 typename RecordFieldType<INDEX>::Builder&
553 content() noexcept {
554 return std::get<INDEX>(contents).builder;
555 }
556
558 const std::string&
559 parameters() const noexcept {
560 return parameters_;
561 }
562
564 void
565 set_parameters(std::string parameter) noexcept {
566 parameters_ = parameter;
567 }
568
570 void set_id(size_t& id) noexcept {
571
572 id_ = id;
573 id++;
574
575 BuilderSetId bsi(id);
576 for (size_t i = 0; i < fields_count_; i++) {
577
578 visit_at(contents, i, bsi); // Here the functor will propagate `id`
579 }
580 }
581
587 public:
588 template <class CONTENT>
589 void operator()(CONTENT& content) const {
590 content.builder.clear();
591 }
592 };
593
594 void
595 clear() noexcept {
596 ClearBuilder clearBuilder; // instantiate the functor
597 for (size_t i = 0; i < fields_count_; i++) {
598 visit_at(contents, i, clearBuilder); // pass the functor instead of a lambda
599 }
600 }
602 size_t
603 length() const noexcept {
604 return (std::get<0>(contents).builder.length());
605 }
606
608 bool
609 is_valid(std::string& error) const noexcept {
610 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
611
612 int64_t length = -1;
613 std::vector<size_t> lengths = field_lengths(index_sequence);
614 for (size_t i = 0; i < lengths.size(); i++) {
615 if (length == -1) {
616 length = lengths[i];
617 }
618 else if (length != (int64_t)lengths[i]) {
619 std::stringstream out;
620 out << "Record node" << id_ << " has field \""
621 << fields().at(i) << "\" length " << lengths[i]
622 << " that differs from the first length " << length << "\n";
623 error.append(out.str());
624
625 return false;
626 }
627 }
628
629 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
630 return std::none_of(std::cbegin(valid_fields),
631 std::cend(valid_fields),
632 std::logical_not<bool>());
633 }
634
638 public:
639 // Constructor to capture names_nbytes by reference
640 BufferNBytesFunctor(std::map<std::string, size_t>& names_nbytes)
641 : names_nbytes_(names_nbytes) { }
642
643 // Template operator() to handle the content
644 template <class CONTENT>
645 void operator()(CONTENT& content) const {
646 content.builder.buffer_nbytes(names_nbytes_);
647 }
648
649 private:
650 std::map<std::string, size_t>& names_nbytes_; // reference to the map
651 };
652
653 void
654 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
655 BufferNBytesFunctor bufferNBytesFunctor(names_nbytes); // instantiate the functor
656 for (size_t i = 0; i < fields_count_; i++) {
657 visit_at(contents, i, bufferNBytesFunctor); // pass the functor instead of the lambda
658 }
659 }
660
667 public:
668 // Constructor to capture buffers by reference
669 ToBuffersFunctor(std::map<std::string, void*>& buffers)
670 : buffers_(buffers) { }
671
672 // Template operator() to handle the content
673 template <class CONTENT>
674 void operator()(CONTENT& content) const {
675 content.builder.to_buffers(buffers_);
676 }
677
678 private:
679 std::map<std::string, void*>& buffers_; // reference to the map
680 };
681
682 void
683 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
684 ToBuffersFunctor toBuffersFunctor(buffers); // instantiate the functor
685 for (size_t i = 0; i < fields_count_; i++) {
686 visit_at(contents, i, toBuffersFunctor); // pass the functor instead of the lambda
687 }
688 }
693 public:
694 // Constructor to capture buffer and name by reference
695 ToBufferFunctor(void* buffer, const char* name)
696 : buffer_(buffer), name_(name) { }
697
698 // Template operator() to handle the content
699 template <class CONTENT>
700 void operator()(CONTENT& content) const {
701 content.builder.to_buffer(buffer_, name_);
702 }
703
704 private:
705 void* buffer_; // reference to buffer
706 const char* name_; // reference to name
707 };
708
709 void
710 to_buffer(void* buffer, const char* name) const noexcept {
711 ToBufferFunctor toBufferFunctor(buffer, name); // instantiate the functor
712 for (size_t i = 0; i < fields_count_; i++) {
713 visit_at(contents, i, toBufferFunctor); // pass the functor instead of the lambda
714 }
715 }
716
717
723 public:
724 // Constructor to capture buffers by reference
725 ToCharBuffersFunctor(std::map<std::string, uint8_t*>& buffers)
726 : buffers_(buffers) { }
727
728 // Template operator() to handle the content
729 template <class CONTENT>
730 void operator()(CONTENT& content) const {
731 content.builder.to_char_buffers(buffers_);
732 }
733
734 private:
735 std::map<std::string, uint8_t*>& buffers_; // reference to the buffers map
736 };
737
738 void
739 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
740 ToCharBuffersFunctor toCharBuffersFunctor(buffers); // instantiate the functor
741 for (size_t i = 0; i < fields_count_; i++) {
742 visit_at(contents, i, toCharBuffersFunctor); // pass the functor instead of the lambda
743 }
744 }
745
746
750 public:
751 // Modify the constructor to accept a std::map instead of a std::vector
752 ContentsFormFunctor(std::stringstream& out, const std::map<unsigned long, std::string>& content_names)
753 : out_(out), content_names_(content_names) {}
754
755 // Template operator() to handle the content
756 template <class CONTENT>
757 void operator()(CONTENT& content) const {
758 unsigned long index = content.index; // Assuming CONTENT has an index
759 auto it = content_names_.find(index); // Lookup content name in the map
760
761 if (it != content_names_.end()) {
762 out_ << "\"" << it->second << "\": ";
763 } else {
764 out_ << "\"" << index << "\": "; // Fallback to index if not found
765 }
766
767 out_ << content.builder.form();
768 }
769
770 private:
771 std::stringstream& out_;
772 const std::map<unsigned long, std::string>& content_names_; // Store the map by reference
773 };
774
775
776 std::string form() const noexcept {
777 std::stringstream form_key;
778 form_key << "node" << id_;
779
780 std::string params("");
781 if (!parameters_.empty()) {
782 params = "\"parameters\": { " + parameters_ + " }, ";
783 }
784
785 std::stringstream out;
786 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
787
788 for (size_t i = 0; i < fields_count_; i++) {
789 if (i != 0) {
790 out << ", ";
791 }
792 ContentsFormFunctor contentsFormFunctor(out, content_names_);
793 visit_at(contents, i, contentsFormFunctor);
794 }
795
796 out << " }, ";
797 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
798 return out.str();
799 }
800
803
804 private:
807 template <std::size_t... S>
808 void
809 map_fields(std::index_sequence<S...>) noexcept {
810 fields_ = std::vector<std::string>(
811 {std::string(std::get<S>(contents).index_as_field())...});
812 }
813
816 template <std::size_t... S>
817 std::vector<size_t>
818 field_lengths(std::index_sequence<S...>) const noexcept {
819 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
820 }
821
823 template <std::size_t... S>
824 std::vector<bool>
825 field_is_valid(std::index_sequence<S...>, std::string& error) const
826 noexcept {
827 return std::vector<bool>(
828 {std::get<S>(contents).builder.is_valid(error)...});
829 }
830
832 std::vector<std::string> fields_;
833
835 UserDefinedMap content_names_;
836
838 std::string parameters_;
839
841 size_t id_;
842
844 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
845 };
846
853 template <typename... BUILDERS>
854 class Tuple {
855 using TupleContents = typename std::tuple<BUILDERS...>;
856
857 template <std::size_t INDEX>
858 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
859
860 public:
863 size_t id = 0;
864 set_id(id);
865 }
866
868 template <std::size_t INDEX>
869 TupleContentType<INDEX>&
870 content() noexcept {
871 return std::get<INDEX>(contents);
872 }
873
875 const std::string&
876 parameters() const noexcept {
877 return parameters_;
878 }
879
881 void
882 set_parameters(std::string parameter) noexcept {
883 parameters_ = parameter;
884 }
885
888 public:
889 // Constructor to capture id by reference
890 SetIdFunctor(size_t& id) : id_(id) { }
891
892 // Template operator() to handle the content
893 template <class CONTENT>
894 void operator()(CONTENT& content) const {
895 content.set_id(id_);
896 }
897
898 private:
899 size_t& id_; // reference to the id
900 };
901
902 void
903 set_id(size_t& id) noexcept {
904 id_ = id;
905 id++;
906 SetIdFunctor setIdFunctor(id); // instantiate the functor with id reference
907 for (size_t i = 0; i < fields_count_; i++) {
908 visit_at(contents, i, setIdFunctor); // pass the functor instead of the lambda
909 }
910 }
911
912
917 public:
918 // Template operator() to handle the content
919 template <class CONTENT>
920 void operator()(CONTENT& content) const {
921 content.clear();
922 }
923 };
924 void
925 clear() noexcept {
926 ClearFunctor clearFunctor; // instantiate the functor
927 for (size_t i = 0; i < fields_count_; i++) {
928 visit_at(contents, i, clearFunctor); // pass the functor instead of the lambda
929 }
930 }
931
933 size_t
934 length() const noexcept {
935 return (std::get<0>(contents).length());
936 }
937
939 bool
940 is_valid(std::string& error) const noexcept {
941 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
942
943 int64_t length = -1;
944 std::vector<size_t> lengths = content_lengths(index_sequence);
945 for (size_t i = 0; i < lengths.size(); i++) {
946 if (length == -1) {
947 length = (int64_t)lengths[i];
948 }
949 else if (length != (int64_t)lengths[i]) {
950 std::stringstream out;
951 out << "Record node" << id_ << " has index \"" << i << "\" length "
952 << lengths[i] << " that differs from the first length "
953 << length << "\n";
954 error.append(out.str());
955
956 return false;
957 }
958 }
959
960 std::vector<bool> valid_fields =
961 content_is_valid(index_sequence, error);
962 return std::none_of(std::cbegin(valid_fields),
963 std::cend(valid_fields),
964 std::logical_not<bool>());
965 }
966
970 public:
971 // Constructor to capture names_nbytes by reference
972 BufferNBytesFunctor(std::map<std::string, size_t>& names_nbytes)
973 : names_nbytes_(names_nbytes) { }
974
975 // Template operator() to handle the content
976 template <class CONTENT>
977 void operator()(CONTENT& content) const {
978 content.buffer_nbytes(names_nbytes_);
979 }
980
981 private:
982 std::map<std::string, size_t>& names_nbytes_; // reference to the map
983 };
984
985 void
986 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
987 BufferNBytesFunctor bufferNBytesFunctor(names_nbytes); // instantiate the functor
988 for (size_t i = 0; i < fields_count_; i++) {
989 visit_at(contents, i, bufferNBytesFunctor); // pass the functor instead of the lambda
990 }
991 }
992
993
1000 public:
1001 // Constructor to capture buffers by reference
1002 ToBuffersFunctor(std::map<std::string, void*>& buffers)
1003 : buffers_(buffers) { }
1004
1005 // Template operator() to handle the content
1006 template <class CONTENT>
1007 void operator()(CONTENT& content) const {
1008 content.to_buffers(buffers_);
1009 }
1010
1011 private:
1012 std::map<std::string, void*>& buffers_; // reference to the buffers map
1013 };
1014
1015 void
1016 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1017 ToBuffersFunctor toBuffersFunctor(buffers); // instantiate the functor
1018 for (size_t i = 0; i < fields_count_; i++) {
1019 visit_at(contents, i, toBuffersFunctor); // pass the functor instead of the lambda
1020 }
1021 }
1022
1023
1028 public:
1029 // Constructor to capture buffer and name by reference
1030 ToBufferFunctor(void* buffer, const char* name)
1031 : buffer_(buffer), name_(name) { }
1032
1033 // Template operator() to handle the content
1034 template <class CONTENT>
1035 void operator()(CONTENT& content) const {
1036 content.to_buffer(buffer_, name_);
1037 }
1038
1039 private:
1040 void* buffer_; // reference to the buffer
1041 const char* name_; // reference to the name
1042 };
1043
1044 void
1045 to_buffer(void* buffer, const char* name) const noexcept {
1046 ToBufferFunctor toBufferFunctor(buffer, name); // instantiate the functor
1047 for (size_t i = 0; i < fields_count_; i++) {
1048 visit_at(contents, i, toBufferFunctor); // pass the functor instead of the lambda
1049 }
1050 }
1051
1052
1058 public:
1059 // Constructor to capture buffers by reference
1060 ToCharBuffersFunctor(std::map<std::string, uint8_t*>& buffers)
1061 : buffers_(buffers) { }
1062
1063 // Template operator() to handle the content
1064 template <class CONTENT>
1065 void operator()(CONTENT& content) const {
1066 content.to_char_buffers(buffers_);
1067 }
1068
1069 private:
1070 std::map<std::string, uint8_t*>& buffers_; // reference to the buffers map
1071 };
1072
1073 void
1074 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1075 ToCharBuffersFunctor toCharBuffersFunctor(buffers); // instantiate the functor
1076 for (size_t i = 0; i < fields_count_; i++) {
1077 visit_at(contents, i, toCharBuffersFunctor); // pass the functor instead of the lambda
1078 }
1079 }
1080
1081
1084 // class ContentsFormFunctor {
1085 // public:
1086 // ContentsFormFunctor(std::stringstream& out)
1087 // : out_(out) {}
1088
1089 // // Template operator() to handle each content
1090 // template <class CONTENT>
1091 // void operator()(CONTENT& content) const {
1092 // out_ << content.form();
1093 // }
1094
1095 // private:
1096 // std::stringstream& out_; // Reference to the output stringstream
1097 // };
1099 public:
1100 // Modify the constructor to accept a std::map instead of a std::vector
1101 ContentsFormFunctor(std::stringstream& out, const std::map<unsigned long, std::string>& content_names)
1102 : out_(out), content_names_(content_names) {}
1103
1104 // Template operator() to handle the content
1105 template <class CONTENT>
1106 void operator()(CONTENT& content) const {
1107 unsigned long index = content.index; // Assuming CONTENT has an index
1108 auto it = content_names_.find(index); // Lookup content name in the map
1109
1110 if (it != content_names_.end()) {
1111 out_ << "\"" << it->second << "\": ";
1112 } else {
1113 out_ << "\"" << index << "\": "; // Fallback to index if not found
1114 }
1115
1116 out_ << content.builder.form();
1117 }
1118
1119 private:
1120 std::stringstream& out_;
1121 const std::map<unsigned long, std::string>& content_names_; // Store the map by reference
1122 };
1123
1124
1125 std::string
1126 form() const noexcept {
1127 std::stringstream form_key;
1128 form_key << "node" << id_;
1129 std::string params("");
1130 if (!parameters_.empty()) {
1131 params = "\"parameters\": { " + parameters_ + " }, ";
1132 }
1133 std::stringstream out;
1134 out << "{ \"class\": \"RecordArray\", \"contents\": [";
1135 for (size_t i = 0; i < fields_count_; i++) {
1136 if (i != 0) {
1137 out << ", ";
1138 }
1139 ContentsFormFunctor contentsFormFunctor(out);
1140 visit_at(contents, i, contentsFormFunctor);
1141 }
1142 out << "], ";
1143 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
1144 return out.str();
1145 }
1146
1148 TupleContents contents;
1149
1150 private:
1153 template <std::size_t... S>
1154 std::vector<size_t>
1155 content_lengths(std::index_sequence<S...>) const noexcept {
1156 return std::vector<size_t>({std::get<S>(contents).length()...});
1157 }
1158
1160 template <std::size_t... S>
1161 std::vector<bool>
1162 content_is_valid(std::index_sequence<S...>, std::string& error) const
1163 noexcept {
1164 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
1165 }
1166
1168 std::vector<int64_t> field_index_;
1169
1171 std::string parameters_;
1172
1174 size_t id_;
1175
1177 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
1178 };
1179
1193 template <unsigned SIZE, typename BUILDER>
1194 class Regular {
1195 public:
1197 Regular() : length_(0) {
1198 size_t id = 0;
1199 set_id(id);
1200 }
1201
1203 BUILDER&
1204 content() noexcept {
1205 return content_;
1206 }
1207
1210 BUILDER&
1211 begin_list() noexcept {
1212 return content_;
1213 }
1214
1216 void
1217 end_list() noexcept {
1218 length_++;
1219 }
1220
1222 const std::string&
1223 parameters() const noexcept {
1224 return parameters_;
1225 }
1226
1228 void
1229 set_parameters(std::string parameter) noexcept {
1230 parameters_ = parameter;
1231 }
1232
1234 void
1235 set_id(size_t& id) noexcept {
1236 id_ = id;
1237 id++;
1238 content_.set_id(id);
1239 }
1240
1242 void
1243 clear() noexcept {
1244 length_ = 0;
1245 content_.clear();
1246 }
1247
1249 size_t
1250 length() const noexcept {
1251 return length_;
1252 }
1253
1255 bool
1256 is_valid(std::string& error) const noexcept {
1257 if (content_.length() != length_ * size_) {
1258 std::stringstream out;
1259 out << "Regular node" << id_ << "has content length "
1260 << content_.length() << ", but length " << length_ << " and size "
1261 << size_ << "\n";
1262 error.append(out.str());
1263
1264 return false;
1265 } else {
1266 return content_.is_valid(error);
1267 }
1268 }
1269
1272 void
1273 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1274 noexcept {
1275 content_.buffer_nbytes(names_nbytes);
1276 }
1277
1283 void
1284 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1285 content_.to_buffers(buffers);
1286 }
1287
1291 void
1292 to_buffer(void* buffer, const char* name) const noexcept {
1293 content_.to_buffer(buffer, name);
1294 }
1295
1300 void
1301 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1302 content_.to_char_buffers(buffers);
1303 }
1304
1307 std::string
1308 form() const noexcept {
1309 std::stringstream form_key;
1310 form_key << "node" << id_;
1311 std::string params("");
1312 if (parameters_ == "") {
1313 } else {
1314 params = std::string(", \"parameters\": { " + parameters_ + " }");
1315 }
1316 return "{ \"class\": \"RegularArray\", \"content\": " +
1317 content_.form() + ", \"size\": " + std::to_string(size_) +
1318 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1319 }
1320
1321 private:
1323 BUILDER content_;
1324
1326 std::string parameters_;
1327
1329 size_t id_;
1330
1332 size_t length_;
1333
1335 size_t size_ = SIZE;
1336 };
1337
1338
1348 template <typename PRIMITIVE, typename BUILDER>
1349 class Indexed {
1350 public:
1354 : index_(
1356 max_index_(0) {
1357 size_t id = 0;
1358 set_id(id);
1359 }
1360
1367 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1368 max_index_(0) {
1369 size_t id = 0;
1370 set_id(id);
1371 }
1372
1374 BUILDER&
1375 content() noexcept {
1376 return content_;
1377 }
1378
1381 BUILDER&
1382 append_index() noexcept {
1383 return append_index(content_.length());
1384 }
1385
1388 BUILDER&
1389 append_index(size_t i) noexcept {
1390 index_.append(i);
1391 if (i > max_index_) {
1392 max_index_ = i;
1393 } else if (i < 0) {
1394 max_index_ = UINTMAX_MAX;
1395 }
1396 return content_;
1397 }
1398
1403 BUILDER&
1404 extend_index(size_t size) noexcept {
1405 size_t start = content_.length();
1406 size_t stop = start + size;
1407 if (stop - 1 > max_index_) {
1408 max_index_ = stop - 1;
1409 }
1410 for (size_t i = start; i < stop; i++) {
1411 index_.append(i);
1412 }
1413 return content_;
1414 }
1415
1417 const std::string&
1418 parameters() const noexcept {
1419 return parameters_;
1420 }
1421
1423 void
1424 set_parameters(std::string parameter) noexcept {
1425 parameters_ = parameter;
1426 }
1427
1429 void
1430 set_id(size_t& id) noexcept {
1431 id_ = id;
1432 id++;
1433 content_.set_id(id);
1434 }
1435
1438 void
1439 clear() noexcept {
1440 max_index_ = 0;
1441 index_.clear();
1442 content_.clear();
1443 }
1444
1446 size_t
1447 length() const noexcept {
1448 return index_.length();
1449 }
1450
1453 void
1454 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1455 noexcept {
1456 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1457 content_.buffer_nbytes(names_nbytes);
1458 }
1459
1461 bool
1462 is_valid(std::string& error) const noexcept {
1463
1464 if (max_index_ == UINTMAX_MAX) {
1465 std::stringstream out;
1466 out << "Indexed node" << id_ << " has a negative index\n";
1467 error.append(out.str());
1468 return false;
1469 } else if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1470 } else if (max_index_ >= content_.length()) {
1471 std::stringstream out;
1472 out << "Indexed node" << id_ << " has index " << max_index_
1473 << " but content has length "
1474 << content_.length() << "\n";
1475 error.append(out.str());
1476 return false;
1477 }
1478 return content_.is_valid(error);
1479 }
1480
1486 void
1487 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1488 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1489 buffers["node" + std::to_string(id_) + "-index"]));
1490 content_.to_buffers(buffers);
1491 }
1492
1497 void
1498 to_buffer(void* buffer, const char* name) const noexcept {
1499 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1500 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1501 }
1502 content_.to_buffer(buffer, name);
1503 }
1504
1509 void
1510 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1511 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1512 buffers["node" + std::to_string(id_) + "-index"]));
1513 content_.to_char_buffers(buffers);
1514 }
1515
1518 std::string
1519 form() const noexcept {
1520 std::stringstream form_key;
1521 form_key << "node" << id_;
1522 std::string params("");
1523 if (parameters_ == "") {
1524 } else {
1525 params = std::string(", \"parameters\": { " + parameters_ + " }");
1526 }
1527 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1528 type_to_numpy_like<PRIMITIVE>() +
1529 "\", \"content\": " + content_.form() + params +
1530 ", \"form_key\": \"" + form_key.str() + "\" }";
1531 }
1532
1533 private:
1538
1540 BUILDER content_;
1541
1543 std::string parameters_;
1544
1546 size_t id_;
1547
1549 size_t max_index_;
1550 };
1551
1562 template <typename PRIMITIVE, typename BUILDER>
1564 public:
1568 : index_(
1570 last_valid_(-1),
1571 max_index_(0) {
1572 size_t id = 0;
1573 set_id(id);
1574 }
1575
1582 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1583 last_valid_(-1),
1584 max_index_(0) {
1585 size_t id = 0;
1586 set_id(id);
1587 }
1588
1590 BUILDER&
1591 content() noexcept {
1592 return content_;
1593 }
1594
1597 BUILDER&
1598 append_valid() noexcept {
1599 last_valid_ = content_.length();
1600 return append_valid(last_valid_);
1601 }
1602
1605 BUILDER&
1606 append_valid(size_t i) noexcept {
1607 last_valid_ = content_.length();
1608 index_.append(i);
1609 if (i > max_index_) {
1610 max_index_ = i;
1611 }
1612 return content_;
1613 }
1614
1619 BUILDER&
1620 extend_valid(size_t size) noexcept {
1621 size_t start = content_.length();
1622 size_t stop = start + size;
1623 last_valid_ = stop - 1;
1624 if (last_valid_ > max_index_) {
1625 max_index_ = last_valid_;
1626 }
1627 for (size_t i = start; i < stop; i++) {
1628 index_.append(i);
1629 }
1630 return content_;
1631 }
1632
1634 void
1635 append_invalid() noexcept {
1636 index_.append(-1);
1637 }
1638
1642 void
1643 extend_invalid(size_t size) noexcept {
1644 for (size_t i = 0; i < size; i++) {
1645 index_.append(-1);
1646 }
1647 }
1648
1650 const std::string&
1651 parameters() const noexcept {
1652 return parameters_;
1653 }
1654
1656 void
1657 set_parameters(std::string parameter) noexcept {
1658 parameters_ = parameter;
1659 }
1660
1662 void
1663 set_id(size_t& id) noexcept {
1664 id_ = id;
1665 id++;
1666 content_.set_id(id);
1667 }
1668
1671 void
1672 clear() noexcept {
1673 last_valid_ = -1;
1674 index_.clear();
1675 content_.clear();
1676 }
1677
1679 size_t
1680 length() const noexcept {
1681 return index_.length();
1682 }
1683
1685 bool
1686 is_valid(std::string& error) const noexcept {
1687 if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1688 } else if (max_index_ >= content_.length()) {
1689 std::stringstream out;
1690 out << "IndexedOption node" << id_ << " has index " << max_index_
1691 << " but content has length "
1692 << content_.length() << "\n";
1693 error.append(out.str());
1694
1695 return false;
1696 }
1697 return content_.is_valid(error);
1698 }
1699
1702 void
1703 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1704 noexcept {
1705 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1706 content_.buffer_nbytes(names_nbytes);
1707 }
1708
1714 void
1715 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1716 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1717 buffers["node" + std::to_string(id_) + "-index"]));
1718 content_.to_buffers(buffers);
1719 }
1720
1725 void
1726 to_buffer(void* buffer, const char* name) const noexcept {
1727 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1728 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1729 }
1730 content_.to_buffer(buffer, name);
1731 }
1732
1737 void
1738 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1739 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1740 buffers["node" + std::to_string(id_) + "-index"]));
1741 content_.to_char_buffers(buffers);
1742 }
1743
1746 std::string
1747 form() const noexcept {
1748 std::stringstream form_key;
1749 form_key << "node" << id_;
1750 std::string params("");
1751 if (parameters_ == "") {
1752 } else {
1753 params = std::string(", \"parameters\": { " + parameters_ + " }");
1754 }
1755 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1756 type_to_numpy_like<PRIMITIVE>() +
1757 "\", \"content\": " + content_.form() + params +
1758 ", \"form_key\": \"" + form_key.str() + "\" }";
1759 }
1760
1761 private:
1766
1768 BUILDER content_;
1769
1771 std::string parameters_;
1772
1774 size_t id_;
1775
1777 size_t last_valid_;
1778
1780 size_t max_index_;
1781 };
1782
1794 template <typename BUILDER>
1795 class Unmasked {
1796 public:
1799 size_t id = 0;
1800 set_id(id);
1801 }
1802
1804 BUILDER&
1805 content() noexcept {
1806 return content_;
1807 }
1808
1810 const std::string&
1811 parameters() const noexcept {
1812 return parameters_;
1813 }
1814
1816 void
1817 set_parameters(std::string parameter) noexcept {
1818 parameters_ = parameter;
1819 }
1820
1822 void
1823 set_id(size_t& id) noexcept {
1824 id_ = id;
1825 id++;
1826 content_.set_id(id);
1827 }
1828
1830 void
1831 clear() noexcept {
1832 content_.clear();
1833 }
1834
1836 size_t
1837 length() const noexcept {
1838 return content_.length();
1839 }
1840
1842 bool
1843 is_valid(std::string& error) const noexcept {
1844 return content_.is_valid(error);
1845 }
1846
1849 void
1850 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1851 noexcept {
1852 content_.buffer_nbytes(names_nbytes);
1853 }
1854
1860 void
1861 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1862 content_.to_buffers(buffers);
1863 }
1864
1868 void
1869 to_buffer(void* buffer, const char* name) const noexcept {
1870 content_.to_buffer(buffer, name);
1871 }
1872
1877 void
1878 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1879 content_.to_char_buffers(buffers);
1880 }
1881
1884 std::string
1885 form() const noexcept {
1886 std::stringstream form_key;
1887 form_key << "node" << id_;
1888 std::string params("");
1889 if (parameters_ == "") {
1890 } else {
1891 params = std::string(", \"parameters\": { " + parameters_ + " }");
1892 }
1893 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1894 content_.form() + params + ", \"form_key\": \"" +
1895 form_key.str() + "\" }";
1896 }
1897
1898 private:
1900 BUILDER content_;
1901
1903 std::string parameters_;
1904
1906 size_t id_;
1907 };
1908
1925 template <bool VALID_WHEN, typename BUILDER>
1927 public:
1932 size_t id = 0;
1933 set_id(id);
1934 }
1935
1942 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1943 size_t id = 0;
1944 set_id(id);
1945 }
1946
1948 BUILDER&
1949 content() noexcept {
1950 return content_;
1951 }
1952
1954 bool
1955 valid_when() const noexcept {
1956 return valid_when_;
1957 }
1958
1962 BUILDER&
1963 append_valid() noexcept {
1964 mask_.append(valid_when_);
1965 return content_;
1966 }
1967
1973 BUILDER&
1974 extend_valid(size_t size) noexcept {
1975 for (size_t i = 0; i < size; i++) {
1976 mask_.append(valid_when_);
1977 }
1978 return content_;
1979 }
1980
1984 BUILDER&
1985 append_invalid() noexcept {
1986 mask_.append(!valid_when_);
1987 return content_;
1988 }
1989
1995 BUILDER&
1996 extend_invalid(size_t size) noexcept {
1997 for (size_t i = 0; i < size; i++) {
1998 mask_.append(!valid_when_);
1999 }
2000 return content_;
2001 }
2002
2004 const std::string&
2005 parameters() const noexcept {
2006 return parameters_;
2007 }
2008
2010 void
2011 set_parameters(std::string parameter) noexcept {
2012 parameters_ = parameter;
2013 }
2014
2016 void
2017 set_id(size_t& id) noexcept {
2018 id_ = id;
2019 id++;
2020 content_.set_id(id);
2021 }
2022
2025 void
2026 clear() noexcept {
2027 mask_.clear();
2028 content_.clear();
2029 }
2030
2032 size_t
2033 length() const noexcept {
2034 return mask_.length();
2035 }
2036
2038 bool
2039 is_valid(std::string& error) const noexcept {
2040 if (content_.length() != mask_.length()) {
2041 std::stringstream out;
2042 out << "ByteMasked node" << id_ << "has content length "
2043 << content_.length() << "but mask length " << mask_.length()
2044 << "\n";
2045 error.append(out.str());
2046
2047 return false;
2048 } else {
2049 return content_.is_valid(error);
2050 }
2051 }
2052
2055 void
2056 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2057 noexcept {
2058 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2059 content_.buffer_nbytes(names_nbytes);
2060 }
2061
2067 void
2068 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2069 mask_.concatenate(reinterpret_cast<int8_t*>(
2070 buffers["node" + std::to_string(id_) + "-mask"]));
2071 content_.to_buffers(buffers);
2072 }
2073
2078 void
2079 to_buffer(void* buffer, const char* name) const noexcept {
2080 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2081 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
2082 }
2083 content_.to_buffer(buffer, name);
2084 }
2085
2090 void
2091 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2092 mask_.concatenate(reinterpret_cast<int8_t*>(
2093 buffers["node" + std::to_string(id_) + "-mask"]));
2094 content_.to_char_buffers(buffers);
2095 }
2096
2099 std::string
2100 form() const noexcept {
2101 std::stringstream form_key, form_valid_when;
2102 form_key << "node" << id_;
2103 form_valid_when << std::boolalpha << valid_when_;
2104 std::string params("");
2105 if (parameters_ == "") {
2106 } else {
2107 params = std::string(", \"parameters\": { " + parameters_ + " }");
2108 }
2109 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
2110 "\"content\": " +
2111 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2112 params + ", \"form_key\": \"" + form_key.str() + "\" }";
2113 }
2114
2115 private:
2120
2122 BUILDER content_;
2123
2125 std::string parameters_;
2126
2128 size_t id_;
2129
2131 bool valid_when_ = VALID_WHEN;
2132 };
2133
2150 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
2152 public:
2157 current_byte_(uint8_t(0)),
2158 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2159 current_index_(0) {
2160 size_t id = 0;
2161 set_id(id);
2162 if (lsb_order_) {
2163 for (size_t i = 0; i < 8; i++) {
2164 cast_[i] = 1 << i;
2165 }
2166 } else {
2167 for (size_t i = 0; i < 8; i++) {
2168 cast_[i] = 128 >> i;
2169 }
2170 }
2171 }
2172
2179 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
2180 current_byte_(uint8_t(0)),
2181 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2182 current_index_(0) {
2183 size_t id = 0;
2184 set_id(id);
2185 if (lsb_order_) {
2186 for (size_t i = 0; i < 8; i++) {
2187 cast_[i] = 1 << i;
2188 }
2189 } else {
2190 for (size_t i = 0; i < 8; i++) {
2191 cast_[i] = 128 >> i;
2192 }
2193 }
2194 }
2195
2197 BUILDER&
2198 content() noexcept {
2199 return content_;
2200 }
2201
2203 bool
2204 valid_when() const noexcept {
2205 return valid_when_;
2206 }
2207
2210 bool
2211 lsb_order() const noexcept {
2212 return lsb_order_;
2213 }
2214
2219 BUILDER&
2220 append_valid() noexcept {
2221 append_begin();
2222 current_byte_ |= cast_[current_index_];
2223 append_end();
2224 return content_;
2225 }
2226
2233 BUILDER&
2234 extend_valid(size_t size) noexcept {
2235 for (size_t i = 0; i < size; i++) {
2236 append_valid();
2237 }
2238 return content_;
2239 }
2240
2244 BUILDER&
2245 append_invalid() noexcept {
2246 append_begin();
2247 append_end();
2248 return content_;
2249 }
2250
2256 BUILDER&
2257 extend_invalid(size_t size) noexcept {
2258 for (size_t i = 0; i < size; i++) {
2260 }
2261 return content_;
2262 }
2263
2265 const std::string&
2266 parameters() const noexcept {
2267 return parameters_;
2268 }
2269
2271 void
2272 set_parameters(std::string parameter) noexcept {
2273 parameters_ = parameter;
2274 }
2275
2277 void
2278 set_id(size_t& id) noexcept {
2279 id_ = id;
2280 id++;
2281 content_.set_id(id);
2282 }
2283
2286 void
2287 clear() noexcept {
2288 mask_.clear();
2289 content_.clear();
2290 current_byte_ = 0;
2291 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2292 current_index_ = 0;
2293 }
2294
2296 size_t
2297 length() const noexcept {
2298 return mask_.length() > 0 ?
2299 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2300 }
2301
2303 bool
2304 is_valid(std::string& error) const noexcept {
2305 if (content_.length() != length()) {
2306 std::stringstream out;
2307 out << "BitMasked node" << id_ << "has content length "
2308 << content_.length() << "but bit mask length " << mask_.length()
2309 << "\n";
2310 error.append(out.str());
2311
2312 return false;
2313 } else {
2314 return content_.is_valid(error);
2315 }
2316 }
2317
2320 void
2321 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2322 noexcept {
2323 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2324 content_.buffer_nbytes(names_nbytes);
2325 }
2326
2332 void
2333 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2334 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2335 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2336 mask_.append(reinterpret_cast<uint8_t*>(
2337 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2338 content_.to_buffers(buffers);
2339 }
2340
2345 void
2346 to_buffer(void* buffer, const char* name) const noexcept {
2347 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2348 mask_.concatenate_from(reinterpret_cast<uint8_t*>(buffer), 0, 1);
2349 mask_.append(reinterpret_cast<uint8_t*>(buffer), mask_.length() - 1, 0, 1);
2350 }
2351 content_.to_buffer(buffer, name);
2352 }
2353
2358 void
2359 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2360 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2361 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2362 mask_.append(reinterpret_cast<uint8_t*>(
2363 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2364 content_.to_char_buffers(buffers);
2365 }
2366
2369 std::string
2370 form() const noexcept {
2371 std::stringstream form_key, form_valid_when, form_lsb_order;
2372 form_key << "node" << id_;
2373 form_valid_when << std::boolalpha << valid_when_;
2374 form_lsb_order << std::boolalpha << lsb_order_;
2375 std::string params("");
2376 if (parameters_ == "") {
2377 } else {
2378 params = std::string(", \"parameters\": { " + parameters_ + " }");
2379 }
2380 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2381 "\"content\": " +
2382 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2383 ", \"lsb_order\": " + form_lsb_order.str() + params +
2384 ", \"form_key\": \"" + form_key.str() + "\" }";
2385 }
2386
2387 private:
2391 void
2392 append_begin() {
2393 if (current_index_ == 8) {
2394 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2395 current_byte_ = uint8_t(0);
2396 current_index_ = 0;
2397 }
2398 }
2399
2405 void
2406 append_end() {
2407 current_index_ += 1;
2408 if (valid_when_) {
2409 current_byte_ref_ = current_byte_;
2410 } else {
2411 current_byte_ref_ = ~current_byte_;
2412 }
2413 }
2414
2418 GrowableBuffer<uint8_t> mask_;
2419
2421 BUILDER content_;
2422
2424 std::string parameters_;
2425
2427 size_t id_;
2428
2430 uint8_t current_byte_;
2431
2433 uint8_t& current_byte_ref_;
2434
2436 size_t current_index_;
2437
2439 uint8_t cast_[8];
2440
2442 bool valid_when_ = VALID_WHEN;
2443
2446 bool lsb_order_ = LSB_ORDER;
2447 };
2448
2464 template <typename TAGS, typename INDEX, typename... BUILDERS>
2465 class Union {
2466 public:
2467 using Contents = typename std::tuple<BUILDERS...>;
2468
2469 template <std::size_t I>
2470 using ContentType = std::tuple_element_t<I, Contents>;
2471
2477 size_t id = 0;
2478 set_id(id);
2479 for (size_t i = 0; i < contents_count_; i++) {
2480 last_valid_index_[i] = -1;
2481 }
2482 }
2483
2490 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2491 index_(awkward::GrowableBuffer<INDEX>(options)) {
2492 size_t id = 0;
2493 set_id(id);
2494 for (size_t i = 0; i < contents_count_; i++) {
2495 last_valid_index_[i] = -1;
2496 }
2497 }
2498
2499 template <std::size_t I>
2500 ContentType<I>&
2501 content() noexcept {
2502 return std::get<I>(contents_);
2503 }
2504
2507 template <std::size_t TAG>
2508 ContentType<TAG>&
2509 append_content() noexcept {
2510 auto& which_content = std::get<TAG>(contents_);
2511 INDEX next_index = which_content.length();
2512
2513 TAGS tag = (TAGS)TAG;
2514 last_valid_index_[tag] = next_index;
2515 tags_.append(tag);
2516 index_.append(next_index);
2517
2518 return which_content;
2519 }
2520
2522 const std::string&
2523 parameters() const noexcept {
2524 return parameters_;
2525 }
2526
2528 void
2529 set_parameters(std::string parameter) noexcept {
2530 parameters_ = parameter;
2531 }
2532
2535 public:
2536 // Constructor to capture id by reference
2537 SetIdFunctor(size_t& id) : id_(id) { }
2538
2539 // Template operator() to handle the content
2540 template <class CONTENT>
2541 void operator()(CONTENT& content) const {
2542 content.set_id(id_);
2543 }
2544
2545 private:
2546 size_t& id_; // reference to the id
2547 };
2548
2549 void
2550 set_id(size_t& id) noexcept {
2551 id_ = id;
2552 id++;
2553 SetIdFunctor setIdFunctor(id); // instantiate the functor
2554 for (size_t i = 0; i < contents_count_; i++) {
2555 visit_at(contents_, i, setIdFunctor); // pass the functor instead of the lambda
2556 }
2557 }
2558
2559
2565 public:
2566 // Template operator() to handle the content
2567 template <class CONTENT>
2568 void operator()(CONTENT& content) const {
2569 content.clear();
2570 }
2571 };
2572
2573 void
2574 clear() noexcept {
2575 for (size_t i = 0; i < contents_count_; i++) {
2576 last_valid_index_[i] = -1;
2577 }
2578 tags_.clear();
2579 index_.clear();
2580
2581 ClearContentsFunctor clearContentsFunctor; // instantiate the functor
2582 for (size_t i = 0; i < contents_count_; i++) {
2583 visit_at(contents_, i, clearContentsFunctor); // pass the functor instead of the lambda
2584 }
2585 }
2586
2587
2589 size_t
2590 length() const noexcept {
2591 return tags_.length();
2592 }
2593
2595 bool
2596 is_valid(std::string& error) const noexcept {
2597 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2598
2599 std::vector<size_t> lengths = content_lengths(index_sequence);
2600 std::unique_ptr<INDEX[]> index_ptr(new INDEX[index_.length()]);
2601 index_.concatenate(index_ptr.get());
2602 std::unique_ptr<TAGS[]> tags_ptr(new TAGS[tags_.length()]);
2603 tags_.concatenate(tags_ptr.get());
2604 for (size_t i = 0; i < index_.length(); i++) {
2605 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2606 std::stringstream out;
2607 out << "Union node" << id_ << " has index " << index_ptr.get()[i]
2608 << " at position " << i << " but content has length "
2609 << lengths[tags_ptr.get()[i]] << "\n";
2610 error.append(out.str());
2611
2612 return false;
2613 }
2614 }
2615
2616 std::vector<bool> valid_contents =
2617 content_is_valid(index_sequence, error);
2618 return std::none_of(std::cbegin(valid_contents),
2619 std::cend(valid_contents),
2620 std::logical_not<bool>());
2621 }
2622
2626 public:
2627 // Constructor to capture names_nbytes by reference
2628 BufferNBytesFunctor(std::map<std::string, size_t>& names_nbytes)
2629 : names_nbytes_(names_nbytes) {}
2630
2631 // Template operator() to handle the content
2632 template <class CONTENT>
2633 void operator()(CONTENT& content) const {
2634 content.buffer_nbytes(names_nbytes_);
2635 }
2636
2637 private:
2638 std::map<std::string, size_t>& names_nbytes_; // reference to the map
2639 };
2640
2641 void
2642 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const noexcept {
2643 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2644
2645 // Store the size of tags and index buffers
2646 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2647 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2648
2649 // Instantiate the functor to handle each content's buffer_nbytes call
2650 BufferNBytesFunctor bufferNBytesFunctor(names_nbytes);
2651
2652 for (size_t i = 0; i < contents_count_; i++) {
2653 visit_at(contents_, i, bufferNBytesFunctor); // pass the functor instead of the lambda
2654 }
2655 }
2656
2657
2664 public:
2665 // Constructor to capture buffers by reference
2666 ToBuffersFunctor(std::map<std::string, void*>& buffers)
2667 : buffers_(buffers) { }
2668
2669 // Template operator() to handle the content
2670 template <class CONTENT>
2671 void operator()(CONTENT& content) const {
2672 content.to_buffers(buffers_);
2673 }
2674
2675 private:
2676 std::map<std::string, void*>& buffers_; // reference to the buffers map
2677 };
2678
2679 void
2680 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2681 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2682
2683 // Concatenate tags and index buffers
2684 tags_.concatenate(reinterpret_cast<TAGS*>(
2685 buffers["node" + std::to_string(id_) + "-tags"]));
2686 index_.concatenate(reinterpret_cast<INDEX*>(
2687 buffers["node" + std::to_string(id_) + "-index"]));
2688
2689 // Create the functor to handle each content's to_buffers call
2690 ToBuffersFunctor toBuffersFunctor(buffers);
2691
2692 for (size_t i = 0; i < contents_count_; i++) {
2693 visit_at(contents_, i, toBuffersFunctor); // pass the functor instead of the lambda
2694 }
2695 }
2696
2697
2703 public:
2704 // Constructor to capture buffer and name by reference
2705 ToBufferFunctor(void* buffer, const char* name)
2706 : buffer_(buffer), name_(name) { }
2707
2708 // Template operator() to handle the content
2709 template <class CONTENT>
2710 void operator()(CONTENT& content) const {
2711 content.to_buffer(buffer_, name_);
2712 }
2713
2714 private:
2715 void* buffer_; // reference to the buffer
2716 const char* name_; // reference to the name
2717 };
2718
2719 void
2720 to_buffer(void* buffer, const char* name) const noexcept {
2721 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2722
2723 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2724 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2725 }
2726 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2727 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2728 }
2729
2730 // Instantiate the functor to handle each content's to_buffer call
2731 ToBufferFunctor toBufferFunctor(buffer, name);
2732
2733 for (size_t i = 0; i < contents_count_; i++) {
2734 visit_at(contents_, i, toBufferFunctor); // pass the functor instead of the lambda
2735 }
2736 }
2737
2738
2744 public:
2745 // Constructor to capture buffers by reference
2746 ToCharBuffersFunctor(std::map<std::string, uint8_t*>& buffers)
2747 : buffers_(buffers) { }
2748
2749 // Template operator() to handle the content
2750 template <class CONTENT>
2751 void operator()(CONTENT& content) const {
2752 content.to_char_buffers(buffers_);
2753 }
2754
2755 private:
2756 std::map<std::string, uint8_t*>& buffers_; // reference to the buffers map
2757 };
2758
2759 void
2760 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2761 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2762
2763 // Concatenate tags and index buffers
2764 tags_.concatenate(reinterpret_cast<TAGS*>(
2765 buffers["node" + std::to_string(id_) + "-tags"]));
2766 index_.concatenate(reinterpret_cast<INDEX*>(
2767 buffers["node" + std::to_string(id_) + "-index"]));
2768
2769 // Instantiate the functor to handle each content's to_char_buffers call
2770 ToCharBuffersFunctor toCharBuffersFunctor(buffers);
2771
2772 for (size_t i = 0; i < contents_count_; i++) {
2773 visit_at(contents_, i, toCharBuffersFunctor); // pass the functor instead of the lambda
2774 }
2775 }
2776
2777
2781 public:
2782 // Modify the constructor to accept a std::map instead of a std::vector
2783 ContentsFormFunctor(std::stringstream& out, const std::map<unsigned long, std::string>& content_names)
2784 : out_(out), content_names_(content_names) {}
2785
2786 // Template operator() to handle the content
2787 template <class CONTENT>
2788 void operator()(CONTENT& content) const {
2789 unsigned long index = content.index; // Assuming CONTENT has an index
2790 auto it = content_names_.find(index); // Lookup content name in the map
2791
2792 if (it != content_names_.end()) {
2793 out_ << "\"" << it->second << "\": ";
2794 } else {
2795 out_ << "\"" << index << "\": "; // Fallback to index if not found
2796 }
2797
2798 out_ << content.builder.form();
2799 }
2800
2801 private:
2802 std::stringstream& out_;
2803 const std::map<unsigned long, std::string>& content_names_; // Store the map by reference
2804 };
2805
2806
2807 std::string
2808 form() const noexcept {
2809 std::stringstream form_key;
2810 form_key << "node" << id_;
2811 std::string params("");
2812 if (!parameters_.empty()) {
2813 params = ", \"parameters\": { " + parameters_ + " }";
2814 }
2815 std::stringstream out;
2816 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2817 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2818 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2819 for (size_t i = 0; i < contents_count_; i++) {
2820 if (i != 0) {
2821 out << ", ";
2822 }
2823 ContentsFormFunctor contentsFormFunctor(out);
2824 visit_at(contents_, i, contentsFormFunctor);
2825 }
2826 out << "], ";
2827 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2828 return out.str();
2829 }
2830
2831
2832 private:
2835 template <std::size_t... S>
2836 std::vector<size_t>
2837 content_lengths(std::index_sequence<S...>) const {
2838 return std::vector<size_t>({std::get<S>(contents_).length()...});
2839 }
2840
2842 template <std::size_t... S>
2843 std::vector<bool>
2844 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2845 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2846 }
2847
2851 GrowableBuffer<TAGS> tags_;
2852
2856 GrowableBuffer<INDEX> index_;
2857
2859 Contents contents_;
2860
2862 std::string parameters_;
2863
2865 size_t id_;
2866
2868 size_t last_valid_index_[sizeof...(BUILDERS)];
2869
2871 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2872 };
2873
2874 } // namespace LayoutBuilder
2875} // namespace awkward
2876
2877#endif // AWKWARD_LAYOUTBUILDER_H_
#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS
Object of BuilderOptions which sets the values of the default options.
Definition LayoutBuilder.h:18
virtual const std::string to_buffers(BuffersContainer &container, int64_t &form_key_id) const =0
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
virtual void clear()=0
Removes all accumulated data without resetting the type knowledge.
virtual const BuilderPtr index(int64_t index)=0
Sets the pointer to a given tuple field index; the next command will fill that slot.
Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels)...
Definition GrowableBuffer.h:233
void concatenate_from(PRIMITIVE *external_pointer, size_t to, size_t from) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:517
size_t nbytes() const
Currently used number of bytes.
Definition GrowableBuffer.h:440
void concatenate(PRIMITIVE *external_pointer) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:492
PRIMITIVE & append_and_get_ref(PRIMITIVE datum)
Like append, but the type signature returns the reference to PRIMITIVE.
Definition GrowableBuffer.h:484
size_t length() const
Currently used number of elements.
Definition GrowableBuffer.h:408
void append(PRIMITIVE datum)
Inserts one datum into the panel, possibly triggering allocation of a new panel.
Definition GrowableBuffer.h:450
void clear()
Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.
Definition GrowableBuffer.h:421
Builds a BitMaskedArray in which mask values are packed into a bitmap.
Definition LayoutBuilder.h:2151
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:2204
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2287
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2211
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2245
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:2234
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:2370
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2266
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2272
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2198
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2297
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:2359
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2278
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2304
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:2178
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:2220
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:2321
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2257
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:2346
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:2155
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:2333
Functor for setting the ids of all nodes in a layout tree.
Definition LayoutBuilder.h:27
BuilderSetId(size_t &id)
Definition LayoutBuilder.h:29
void operator()(CONTENT &content)
Definition LayoutBuilder.h:32
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1926
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1955
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2026
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1985
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1974
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:2100
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2005
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1930
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2011
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1949
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1941
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2033
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:2091
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2017
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2039
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1963
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:2056
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1996
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:2079
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:2068
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:432
void clear() noexcept
Definition LayoutBuilder.h:444
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:454
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:478
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:463
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:466
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:435
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:441
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:448
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:459
void to_char_buffers(std::map< std::string, uint8_t * > &) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:473
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:48
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:54
BUILDER Builder
Definition LayoutBuilder.h:50
const std::size_t index
The index of a Record field.
Definition LayoutBuilder.h:59
Builder builder
The content type of field in a Record.
Definition LayoutBuilder.h:61
Builds an IndexedOptionArray which consists of an index buffer. The negative values in the index are ...
Definition LayoutBuilder.h:1563
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1672
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1643
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:1620
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:1747
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1651
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1657
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1581
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1591
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:1606
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1680
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:1738
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1663
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1686
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1567
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1598
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:1703
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1635
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:1726
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:1715
Builds an IndexedArray which consists of an index buffer.
Definition LayoutBuilder.h:1349
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1439
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:1519
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1366
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1418
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1353
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1382
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1424
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1375
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:1404
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1447
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:1510
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1430
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1462
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:1454
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:1498
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:1487
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:1389
Builds a ListOffsetArray which describes unequal-length lists (often called a "jagged" or "ragged" ar...
Definition LayoutBuilder.h:236
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:301
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:268
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:240
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:377
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:281
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:287
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:262
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:309
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:368
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:293
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:315
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:275
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:332
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:356
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:253
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:345
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:71
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:128
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:140
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:87
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:109
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:115
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:134
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:177
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:95
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
Definition LayoutBuilder.h:75
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:121
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the name and size (in bytes) of the buffer.
Definition LayoutBuilder.h:146
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:103
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:166
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a user-defined pointer.
Definition LayoutBuilder.h:157
std::string form() const
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:185
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:637
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:640
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:645
Clears the builder contents.
Definition LayoutBuilder.h:586
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:589
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:749
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:752
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:757
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:692
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:695
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:700
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:666
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:674
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:669
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:722
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:725
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:730
Builds a RecordArray which represents an array of records, which can be of same or different types....
Definition LayoutBuilder.h:499
void clear() noexcept
Definition LayoutBuilder.h:595
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:508
MAP UserDefinedMap
Definition LayoutBuilder.h:502
std::string form() const noexcept
Definition LayoutBuilder.h:776
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:553
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:505
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:520
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:559
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:501
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:565
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:603
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:739
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:570
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:609
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:654
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:546
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:710
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:529
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:683
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:802
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:1194
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1243
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:1211
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:1308
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1223
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1229
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1204
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1250
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:1301
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1235
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1256
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:1217
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:1273
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:1292
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:1197
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:1284
Helper for building an array of strings with a similar API as a Numpy builder.
Definition LayoutBuilder.h:412
void append(const std::string &value)
Definition LayoutBuilder.h:419
String()
Definition LayoutBuilder.h:414
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:969
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:972
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:977
Clears the builder contents.
Definition LayoutBuilder.h:916
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:920
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1098
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:1101
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1106
Assigns a unique ID to each node.
Definition LayoutBuilder.h:887
SetIdFunctor(size_t &id)
Definition LayoutBuilder.h:890
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:894
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:1027
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:1030
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1035
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:999
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1007
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:1002
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1057
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:1060
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1065
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:854
void clear() noexcept
Definition LayoutBuilder.h:925
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:1148
std::string form() const noexcept
Definition LayoutBuilder.h:1126
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:862
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:876
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:882
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:934
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:1074
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:870
void set_id(size_t &id) noexcept
Definition LayoutBuilder.h:903
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:940
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:986
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:1045
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:1016
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2625
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:2628
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2633
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2564
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2568
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2780
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:2783
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2788
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2534
SetIdFunctor(size_t &id)
Definition LayoutBuilder.h:2537
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2541
Copies and concatenates the accumulated data in the builder buffers to user-defined pointers if the g...
Definition LayoutBuilder.h:2702
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:2705
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2710
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2663
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2671
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:2666
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2743
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:2746
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2751
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:2465
void clear() noexcept
Definition LayoutBuilder.h:2574
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:2489
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2467
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2470
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:2509
std::string form() const noexcept
Definition LayoutBuilder.h:2808
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2523
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2529
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2590
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:2760
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2474
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2501
void set_id(size_t &id) noexcept
Definition LayoutBuilder.h:2550
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2596
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:2642
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:2720
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:2680
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1795
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1831
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1798
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:1885
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1811
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1817
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1805
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1837
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:1878
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1823
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1843
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:1850
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:1869
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:1861
Definition ArrayBuilder.h:14
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:263
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20
Definition utils.h:168
std::map< std::size_t, std::string > UserDefinedMap
Definition test_1494-layout-builder.cpp:39