Skip to content

Commit 403f467

Browse files
committed
instantiate some more methods
1 parent 0acb367 commit 403f467

2 files changed

Lines changed: 86 additions & 69 deletions

File tree

include/openPMD/LoadStoreChunk.tpp

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,6 @@
44

55
namespace openPMD::core
66
{
7-
template <typename T>
8-
auto ConfigureLoadStore::withSharedPtr(std::shared_ptr<T> data)
9-
-> shared_ptr_return_type<T>
10-
{
11-
using T_decayed = std::remove_cv_t<std::remove_extent_t<T>>;
12-
if (!data)
13-
{
14-
throw std::runtime_error(
15-
"Unallocated pointer passed during chunk store.");
16-
}
17-
return shared_ptr_return_type<T>(
18-
auxiliary::WriteBuffer(
19-
std::static_pointer_cast<
20-
std::conditional_t<std::is_const_v<T>, void const, void>>(
21-
std::move(data))),
22-
determineDatatype<T_decayed>(),
23-
{std::move(*this)});
24-
}
25-
template <typename T>
26-
auto ConfigureLoadStore::withUniquePtr(UniquePtrWithLambda<T> data)
27-
-> unique_ptr_return_type<T>
28-
29-
{
30-
using T_decayed = std::remove_cv_t<std::remove_extent_t<T>>;
31-
if (!data)
32-
{
33-
throw std::runtime_error(
34-
"Unallocated pointer passed during chunk store.");
35-
}
36-
if constexpr (std::is_const_v<T>)
37-
{
38-
void const *raw_ptr = data.get();
39-
return unique_ptr_return_type<T>(
40-
auxiliary::WriteBuffer(
41-
std::shared_ptr<void const>(
42-
raw_ptr,
43-
[data_lambda =
44-
std::move(data)](auto const *) { /* no-op */ })),
45-
determineDatatype<T_decayed>(),
46-
{std::move(*this)});
47-
}
48-
else
49-
{
50-
return unique_ptr_return_type<T>(
51-
auxiliary::WriteBuffer(
52-
std::move(data).template static_cast_<void>()),
53-
determineDatatype<T_decayed>(),
54-
{std::move(*this)});
55-
}
56-
}
57-
template <typename T>
58-
auto ConfigureLoadStore::withRawPtr(T *data) -> shared_ptr_return_type<T>
59-
{
60-
using T_decayed = std::remove_cv_t<std::remove_extent_t<T>>;
61-
if (!data)
62-
{
63-
throw std::runtime_error(
64-
"Unallocated pointer passed during chunk store.");
65-
}
66-
return shared_ptr_return_type<T>(
67-
auxiliary::WriteBuffer(
68-
std::static_pointer_cast<
69-
std::conditional_t<std::is_const_v<T>, void const, void>>(
70-
auxiliary::shareRaw(data))),
71-
determineDatatype<T_decayed>(),
72-
{std::move(*this)});
73-
}
74-
757
template <typename T, typename Del>
768
auto ConfigureLoadStore::withUniquePtr(std::unique_ptr<T, Del> data)
779
-> unique_ptr_return_type<T>

src/LoadStoreChunk.cpp

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,74 @@ namespace core
123123
return *m_extent;
124124
}
125125

126+
template <typename T>
127+
auto ConfigureLoadStore::withSharedPtr(std::shared_ptr<T> data)
128+
-> shared_ptr_return_type<T>
129+
{
130+
using T_decayed = std::remove_cv_t<std::remove_extent_t<T>>;
131+
if (!data)
132+
{
133+
throw std::runtime_error(
134+
"Unallocated pointer passed during chunk store.");
135+
}
136+
return shared_ptr_return_type<T>(
137+
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>(),
142+
{std::move(*this)});
143+
}
144+
template <typename T>
145+
auto ConfigureLoadStore::withUniquePtr(UniquePtrWithLambda<T> data)
146+
-> unique_ptr_return_type<T>
147+
148+
{
149+
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+
}
155+
if constexpr (std::is_const_v<T>)
156+
{
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)});
166+
}
167+
else
168+
{
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)});
174+
}
175+
}
176+
template <typename T>
177+
auto ConfigureLoadStore::withRawPtr(T *data) -> shared_ptr_return_type<T>
178+
{
179+
using T_decayed = std::remove_cv_t<std::remove_extent_t<T>>;
180+
if (!data)
181+
{
182+
throw std::runtime_error(
183+
"Unallocated pointer passed during chunk store.");
184+
}
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>(),
191+
{std::move(*this)});
192+
}
193+
126194
template <typename T>
127195
auto ConfigureLoadStore::enqueueStore() -> DynamicMemoryView<T>
128196
{
@@ -324,6 +392,7 @@ template class compose::ConfigureStoreChunkFromBuffer<
324392

325393
// need this for clang-tidy
326394
#define OPENPMD_ARRAY(type) type[]
395+
#define OPENPMD_POINTER(type) type *
327396
#define OPENPMD_APPLY_TEMPLATE(template_, type) template_<type>
328397

329398
#define INSTANTIATE_METHOD_TEMPLATES(dtype) \
@@ -332,11 +401,26 @@ template class compose::ConfigureStoreChunkFromBuffer<
332401
std::shared_ptr, dtype)>; \
333402
template auto core::ConfigureLoadStore::load(EnqueuePolicy) \
334403
->std::shared_ptr<dtype>;
404+
#define INSTANTIATE_FULLMATRIX(dtype) \
405+
template auto core::ConfigureLoadStore::withSharedPtr( \
406+
std::shared_ptr<dtype> data) -> shared_ptr_return_type<dtype>; \
407+
template auto core::ConfigureLoadStore::withUniquePtr( \
408+
UniquePtrWithLambda<dtype> data) -> unique_ptr_return_type<dtype>;
335409
#define INSTANTIATE_METHOD_TEMPLATES_WITH_AND_WITHOUT_EXTENT(type) \
336410
INSTANTIATE_METHOD_TEMPLATES(type) \
337411
INSTANTIATE_METHOD_TEMPLATES(OPENPMD_ARRAY(type)) \
412+
INSTANTIATE_FULLMATRIX(type) \
413+
INSTANTIATE_FULLMATRIX(type const) \
414+
INSTANTIATE_FULLMATRIX(OPENPMD_ARRAY(type)) \
415+
INSTANTIATE_FULLMATRIX(OPENPMD_ARRAY(type const)) \
338416
template auto core::ConfigureLoadStore::enqueueStore() \
339-
-> DynamicMemoryView<type>;
417+
-> DynamicMemoryView<type>; \
418+
template auto core::ConfigureLoadStore::withRawPtr(OPENPMD_POINTER(type) \
419+
data) \
420+
->OPENPMD_APPLY_TEMPLATE(shared_ptr_return_type, type); \
421+
template auto core::ConfigureLoadStore::withRawPtr( \
422+
OPENPMD_POINTER(type const) data) \
423+
->OPENPMD_APPLY_TEMPLATE(shared_ptr_return_type, type const);
340424

341425
OPENPMD_FOREACH_DATASET_DATATYPE(
342426
INSTANTIATE_METHOD_TEMPLATES_WITH_AND_WITHOUT_EXTENT)
@@ -346,6 +430,7 @@ OPENPMD_FOREACH_DATASET_DATATYPE(
346430

347431
#undef INSTANTIATE_METHOD_TEMPLATES
348432
#undef OPENPMD_ARRAY
433+
#undef OPENPMD_POINTER
349434
#undef OPENPMD_APPLY_TEMPLATE
350435

351436
ConfigureLoadStore::ConfigureLoadStore(RecordComponent &rc)

0 commit comments

Comments
 (0)