11#pragma once
22
33#include " openPMD/Dataset.hpp"
4+ #include " openPMD/auxiliary/ShareRawInternal.hpp"
45#include " openPMD/auxiliary/UniquePtr.hpp"
56
67#include < optional>
@@ -34,19 +35,27 @@ namespace internal
3435 Extent extent;
3536 std::optional<MemorySelection> memorySelection;
3637 };
38+
39+ struct ConfigureStoreChunkData
40+ {
41+ ConfigureStoreChunkData (RecordComponent &);
42+
43+ RecordComponent &m_rc;
44+ std::optional<Offset> m_offset;
45+ std::optional<Extent> m_extent;
46+ };
3747} // namespace internal
3848
3949template <typename ChildClass = void >
40- class ConfigureStoreChunk
50+ class ConfigureStoreChunk : protected internal ::ConfigureStoreChunkData
4151{
4252 friend class RecordComponent ;
53+ template <typename >
54+ friend class ConfigureStoreChunk ;
4355
44- private:
45- RecordComponent &m_rc;
46- std::optional<Offset> m_offset;
47- std::optional<Extent> m_extent;
48-
56+ protected:
4957 ConfigureStoreChunk (RecordComponent &rc);
58+ ConfigureStoreChunk (ConfigureStoreChunkData &&);
5059
5160 auto dim () const -> uint8_t;
5261 auto getOffset () const -> Offset;
@@ -58,23 +67,29 @@ class ConfigureStoreChunk
5867 std::is_void_v<ChildClass>,
5968 /* then*/ ConfigureStoreChunk<void >,
6069 /* else*/ ChildClass>;
70+ template <typename T>
71+ using normalize_dataset_type =
72+ std::remove_cv_t <std::remove_extent_t <T>> const ;
6173
6274 auto offset (Offset) -> return_type &;
6375 auto extent (Extent) -> return_type &;
6476
77+ // @todo rvalue references..?
6578 template <typename T>
66- auto fromSharedPtr (
67- std::shared_ptr<T>) && -> TypedConfigureStoreChunk<std::shared_ptr<T >>;
79+ auto fromSharedPtr (std::shared_ptr<T>)
80+ -> TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T> >>;
6881 template <typename T>
6982 auto fromUniquePtr (UniquePtrWithLambda<T>)
70- && -> TypedConfigureStoreChunk<UniquePtrWithLambda<T>>;
83+ -> TypedConfigureStoreChunk<
84+ UniquePtrWithLambda<normalize_dataset_type<T>>>;
7185 template <typename T, typename Del>
7286 auto fromUniquePtr (std::unique_ptr<T, Del>)
73- && -> TypedConfigureStoreChunk<UniquePtrWithLambda<T>>;
87+ -> TypedConfigureStoreChunk<
88+ UniquePtrWithLambda<normalize_dataset_type<T>>>;
7489 template <typename T>
75- auto fromRawPtr (T *data) && -> TypedConfigureStoreChunk<std::shared_ptr<T>>;
90+ auto fromRawPtr (T *data) -> TypedConfigureStoreChunk<std::shared_ptr<T>>;
7691 template <typename T_ContiguousContainer>
77- auto fromContiguousContainer (T_ContiguousContainer &data) && ->
92+ auto fromContiguousContainer (T_ContiguousContainer &data) ->
7893 typename std::enable_if_t<
7994 auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
8095 TypedConfigureStoreChunk<
@@ -97,7 +112,8 @@ class TypedConfigureStoreChunk
97112 using parent_t = ConfigureStoreChunk<TypedConfigureStoreChunk<Ptr_Type>>;
98113
99114private:
100- friend class ConfigureStoreChunk <TypedConfigureStoreChunk<Ptr_Type>>;
115+ template <typename T>
116+ friend class ConfigureStoreChunk ;
101117
102118 Ptr_Type m_buffer;
103119 std::optional<MemorySelection> m_mem_select;
@@ -113,21 +129,64 @@ class TypedConfigureStoreChunk
113129 auto as_parent () & -> parent_t &;
114130 auto as_parent () const & -> parent_t const &;
115131
116- auto enqueue () & -> void;
132+ auto enqueue () -> void;
117133};
118134
135+ template <typename ChildClass>
136+ template <typename T>
137+ auto ConfigureStoreChunk<ChildClass>::fromSharedPtr(std::shared_ptr<T> data)
138+ -> TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T>>>
139+ {
140+ if (!data)
141+ {
142+ throw std::runtime_error (
143+ " Unallocated pointer passed during chunk store." );
144+ }
145+ return TypedConfigureStoreChunk<std::shared_ptr<normalize_dataset_type<T>>>(
146+ std::static_pointer_cast<normalize_dataset_type<T>>(std::move (data)),
147+ {std::move (*this )});
148+ }
149+ template <typename ChildClass>
150+ template <typename T>
151+ auto ConfigureStoreChunk<ChildClass>::fromUniquePtr(UniquePtrWithLambda<T> data)
152+ -> TypedConfigureStoreChunk<UniquePtrWithLambda<normalize_dataset_type<T>>>
153+ {
154+ if (!data)
155+ {
156+ throw std::runtime_error (
157+ " Unallocated pointer passed during chunk store." );
158+ }
159+ return TypedConfigureStoreChunk<
160+ UniquePtrWithLambda<normalize_dataset_type<T>>>(
161+ std::move (data).template static_cast_ <normalize_dataset_type<T>>(),
162+ {std::move (*this )});
163+ }
164+ template <typename ChildClass>
165+ template <typename T>
166+ auto ConfigureStoreChunk<ChildClass>::fromRawPtr(T *data)
167+ -> TypedConfigureStoreChunk<std::shared_ptr<T>>
168+ {
169+ if (!data)
170+ {
171+ throw std::runtime_error (
172+ " Unallocated pointer passed during chunk store." );
173+ }
174+ return TypedConfigureStoreChunk<std::shared_ptr<T>>(
175+ auxiliary::shareRaw (data), {std::move (*this )});
176+ }
177+
119178template <typename ChildClass>
120179template <typename T, typename Del>
121180auto ConfigureStoreChunk<ChildClass>::fromUniquePtr(
122181 std::unique_ptr<T, Del> data)
123- && -> TypedConfigureStoreChunk<UniquePtrWithLambda<T >>
182+ -> TypedConfigureStoreChunk<UniquePtrWithLambda<normalize_dataset_type<T> >>
124183{
125184 return fromUniquePtr (UniquePtrWithLambda<T>(std::move (data)));
126185}
127186template <typename ChildClass>
128187template <typename T_ContiguousContainer>
129188auto ConfigureStoreChunk<ChildClass>::fromContiguousContainer(
130- T_ContiguousContainer &data) && ->
189+ T_ContiguousContainer &data) ->
131190 typename std::enable_if_t <
132191 auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
133192 TypedConfigureStoreChunk<
0 commit comments