Skip to content

Commit 80a3179

Browse files
storeChunk: use const-type pointers (#1778)
* Use const-type pointers * Use const in some pointer type conversions
1 parent d197e23 commit 80a3179

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

include/openPMD/RecordComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class RecordComponent : public BaseRecordComponent
388388
* @param extent Extent within the dataset, counted from the offset.
389389
*/
390390
template <typename T>
391-
void storeChunkRaw(T *data, Offset offset, Extent extent);
391+
void storeChunkRaw(T const *data, Offset offset, Extent extent);
392392

393393
/** Store a chunk of data from a contiguous container.
394394
*

include/openPMD/auxiliary/ShareRawInternal.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ std::shared_ptr<T const> shareRaw(T const *x)
6161
}
6262

6363
template <typename T>
64-
auto shareRaw(T &c)
65-
-> std::shared_ptr<typename std::remove_pointer<decltype(c.data())>::type>
64+
auto shareRaw(T &c) -> std::shared_ptr<typename T::value_type>
6665
{
6766
using value_type = typename std::remove_pointer<decltype(c.data())>::type;
6867
return std::shared_ptr<value_type>(c.data(), [](value_type *) {});
6968
}
7069

7170
template <typename T>
72-
auto shareRaw(T const &c)
73-
-> std::shared_ptr<typename std::remove_pointer<decltype(c.data())>::type>
71+
auto shareRaw(T const &c) -> std::shared_ptr<typename T::value_type>
7472
{
7573
using value_type = typename std::remove_pointer<decltype(c.data())>::type;
7674
return std::shared_ptr<value_type>(c.data(), [](value_type *) {});

src/RecordComponent.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,13 @@ template <typename T>
820820
void RecordComponent::storeChunk(std::shared_ptr<T[]> data, Offset o, Extent e)
821821
{
822822
storeChunk(
823-
std::static_pointer_cast<T>(std::move(data)),
823+
std::static_pointer_cast<T const>(std::move(data)),
824824
std::move(o),
825825
std::move(e));
826826
}
827827

828828
template <typename T>
829-
void RecordComponent::storeChunkRaw(T *ptr, Offset offset, Extent extent)
829+
void RecordComponent::storeChunkRaw(T const *ptr, Offset offset, Extent extent)
830830
{
831831
storeChunk(auxiliary::shareRaw(ptr), std::move(offset), std::move(extent));
832832
}
@@ -864,15 +864,15 @@ void RecordComponent::verifyChunk(Offset const &o, Extent const &e) const
864864
template void RecordComponent::verifyChunk<type>( \
865865
Offset const &o, Extent const &e) const; \
866866
template DynamicMemoryView<type> RecordComponent::storeChunk<type>( \
867-
Offset offset, Extent extent);
867+
Offset offset, Extent extent); \
868+
template void RecordComponent::storeChunkRaw<type>( \
869+
OPENPMD_PTR(type const) ptr, Offset offset, Extent extent);
868870

869871
#define OPENPMD_INSTANTIATE_CONST_AND_NONCONST(type) \
870872
template void RecordComponent::storeChunk<type>( \
871873
std::shared_ptr<type> data, Offset o, Extent e); \
872874
template void RecordComponent::storeChunk<type>( \
873-
std::shared_ptr<OPENPMD_ARRAY(type)> data, Offset o, Extent e); \
874-
template void RecordComponent::storeChunkRaw<type>( \
875-
OPENPMD_PTR(type) ptr, Offset offset, Extent extent);
875+
std::shared_ptr<OPENPMD_ARRAY(type)> data, Offset o, Extent e);
876876

877877
#define OPENPMD_INSTANTIATE_WITH_AND_WITHOUT_EXTENT(type) \
878878
template std::shared_ptr<type> RecordComponent::loadChunk<type>( \

0 commit comments

Comments
 (0)