File indexing completed on 2026-09-19 09:17:25
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 template<template<Ownership, MemSpace> class S, MemSpace M>
0041 class CollectionStateStore
0042 {
0043 public:
0044
0045
0046 using Value = S<Ownership::value, M>;
0047 using Ref = S<Ownership::reference, M>;
0048 using size_type = TrackSlotId::size_type;
0049
0050
0051 public:
0052 CollectionStateStore() = default;
0053 ~CollectionStateStore() = default;
0054
0055
0056 template<template<Ownership, MemSpace> class P>
0057 inline CollectionStateStore(HostCRef<P> const& p,
0058 StreamId stream_id,
0059 size_type size);
0060
0061
0062 template<template<Ownership, MemSpace> class P>
0063 inline CollectionStateStore(HostCRef<P> const& p, size_type size);
0064
0065
0066 explicit inline CollectionStateStore(StreamId stream_id, size_type size);
0067
0068
0069 explicit inline CollectionStateStore(size_type size);
0070
0071
0072 explicit inline CollectionStateStore(S<Ownership::value, M>&& other);
0073
0074
0075 template<Ownership W2, MemSpace M2>
0076 explicit inline CollectionStateStore(S<W2, M2> const& other);
0077
0078
0079 template<Ownership W2, MemSpace M2>
0080 inline CollectionStateStore& operator=(S<W2, M2> const& other);
0081
0082
0083 CELER_DEFAULT_MOVE_DELETE_COPY(CollectionStateStore);
0084
0085
0086 explicit operator bool() const { return static_cast<bool>(val_); }
0087
0088
0089 size_type size() const { return val_.size(); }
0090
0091
0092 inline Ref& ref();
0093
0094
0095 inline Ref const& ref() const;
0096
0097 private:
0098 Value val_;
0099 Ref ref_;
0100
0101 template<template<Ownership, MemSpace> class S2, MemSpace M2>
0102 friend class CollectionStateStore;
0103 };
0104
0105
0106
0107
0108
0109
0110
0111
0112 template<template<Ownership, MemSpace> class S, MemSpace M>
0113 template<template<Ownership, MemSpace> class P>
0114 CollectionStateStore<S, M>::CollectionStateStore(HostCRef<P> const& p,
0115 StreamId sid,
0116 size_type size)
0117 {
0118 CELER_EXPECT(sid);
0119 CELER_EXPECT(size > 0);
0120 resize(&val_, p, sid, size);
0121 CELER_ASSERT(val_);
0122
0123
0124 ref_ = val_;
0125 }
0126
0127
0128
0129
0130
0131
0132
0133
0134 template<template<Ownership, MemSpace> class S, MemSpace M>
0135 template<template<Ownership, MemSpace> class P>
0136 CollectionStateStore<S, M>::CollectionStateStore(HostCRef<P> const& p,
0137 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 CollectionStateStore<S, M>::CollectionStateStore(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 CollectionStateStore<S, M>::CollectionStateStore(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 CollectionStateStore<S, M>::CollectionStateStore(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 CollectionStateStore<S, M>::CollectionStateStore(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 CollectionStateStore<S, M>::operator=(S<W2, M2> const& other)
0220 -> CollectionStateStore<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 CollectionStateStore<S, M>::ref() -> Ref&
0237 {
0238 CELER_EXPECT(*this);
0239 return ref_;
0240 }
0241
0242
0243
0244
0245
0246 template<template<Ownership, MemSpace> class S, MemSpace M>
0247 auto CollectionStateStore<S, M>::ref() const -> Ref const&
0248 {
0249 CELER_EXPECT(*this);
0250 return ref_;
0251 }
0252
0253
0254 }