File indexing completed on 2026-10-26 09:34:34
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/OpaqueId.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/sys/ThreadId.hh"
0013
0014 namespace celeritas
0015 {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template<template<Ownership, MemSpace> class S, MemSpace M>
0043 class StateDataStore
0044 {
0045 public:
0046
0047
0048 using Value = S<Ownership::value, M>;
0049 using Ref = S<Ownership::reference, M>;
0050 using size_type = TrackSlotId::size_type;
0051
0052
0053 public:
0054
0055 StateDataStore() = default;
0056 ~StateDataStore() = default;
0057
0058
0059 template<template<Ownership, MemSpace> class P>
0060 inline StateDataStore(
0061 HostCRef<P> const& p, StreamId stream_id, size_type size);
0062
0063
0064 template<template<Ownership, MemSpace> class P>
0065 inline StateDataStore(HostCRef<P> const& p, size_type size);
0066
0067
0068 explicit inline StateDataStore(StreamId stream_id, size_type size);
0069
0070
0071 explicit inline StateDataStore(size_type size);
0072
0073
0074 explicit inline StateDataStore(S<Ownership::value, M>&& other);
0075
0076
0077 template<Ownership W2, MemSpace M2>
0078 explicit inline StateDataStore(S<W2, M2> const& other);
0079
0080
0081 template<Ownership W2, MemSpace M2>
0082 inline StateDataStore& operator=(S<W2, M2> const& other);
0083
0084
0085 CELER_DEFAULT_MOVE_DELETE_COPY(StateDataStore);
0086
0087
0088 explicit operator bool() const { return static_cast<bool>(val_); }
0089
0090
0091 size_type size() const { return val_.size(); }
0092
0093
0094 inline Ref& ref();
0095
0096
0097 inline Ref const& ref() const;
0098
0099 private:
0100 Value val_;
0101 Ref ref_;
0102
0103 template<template<Ownership, MemSpace> class S2, MemSpace M2>
0104 friend class StateDataStore;
0105 };
0106
0107
0108
0109
0110
0111
0112
0113
0114 template<template<Ownership, MemSpace> class S, MemSpace M>
0115 template<template<Ownership, MemSpace> class P>
0116 StateDataStore<S, M>::StateDataStore(
0117 HostCRef<P> const& p, StreamId sid, size_type size)
0118 {
0119 CELER_EXPECT(sid);
0120 CELER_EXPECT(size > 0);
0121 resize(&val_, p, sid, size);
0122 CELER_ASSERT(val_);
0123
0124
0125 ref_ = val_;
0126 }
0127
0128
0129
0130
0131
0132
0133
0134
0135 template<template<Ownership, MemSpace> class S, MemSpace M>
0136 template<template<Ownership, MemSpace> class P>
0137 StateDataStore<S, M>::StateDataStore(HostCRef<P> const& p, size_type size)
0138 {
0139 CELER_EXPECT(size > 0);
0140 resize(&val_, p, size);
0141 CELER_ASSERT(val_);
0142
0143
0144 ref_ = val_;
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154 template<template<Ownership, MemSpace> class S, MemSpace M>
0155 StateDataStore<S, M>::StateDataStore(StreamId sid, size_type size)
0156 {
0157 CELER_EXPECT(size > 0);
0158 resize(&val_, sid, size);
0159 CELER_ASSERT(val_);
0160
0161
0162 ref_ = val_;
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172 template<template<Ownership, MemSpace> class S, MemSpace M>
0173 StateDataStore<S, M>::StateDataStore(size_type size)
0174 {
0175 CELER_EXPECT(size > 0);
0176 resize(&val_, size);
0177 CELER_ASSERT(val_);
0178
0179
0180 ref_ = val_;
0181 }
0182
0183
0184
0185
0186
0187 template<template<Ownership, MemSpace> class S, MemSpace M>
0188 StateDataStore<S, M>::StateDataStore(S<Ownership::value, M>&& other)
0189 : val_(std::move(other))
0190 {
0191 CELER_EXPECT(val_);
0192
0193 ref_ = val_;
0194 }
0195
0196
0197
0198
0199
0200 template<template<Ownership, MemSpace> class S, MemSpace M>
0201 template<Ownership W2, MemSpace M2>
0202 StateDataStore<S, M>::StateDataStore(S<W2, M2> const& other)
0203 {
0204 CELER_EXPECT(other);
0205
0206
0207 val_ = const_cast<S<W2, M2>&>(other);
0208 CELER_ASSERT(val_);
0209
0210 ref_ = val_;
0211 }
0212
0213
0214
0215
0216
0217 template<template<Ownership, MemSpace> class S, MemSpace M>
0218 template<Ownership W2, MemSpace M2>
0219 auto StateDataStore<S, M>::operator=(S<W2, M2> const& other)
0220 -> StateDataStore<S, M>&
0221 {
0222 CELER_EXPECT(other);
0223
0224 val_ = const_cast<S<W2, M2>&>(other);
0225 CELER_ASSERT(val_);
0226
0227 ref_ = val_;
0228 return *this;
0229 }
0230
0231
0232
0233
0234
0235 template<template<Ownership, MemSpace> class S, MemSpace M>
0236 auto StateDataStore<S, M>::ref() -> Ref&
0237 {
0238 return ref_;
0239 }
0240
0241
0242
0243
0244
0245 template<template<Ownership, MemSpace> class S, MemSpace M>
0246 auto StateDataStore<S, M>::ref() const -> Ref const&
0247 {
0248 return ref_;
0249 }
0250
0251
0252 }