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