Skip to content

Commit b5cc977

Browse files
committed
Add variant-based loadChunk
1 parent ce0e468 commit b5cc977

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

include/openPMD/LoadStoreChunk.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class ConfigureLoadStore : protected internal::ConfigureLoadStoreData
121121

122122
template <typename T>
123123
[[nodiscard]] auto enqueueLoad() -> std::shared_ptr<T>;
124+
125+
using shared_ptr_dataset_types = auxiliary::detail::
126+
map_variant<auxiliary::detail::as_shared_pointer, dataset_types>::type;
127+
[[nodiscard]] auto enqueueLoadVariant() -> shared_ptr_dataset_types;
124128
};
125129

126130
template <typename Ptr_Type, typename ChildClass = void>

src/LoadStoreChunk.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ auto ConfigureLoadStore<ChildClass>::enqueueLoad() -> std::shared_ptr<T>
133133
return m_rc.loadChunkAllocate_impl<T>(storeChunkConfig());
134134
}
135135

136+
namespace
137+
{
138+
template <typename ConfigureLoadStore_t>
139+
struct VisitorEnqueueLoadVariant
140+
{
141+
template <typename T>
142+
static auto call(RecordComponent const &, ConfigureLoadStore_t &cfg) ->
143+
typename ConfigureLoadStore_t::shared_ptr_dataset_types
144+
{
145+
return cfg.template enqueueLoad<T>();
146+
}
147+
};
148+
} // namespace
149+
150+
template <typename ChildClass>
151+
auto ConfigureLoadStore<ChildClass>::enqueueLoadVariant()
152+
-> shared_ptr_dataset_types
153+
{
154+
return m_rc
155+
.visit<VisitorEnqueueLoadVariant<ConfigureLoadStore<ChildClass>>>(
156+
*this);
157+
}
158+
136159
template <typename Ptr_Type, typename ChildClass>
137160
ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::
138161
ConfigureStoreChunkFromBuffer(Ptr_Type buffer, parent_t &&parent)

test/SerialIOTest.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,13 +1676,17 @@ inline void write_test(const std::string &backend)
16761676
auto opaqueTypeDataset = rc.visit<ReadFromAnyType>();
16771677

16781678
auto variantTypeDataset = rc.loadChunkVariant();
1679+
auto variantTypeDataset2 = rc.prepareLoadStore().enqueueLoadVariant();
16791680
rc.seriesFlush();
1680-
std::visit(
1681-
[](auto &&shared_ptr) {
1682-
std::cout << "First value in loaded chunk: '" << shared_ptr.get()[0]
1683-
<< '\'' << std::endl;
1684-
},
1685-
variantTypeDataset);
1681+
for (auto ptr : {&variantTypeDataset, &variantTypeDataset2})
1682+
{
1683+
std::visit(
1684+
[](auto &&shared_ptr) {
1685+
std::cout << "First value in loaded chunk: '"
1686+
<< shared_ptr.get()[0] << '\'' << std::endl;
1687+
},
1688+
*ptr);
1689+
}
16861690

16871691
#ifndef _WIN32
16881692
REQUIRE(read.rankTable(/* collective = */ false) == compare);

0 commit comments

Comments
 (0)