Skip to content

Commit 727cbbc

Browse files
committed
Prepare class structure for load_chunk
1 parent 5f45fa0 commit 727cbbc

File tree

4 files changed

+93
-66
lines changed

4 files changed

+93
-66
lines changed

include/openPMD/LoadStoreChunk.hpp

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
namespace openPMD
1212
{
1313
class RecordComponent;
14-
template <typename Ptr_Type>
14+
template <typename Ptr_Type, typename ChildClass>
1515
class ConfigureStoreChunkFromBuffer;
16+
template <typename Ptr_Type>
17+
class ConfigureLoadStoreFromBuffer;
1618
template <typename T>
1719
class DynamicMemoryView;
1820

@@ -67,30 +69,28 @@ class ConfigureLoadStore : protected internal::ConfigureStoreChunkData
6769
auto offset(Offset) -> return_type &;
6870
auto extent(Extent) -> return_type &;
6971

72+
template <typename T>
73+
using shared_ptr_return_type = ConfigureLoadStoreFromBuffer<
74+
std::shared_ptr<normalize_dataset_type<T> const>>;
75+
template <typename T>
76+
using unique_ptr_return_type = ConfigureStoreChunkFromBuffer<
77+
UniquePtrWithLambda<normalize_dataset_type<T>>,
78+
void>;
79+
7080
// @todo rvalue references..?
7181
template <typename T>
72-
auto fromSharedPtr(std::shared_ptr<T>)
73-
-> ConfigureStoreChunkFromBuffer<
74-
std::shared_ptr<normalize_dataset_type<T> const>>;
82+
auto fromSharedPtr(std::shared_ptr<T>) -> shared_ptr_return_type<T>;
7583
template <typename T>
76-
auto fromUniquePtr(UniquePtrWithLambda<T>)
77-
-> ConfigureStoreChunkFromBuffer<
78-
UniquePtrWithLambda<normalize_dataset_type<T>>>;
84+
auto fromUniquePtr(UniquePtrWithLambda<T>) -> unique_ptr_return_type<T>;
7985
template <typename T, typename Del>
80-
auto fromUniquePtr(std::unique_ptr<T, Del>)
81-
-> ConfigureStoreChunkFromBuffer<
82-
UniquePtrWithLambda<normalize_dataset_type<T>>>;
86+
auto fromUniquePtr(std::unique_ptr<T, Del>) -> unique_ptr_return_type<T>;
8387
template <typename T>
84-
auto
85-
fromRawPtr(T *data) -> ConfigureStoreChunkFromBuffer<
86-
std::shared_ptr<normalize_dataset_type<T> const>>;
88+
auto fromRawPtr(T *data) -> shared_ptr_return_type<T>;
8789
template <typename T_ContiguousContainer>
88-
auto fromContiguousContainer(T_ContiguousContainer &data) ->
89-
typename std::enable_if_t<
90+
auto fromContiguousContainer(T_ContiguousContainer &data)
91+
-> std::enable_if_t<
9092
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
91-
ConfigureStoreChunkFromBuffer<
92-
std::shared_ptr<normalize_dataset_type<
93-
typename T_ContiguousContainer::value_type> const>>>;
93+
shared_ptr_return_type<typename T_ContiguousContainer::value_type>>;
9494

9595
template <typename T>
9696
[[nodiscard]] auto enqueueStore() -> DynamicMemoryView<T>;
@@ -100,13 +100,19 @@ class ConfigureLoadStore : protected internal::ConfigureStoreChunkData
100100
[[nodiscard]] auto enqueueStore(F &&createBuffer) -> DynamicMemoryView<T>;
101101
};
102102

103-
template <typename Ptr_Type>
103+
template <typename Ptr_Type, typename ChildClass = void>
104104
class ConfigureStoreChunkFromBuffer
105-
: public ConfigureLoadStore<ConfigureStoreChunkFromBuffer<Ptr_Type>>
105+
: public ConfigureLoadStore<std::conditional_t<
106+
std::is_void_v<ChildClass>,
107+
/*then*/ ConfigureStoreChunkFromBuffer<Ptr_Type, void>,
108+
/*else*/ ChildClass>>
106109
{
107110
public:
108-
using parent_t =
109-
ConfigureLoadStore<ConfigureStoreChunkFromBuffer<Ptr_Type>>;
111+
using return_type = std::conditional_t<
112+
std::is_void_v<ChildClass>,
113+
/*then*/ ConfigureStoreChunkFromBuffer<Ptr_Type, void>,
114+
/*else*/ ChildClass>;
115+
using parent_t = ConfigureLoadStore<return_type>;
110116

111117
private:
112118
template <typename T>
@@ -115,19 +121,38 @@ class ConfigureStoreChunkFromBuffer
115121
Ptr_Type m_buffer;
116122
std::optional<MemorySelection> m_mem_select;
117123

118-
ConfigureStoreChunkFromBuffer(Ptr_Type buffer, parent_t &&);
119-
120124
auto storeChunkConfig() const -> internal::StoreChunkConfigFromBuffer;
121125

126+
protected:
127+
ConfigureStoreChunkFromBuffer(Ptr_Type buffer, parent_t &&);
128+
122129
public:
123-
auto memorySelection(MemorySelection) -> ConfigureStoreChunkFromBuffer &;
130+
auto memorySelection(MemorySelection) -> return_type &;
124131

125132
auto as_parent() && -> parent_t &&;
126133
auto as_parent() & -> parent_t &;
127134
auto as_parent() const & -> parent_t const &;
128135

129136
auto enqueueStore() -> void;
130137
};
138+
139+
template <typename Ptr_Type>
140+
class ConfigureLoadStoreFromBuffer
141+
: public ConfigureStoreChunkFromBuffer<
142+
Ptr_Type,
143+
ConfigureLoadStoreFromBuffer<Ptr_Type>>
144+
{
145+
using parent_t = ConfigureStoreChunkFromBuffer<
146+
Ptr_Type,
147+
ConfigureLoadStoreFromBuffer<Ptr_Type>>;
148+
template <typename>
149+
friend class ConfigureLoadStore;
150+
ConfigureLoadStoreFromBuffer(
151+
Ptr_Type buffer, typename parent_t::parent_t &&);
152+
153+
public:
154+
auto enqueueLoad() -> void;
155+
};
131156
} // namespace openPMD
132157

133158
#include "openPMD/LoadStoreChunk.tpp"

include/openPMD/LoadStoreChunk.tpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,64 @@
44

55
namespace openPMD
66
{
7-
87
template <typename ChildClass>
98
template <typename T>
109
auto ConfigureLoadStore<ChildClass>::fromSharedPtr(std::shared_ptr<T> data)
11-
-> ConfigureStoreChunkFromBuffer<
12-
std::shared_ptr<normalize_dataset_type<T> const>>
10+
-> shared_ptr_return_type<T>
1311
{
1412
if (!data)
1513
{
1614
throw std::runtime_error(
1715
"Unallocated pointer passed during chunk store.");
1816
}
19-
return ConfigureStoreChunkFromBuffer<
20-
std::shared_ptr<normalize_dataset_type<T> const>>(
17+
return shared_ptr_return_type<T>(
2118
std::static_pointer_cast<normalize_dataset_type<T> const>(
2219
std::move(data)),
2320
{std::move(*this)});
2421
}
2522
template <typename ChildClass>
2623
template <typename T>
2724
auto ConfigureLoadStore<ChildClass>::fromUniquePtr(UniquePtrWithLambda<T> data)
28-
-> ConfigureStoreChunkFromBuffer<
29-
UniquePtrWithLambda<normalize_dataset_type<T>>>
25+
-> unique_ptr_return_type<T>
26+
3027
{
3128
if (!data)
3229
{
3330
throw std::runtime_error(
3431
"Unallocated pointer passed during chunk store.");
3532
}
36-
return ConfigureStoreChunkFromBuffer<
37-
UniquePtrWithLambda<normalize_dataset_type<T>>>(
33+
return unique_ptr_return_type<T>(
3834
std::move(data).template static_cast_<normalize_dataset_type<T>>(),
3935
{std::move(*this)});
4036
}
4137
template <typename ChildClass>
4238
template <typename T>
4339
auto ConfigureLoadStore<ChildClass>::fromRawPtr(T *data)
44-
-> ConfigureStoreChunkFromBuffer<
45-
std::shared_ptr<normalize_dataset_type<T> const>>
40+
-> shared_ptr_return_type<T>
4641
{
4742
if (!data)
4843
{
4944
throw std::runtime_error(
5045
"Unallocated pointer passed during chunk store.");
5146
}
52-
return ConfigureStoreChunkFromBuffer<
53-
std::shared_ptr<normalize_dataset_type<T> const>>(
47+
return shared_ptr_return_type<T>(
5448
auxiliary::shareRaw(data), {std::move(*this)});
5549
}
5650

5751
template <typename ChildClass>
5852
template <typename T, typename Del>
5953
auto ConfigureLoadStore<ChildClass>::fromUniquePtr(std::unique_ptr<T, Del> data)
60-
-> ConfigureStoreChunkFromBuffer<
61-
UniquePtrWithLambda<normalize_dataset_type<T>>>
54+
-> unique_ptr_return_type<T>
6255
{
6356
return fromUniquePtr(UniquePtrWithLambda<T>(std::move(data)));
6457
}
6558
template <typename ChildClass>
6659
template <typename T_ContiguousContainer>
6760
auto ConfigureLoadStore<ChildClass>::fromContiguousContainer(
68-
T_ContiguousContainer &data) ->
69-
typename std::enable_if_t<
61+
T_ContiguousContainer &data)
62+
-> std::enable_if_t<
7063
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
71-
ConfigureStoreChunkFromBuffer<std::shared_ptr<normalize_dataset_type<
72-
typename T_ContiguousContainer::value_type> const>>>
64+
shared_ptr_return_type<typename T_ContiguousContainer::value_type>>
7365
{
7466
if (!m_extent.has_value() && dim() == 1)
7567
{

include/openPMD/RecordComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class RecordComponent : public BaseRecordComponent
135135
friend class MeshRecordComponent;
136136
template <typename ChildClass>
137137
friend class ConfigureLoadStore;
138-
template <typename Ptr_Type>
138+
template <typename Ptr_Type, typename ChildClass>
139139
friend class ConfigureStoreChunkFromBuffer;
140140

141141
public:

src/LoadStoreChunk.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,54 +121,62 @@ auto ConfigureLoadStore<ChildClass>::enqueueStore() -> DynamicMemoryView<T>
121121
return m_rc.storeChunkSpan_impl<T>(storeChunkConfig());
122122
}
123123

124-
template <typename Ptr_Type>
125-
ConfigureStoreChunkFromBuffer<Ptr_Type>::ConfigureStoreChunkFromBuffer(
126-
Ptr_Type buffer, parent_t &&parent)
124+
template <typename Ptr_Type, typename ChildClass>
125+
ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::
126+
ConfigureStoreChunkFromBuffer(Ptr_Type buffer, parent_t &&parent)
127127
: parent_t(std::move(parent)), m_buffer(std::move(buffer))
128128
{}
129129

130-
template <typename Ptr_Type>
131-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::as_parent() && -> parent_t &&
130+
template <typename Ptr_Type, typename ChildClass>
131+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::as_parent()
132+
&& -> parent_t &&
132133
{
133134
return std::move(*this);
134135
}
135-
template <typename Ptr_Type>
136-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::as_parent() & -> parent_t &
136+
template <typename Ptr_Type, typename ChildClass>
137+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::as_parent()
138+
& -> parent_t &
137139
{
138140
return *this;
139141
}
140-
template <typename Ptr_Type>
141-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::as_parent()
142+
template <typename Ptr_Type, typename ChildClass>
143+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::as_parent()
142144
const & -> parent_t const &
143145
{
144146
return *this;
145147
}
146148

147-
template <typename Ptr_Type>
148-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::storeChunkConfig() const
149-
-> internal::StoreChunkConfigFromBuffer
149+
template <typename Ptr_Type, typename ChildClass>
150+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::storeChunkConfig()
151+
const -> internal::StoreChunkConfigFromBuffer
150152
{
151153
return internal::StoreChunkConfigFromBuffer{
152154
this->getOffset(), this->getExtent(), m_mem_select};
153155
}
154156

155-
template <typename Ptr_Type>
156-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::memorySelection(
157-
MemorySelection sel) -> ConfigureStoreChunkFromBuffer &
157+
template <typename Ptr_Type, typename ChildClass>
158+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::memorySelection(
159+
MemorySelection sel) -> return_type &
158160
{
159161
this->m_mem_select = std::make_optional<MemorySelection>(std::move(sel));
160-
return *this;
162+
return *static_cast<return_type *>(this);
161163
}
162164

163-
template <typename Ptr_Type>
164-
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::enqueueStore() -> void
165+
template <typename Ptr_Type, typename ChildClass>
166+
auto ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::enqueueStore() -> void
165167
{
166168
this->m_rc.storeChunk_impl(
167169
asWriteBuffer(std::move(m_buffer)),
168170
determineDatatype<auxiliary::IsPointer_t<Ptr_Type>>(),
169171
storeChunkConfig());
170172
}
171173

174+
template <typename Ptr_Type>
175+
ConfigureLoadStoreFromBuffer<Ptr_Type>::ConfigureLoadStoreFromBuffer(
176+
Ptr_Type buffer, typename parent_t::parent_t &&parent)
177+
: parent_t(std::move(buffer), std::move(parent))
178+
{}
179+
172180
#define INSTANTIATE_METHOD_TEMPLATES(base_class, dtype) \
173181
template auto base_class::enqueueStore() -> DynamicMemoryView<dtype>;
174182

@@ -181,13 +189,15 @@ OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_METHOD_TEMPLATES_FOR_BASE)
181189
#undef INSTANTIATE_METHOD_TEMPLATES_FOR_BASE
182190

183191
#define INSTANTIATE_STORE_CHUNK_FROM_BUFFER(dtype) \
192+
template class ConfigureLoadStoreFromBuffer<std::shared_ptr<dtype const>>; \
184193
template class ConfigureStoreChunkFromBuffer< \
185-
std::shared_ptr<dtype const>>; \
194+
std::shared_ptr<dtype const>, \
195+
ConfigureLoadStoreFromBuffer<std::shared_ptr<dtype const>>>; \
186196
template class ConfigureLoadStore< \
187-
ConfigureStoreChunkFromBuffer<std::shared_ptr<dtype const>>>; \
197+
ConfigureLoadStoreFromBuffer<std::shared_ptr<dtype const>>>; \
188198
INSTANTIATE_METHOD_TEMPLATES( \
189199
ConfigureLoadStore< \
190-
ConfigureStoreChunkFromBuffer<std::shared_ptr<dtype const>>>, \
200+
ConfigureLoadStoreFromBuffer<std::shared_ptr<dtype const>>>, \
191201
dtype) \
192202
template class ConfigureStoreChunkFromBuffer<UniquePtrWithLambda<dtype>>; \
193203
template class ConfigureLoadStore< \

0 commit comments

Comments
 (0)