Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 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,12 @@ RecordComponent::storeChunk( Offset offset, Extent extent )
std::move( extent ),
[]( size_t size )
{
#if defined(__clang_major__) && __clang_major__ < 7
return std::shared_ptr< T >{
new T[ size ], []( auto * ptr ) { delete[] ptr; } };
#else
return std::shared_ptr< T[] >{ new T[ size ] };
#endif
} );
}
}