Skip to content

Commit

Permalink
Add storeChunk(shared_ptr<T[]>, ...) overload
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 28, 2022
1 parent d64365b commit 4f30f34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ class RecordComponent : public BaseRecordComponent
template <typename T>
void storeChunk(std::shared_ptr<T>, Offset, Extent);

template <typename T>
void storeChunk(std::shared_ptr<T[]>, Offset, Extent);

template <typename T_ContiguousContainer>
typename std::enable_if<
traits::IsContiguousContainer<T_ContiguousContainer>::value>::type
Expand Down
15 changes: 13 additions & 2 deletions include/openPMD/RecordComponent.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ RecordComponent::storeChunk(std::shared_ptr<T> data, Offset o, Extent e)
rc.m_chunks.push(IOTask(this, dWrite));
}

template <typename T>
inline void
RecordComponent::storeChunk(std::shared_ptr<T[]> data, Offset o, Extent e)
{
storeChunk(
std::static_pointer_cast<T>(std::move(data)),
std::move(o),
std::move(e));
}

template< typename T_ContiguousContainer >
inline typename std::enable_if<
traits::IsContiguousContainer< T_ContiguousContainer >::value
Expand Down Expand Up @@ -310,6 +320,8 @@ RecordComponent::storeChunk( Offset o, Extent e, F && createBuffer )
auto &out = *getBufferView.out;
if (!out.backendManagedBuffer)
{
// note that data might have either
// type shared_ptr<T> or shared_ptr<T[]>
auto data = std::forward<F>(createBuffer)(size);
out.ptr = static_cast<void *>(data.get());
storeChunk(std::move(data), std::move(o), std::move(e));
Expand All @@ -326,8 +338,7 @@ RecordComponent::storeChunk( Offset offset, Extent extent )
std::move( extent ),
[]( size_t size )
{
return std::shared_ptr< T >{
new T[ size ], []( auto * ptr ) { delete[] ptr; } };
return std::shared_ptr< T[] >{ new T[ size ] };
} );
}
}

0 comments on commit 4f30f34

Please sign in to comment.