File indexing completed on 2025-01-30 10:03:41
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/OpaqueId.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/sys/ThreadId.hh"
0014
0015 namespace celeritas
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 template<template<Ownership, MemSpace> class S, MemSpace M>
0042 class CollectionStateStore
0043 {
0044 public:
0045
0046
0047 using Value = S<Ownership::value, M>;
0048 using Ref = S<Ownership::reference, M>;
0049 using size_type = TrackSlotId::size_type;
0050
0051
0052 public:
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(size_type size);
0067
0068
0069 explicit inline CollectionStateStore(S<Ownership::value, M>&& other);
0070
0071
0072 template<Ownership W2, MemSpace M2>
0073 explicit inline CollectionStateStore(S<W2, M2> const& other);
0074
0075
0076 template<Ownership W2, MemSpace M2>
0077 inline CollectionStateStore& operator=(S<W2, M2> const& other);
0078
0079
0080 CELER_DEFAULT_MOVE_DELETE_COPY(CollectionStateStore);
0081
0082
0083 explicit operator bool() const { return static_cast<bool>(val_); }
0084
0085
0086 size_type size() const { return val_.size(); }
0087
0088
0089 inline Ref& ref();
0090
0091
0092 inline Ref const& ref() const;
0093
0094 private:
0095 Value val_;
0096 Ref ref_;
0097
0098 template<template<Ownership, MemSpace> class S2, MemSpace M2>
0099 friend class CollectionStateStore;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108
0109 template<template<Ownership, MemSpace> class S, MemSpace M>
0110 template<template<Ownership, MemSpace> class P>
0111 CollectionStateStore<S, M>::CollectionStateStore(HostCRef<P> const& p,
0112 StreamId sid,
0113 size_type size)
0114 {
0115 CELER_EXPECT(sid);
0116 CELER_EXPECT(size > 0);
0117 resize(&val_, p, sid, size);
0118 CELER_ASSERT(val_);
0119
0120
0121 ref_ = val_;
0122 }
0123
0124
0125
0126
0127
0128
0129
0130
0131 template<template<Ownership, MemSpace> class S, MemSpace M>
0132 template<template<Ownership, MemSpace> class P>
0133 CollectionStateStore<S, M>::CollectionStateStore(HostCRef<P> const& p,
0134 size_type size)
0135 {
0136 CELER_EXPECT(size > 0);
0137 resize(&val_, p, size);
0138 CELER_ASSERT(val_);
0139
0140
0141 ref_ = val_;
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151 template<template<Ownership, MemSpace> class S, MemSpace M>
0152 CollectionStateStore<S, M>::CollectionStateStore(size_type size)
0153 {
0154 CELER_EXPECT(size > 0);
0155 resize(&val_, size);
0156 CELER_ASSERT(val_);
0157
0158
0159 ref_ = val_;
0160 }
0161
0162
0163
0164
0165
0166 template<template<Ownership, MemSpace> class S, MemSpace M>
0167 CollectionStateStore<S, M>::CollectionStateStore(S<Ownership::value, M>&& other)
0168 : val_(std::move(other))
0169 {
0170 CELER_EXPECT(val_);
0171
0172 ref_ = val_;
0173 }
0174
0175
0176
0177
0178
0179 template<template<Ownership, MemSpace> class S, MemSpace M>
0180 template<Ownership W2, MemSpace M2>
0181 CollectionStateStore<S, M>::CollectionStateStore(S<W2, M2> const& other)
0182 {
0183 CELER_EXPECT(other);
0184
0185
0186 val_ = const_cast<S<W2, M2>&>(other);
0187 CELER_ASSERT(val_);
0188
0189 ref_ = val_;
0190 }
0191
0192
0193
0194
0195
0196 template<template<Ownership, MemSpace> class S, MemSpace M>
0197 template<Ownership W2, MemSpace M2>
0198 auto CollectionStateStore<S, M>::operator=(S<W2, M2> const& other)
0199 -> CollectionStateStore<S, M>&
0200 {
0201 CELER_EXPECT(other);
0202
0203 val_ = const_cast<S<W2, M2>&>(other);
0204 CELER_ASSERT(val_);
0205
0206 ref_ = val_;
0207 return *this;
0208 }
0209
0210
0211
0212
0213
0214 template<template<Ownership, MemSpace> class S, MemSpace M>
0215 auto CollectionStateStore<S, M>::ref() -> Ref&
0216 {
0217 CELER_EXPECT(*this);
0218 return ref_;
0219 }
0220
0221
0222
0223
0224
0225 template<template<Ownership, MemSpace> class S, MemSpace M>
0226 auto CollectionStateStore<S, M>::ref() const -> Ref const&
0227 {
0228 CELER_EXPECT(*this);
0229 return ref_;
0230 }
0231
0232
0233 }