File indexing completed on 2025-09-16 09:03:15
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/Collection.hh"
0011 #include "corecel/data/CollectionBuilder.hh"
0012 #include "corecel/data/DedupeCollectionBuilder.hh"
0013
0014 #include "../OrangeData.hh"
0015 #include "../transform/VariantTransform.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022
0023
0024
0025
0026
0027
0028 class TransformRecordInserter
0029 {
0030 public:
0031
0032
0033 template<class T>
0034 using Items = Collection<T, Ownership::value, MemSpace::host>;
0035
0036
0037 public:
0038
0039 inline TransformRecordInserter(Items<TransformRecord>* transforms,
0040 Items<real_type>* reals);
0041
0042
0043 inline TransformId operator()(VariantTransform const& tr);
0044
0045
0046 template<class T>
0047 inline TransformId operator()(T const& tr);
0048
0049 private:
0050 TransformId null_transform_;
0051 CollectionBuilder<TransformRecord> transforms_;
0052 DedupeCollectionBuilder<real_type> reals_;
0053 };
0054
0055
0056
0057
0058
0059
0060
0061 TransformRecordInserter::TransformRecordInserter(
0062 Items<TransformRecord>* transforms, Items<real_type>* reals)
0063 : transforms_{transforms}, reals_{reals}
0064 {
0065 CELER_EXPECT(transforms && reals);
0066 }
0067
0068
0069
0070
0071
0072 TransformId TransformRecordInserter::operator()(VariantTransform const& tr)
0073 {
0074 CELER_ASSUME(!tr.valueless_by_exception());
0075 return std::visit(*this, tr);
0076 }
0077
0078
0079
0080
0081
0082 template<class T>
0083 TransformId TransformRecordInserter::operator()(T const& tr)
0084 {
0085
0086
0087
0088
0089 if constexpr (std::is_same_v<T, NoTransformation>)
0090 {
0091
0092 if (null_transform_)
0093 {
0094 return null_transform_;
0095 }
0096
0097 null_transform_ = transforms_.size_id();
0098 }
0099
0100 TransformRecord record;
0101 record.type = tr.transform_type();
0102 auto data = tr.data();
0103 record.data_offset = *reals_.insert_back(data.begin(), data.end()).begin();
0104
0105 CELER_ASSERT(record);
0106 return transforms_.push_back(record);
0107 }
0108
0109
0110 }
0111 }