File indexing completed on 2025-09-15 08:55:04
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011
0012 #include "Collection.hh"
0013 #include "CollectionAlgorithms.hh"
0014 #include "CollectionBuilder.hh"
0015
0016 namespace celeritas
0017 {
0018
0019
0020
0021
0022 template<class T, Ownership W, MemSpace M>
0023 struct StackAllocatorData
0024 {
0025 celeritas::Collection<T, W, M> storage;
0026 celeritas::Collection<size_type, W, M> size;
0027
0028
0029 explicit CELER_FUNCTION operator bool() const
0030 {
0031 return !storage.empty() && !size.empty();
0032 }
0033
0034
0035 CELER_FUNCTION size_type capacity() const { return storage.size(); }
0036
0037
0038 template<Ownership W2, MemSpace M2>
0039 StackAllocatorData& operator=(StackAllocatorData<T, W2, M2>& other)
0040 {
0041 CELER_EXPECT(other);
0042 storage = other.storage;
0043 size = other.size;
0044 return *this;
0045 }
0046 };
0047
0048
0049
0050
0051
0052 template<class T, MemSpace M>
0053 inline void
0054 resize(StackAllocatorData<T, Ownership::value, M>* data, size_type capacity)
0055 {
0056 CELER_EXPECT(capacity > 0);
0057 resize(&data->storage, capacity);
0058 resize(&data->size, 1);
0059 celeritas::fill(size_type(0), &data->size);
0060 }
0061
0062
0063 }