Skip to content

Commit

Permalink
Frontend support for unique pointers with const value types
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 25, 2024
1 parent 4d1e260 commit 332932f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 0 additions & 4 deletions include/openPMD/LoadStoreChunk.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ auto ConfigureLoadStore<ChildClass>::withUniquePtr(UniquePtrWithLambda<T> data)
-> unique_ptr_return_type<T>

{
// should we support them?
static_assert(
!std::is_const_v<T>,
"Unique pointers to const types not supported as storeChunk buffers.");
if (!data)
{
throw std::runtime_error(
Expand Down
24 changes: 24 additions & 0 deletions src/LoadStoreChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ namespace
return auxiliary::WriteBuffer(
std::move(ptr).template static_cast_<void>());
}

/*
* There is no backend support currently for const unique pointers.
* We support these mostly for providing a clean API to users that have such
* pointers and want to store from them, but there will be no
* backend-specific optimizations for such buffers as there are for
* non-const unique pointers.
*/
template <typename T>
auto
asWriteBuffer(UniquePtrWithLambda<T const> &&ptr) -> auxiliary::WriteBuffer

Check notice

Code scanning / CodeQL

Unused static function Note

Static function asWriteBuffer is unreachable
{
auto raw_ptr = ptr.get();
return asWriteBuffer(std::shared_ptr<T const>{
raw_ptr, [ptr_lambda = std::move(ptr)](auto const *) {}});
}
} // namespace

template <typename ChildClass>
Expand Down Expand Up @@ -272,6 +288,14 @@ OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_METHOD_TEMPLATES_FOR_BASE)
INSTANTIATE_METHOD_TEMPLATES( \
ConfigureLoadStore< \
ConfigureStoreChunkFromBuffer<std::shared_ptr<dtype const>>>, \
dtype) \
template class ConfigureStoreChunkFromBuffer< \
UniquePtrWithLambda<dtype const>>; \
template class ConfigureLoadStore< \
ConfigureStoreChunkFromBuffer<UniquePtrWithLambda<dtype const>>>; \
INSTANTIATE_METHOD_TEMPLATES( \
ConfigureLoadStore< \
ConfigureStoreChunkFromBuffer<UniquePtrWithLambda<dtype const>>>, \
dtype)
// clang-format on

Expand Down
6 changes: 5 additions & 1 deletion test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,11 @@ inline void constant_scalar(std::string const &file_ending)
new unsigned int[6], [](unsigned int const *p) { delete[] p; });
unsigned int e{0};
std::generate(E.get(), E.get() + 6, [&e] { return e++; });
E_y.storeChunk(std::move(E), {0, 0, 0}, {1, 2, 3});
// check that const-type unique pointers work in the builder pattern
E_y.prepareLoadStore()
.extent({1, 2, 3})
.withUniquePtr(std::move(E).static_cast_<unsigned int const>())
.enqueueStore();

// store a number of predefined attributes in E
Mesh &E_mesh = s.iterations[1].meshes["E"];
Expand Down

0 comments on commit 332932f

Please sign in to comment.