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