@@ -123,22 +123,84 @@ namespace core
123123 return *m_extent;
124124 }
125125
126+ auto ConfigureLoadStore::withSharedPtr_impl_mut (
127+ std::shared_ptr<void > data, Datatype datatype)
128+ -> openPMD::ConfigureLoadStoreFromBuffer
129+ {
130+ if (!data)
131+ {
132+ throw std::runtime_error (
133+ " Unallocated pointer passed during chunk store." );
134+ }
135+ return openPMD::ConfigureLoadStoreFromBuffer (
136+ auxiliary::WriteBuffer (std::move (data)),
137+ datatype,
138+ {std::move (*this )});
139+ }
140+ auto ConfigureLoadStore::withSharedPtr_impl_const (
141+ std::shared_ptr<void const > data, Datatype datatype)
142+ -> openPMD::ConfigureStoreChunkFromBuffer
143+ {
144+ if (!data)
145+ {
146+ throw std::runtime_error (
147+ " Unallocated pointer passed during chunk store." );
148+ }
149+ return openPMD::ConfigureStoreChunkFromBuffer (
150+ auxiliary::WriteBuffer (std::move (data)),
151+ datatype,
152+ {std::move (*this )});
153+ }
154+
126155 template <typename T>
127156 auto ConfigureLoadStore::withSharedPtr (std::shared_ptr<T> data)
128157 -> shared_ptr_return_type<T>
129158 {
130159 using T_decayed = std::remove_cv_t <std::remove_extent_t <T>>;
160+ constexpr auto dtype = determineDatatype<T_decayed>();
161+ if constexpr (std::is_const_v<T>)
162+ {
163+ return withSharedPtr_impl_const (data, dtype);
164+ }
165+ else
166+ {
167+ return withSharedPtr_impl_mut (data, dtype);
168+ }
169+ }
170+
171+ auto ConfigureLoadStore::withUniquePtr_impl_mut (
172+ UniquePtrWithLambda<void > data, Datatype dtype)
173+ -> openPMD::ConfigureStoreChunkFromBuffer
174+
175+ {
176+ if (!data)
177+ {
178+ throw std::runtime_error (
179+ " Unallocated pointer passed during chunk store." );
180+ }
181+
182+ return openPMD::ConfigureStoreChunkFromBuffer (
183+ auxiliary::WriteBuffer (std::move (data)), dtype, {std::move (*this )});
184+ }
185+ auto ConfigureLoadStore::withUniquePtr_impl_const (
186+ UniquePtrWithLambda<void const > data, Datatype dtype)
187+ -> openPMD::ConfigureStoreChunkFromBuffer
188+
189+ {
131190 if (!data)
132191 {
133192 throw std::runtime_error (
134193 " Unallocated pointer passed during chunk store." );
135194 }
136- return shared_ptr_return_type<T>(
195+
196+ void const *raw_ptr = data.get ();
197+ return openPMD::ConfigureStoreChunkFromBuffer (
137198 auxiliary::WriteBuffer (
138- std::static_pointer_cast<
139- std::conditional_t <std::is_const_v<T>, void const , void >>(
140- std::move (data))),
141- determineDatatype<T_decayed>(),
199+ std::shared_ptr<void const >(
200+ raw_ptr,
201+ [data_lambda =
202+ std::move (data)](auto const *) { /* no-op */ })),
203+ dtype,
142204 {std::move (*this )});
143205 }
144206 template <typename T>
@@ -147,50 +209,63 @@ namespace core
147209
148210 {
149211 using T_decayed = std::remove_cv_t <std::remove_extent_t <T>>;
150- if (!data)
151- {
152- throw std::runtime_error (
153- " Unallocated pointer passed during chunk store." );
154- }
212+ constexpr auto dtype = determineDatatype<T_decayed>();
155213 if constexpr (std::is_const_v<T>)
156214 {
157- void const *raw_ptr = data.get ();
158- return unique_ptr_return_type<T>(
159- auxiliary::WriteBuffer (
160- std::shared_ptr<void const >(
161- raw_ptr,
162- [data_lambda =
163- std::move (data)](auto const *) { /* no-op */ })),
164- determineDatatype<T_decayed>(),
165- {std::move (*this )});
215+ return withUniquePtr_impl_const (
216+ std::move (data).template static_cast_ <void const >(), dtype);
166217 }
167218 else
168219 {
169- return unique_ptr_return_type<T>(
170- auxiliary::WriteBuffer (
171- std::move (data).template static_cast_ <void >()),
172- determineDatatype<T_decayed>(),
173- {std::move (*this )});
220+ return withUniquePtr_impl_mut (
221+ std::move (data).template static_cast_ <void >(), dtype);
174222 }
175223 }
176- template <typename T>
177- auto ConfigureLoadStore::withRawPtr (T *data) -> shared_ptr_return_type<T>
224+
225+ auto ConfigureLoadStore::withRawPtr_impl_mut (void *data, Datatype dtype)
226+ -> openPMD::ConfigureLoadStoreFromBuffer
178227 {
179- using T_decayed = std::remove_cv_t <std::remove_extent_t <T>>;
180228 if (!data)
181229 {
182230 throw std::runtime_error (
183231 " Unallocated pointer passed during chunk store." );
184232 }
185- return shared_ptr_return_type<T>(
186- auxiliary::WriteBuffer (
187- std::static_pointer_cast<
188- std::conditional_t <std::is_const_v<T>, void const , void >>(
189- auxiliary::shareRaw (data))),
190- determineDatatype<T_decayed>(),
233+ return openPMD::ConfigureLoadStoreFromBuffer (
234+ auxiliary::WriteBuffer (auxiliary::shareRaw (data)),
235+ dtype,
236+ {std::move (*this )});
237+ }
238+
239+ auto
240+ ConfigureLoadStore::withRawPtr_impl_const (void const *data, Datatype dtype)
241+ -> openPMD::ConfigureStoreChunkFromBuffer
242+ {
243+ if (!data)
244+ {
245+ throw std::runtime_error (
246+ " Unallocated pointer passed during chunk store." );
247+ }
248+ return openPMD::ConfigureStoreChunkFromBuffer (
249+ auxiliary::WriteBuffer (auxiliary::shareRaw (data)),
250+ dtype,
191251 {std::move (*this )});
192252 }
193253
254+ template <typename T>
255+ auto ConfigureLoadStore::withRawPtr (T *data) -> shared_ptr_return_type<T>
256+ {
257+ using T_decayed = std::remove_cv_t <std::remove_extent_t <T>>;
258+ constexpr auto dtype = determineDatatype<T_decayed>();
259+ if constexpr (std::is_const_v<T>)
260+ {
261+ return withRawPtr_impl_const (data, dtype);
262+ }
263+ else
264+ {
265+ return withRawPtr_impl_mut (data, dtype);
266+ }
267+ }
268+
194269 template <typename T>
195270 auto ConfigureLoadStore::enqueueStore () -> DynamicMemoryView<T>
196271 {
0 commit comments