Skip to content

Commit 4d1e260

Browse files
committed
Some documentation and cleanup
1 parent b6077fd commit 4d1e260

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

include/openPMD/LoadStoreChunk.hpp

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ namespace internal
3232
std::optional<MemorySelection> memorySelection;
3333
};
3434

35+
/*
36+
* Actual data members of `ConfigureLoadStore<>`. They don't depend on the
37+
* template parameter of that class template, so by extracting the members
38+
* to this struct, we can pass them around between different instances of
39+
* the class template.
40+
*/
3541
struct ConfigureLoadStoreData
3642
{
3743
ConfigureLoadStoreData(RecordComponent &);
@@ -42,6 +48,13 @@ namespace internal
4248
};
4349
} // namespace internal
4450

51+
/** Basic configuration for a Load/Store operation.
52+
*
53+
* @tparam ChildClass CRT pattern.
54+
* The purpose is that in child classes `return *this` should return
55+
* an instance of the child class, not of ConfigureLoadStore.
56+
* Instantiate with void when using without subclass.
57+
*/
4558
template <typename ChildClass = void>
4659
class ConfigureLoadStore : protected internal::ConfigureLoadStoreData
4760
{
@@ -53,7 +66,7 @@ class ConfigureLoadStore : protected internal::ConfigureLoadStoreData
5366
ConfigureLoadStore(RecordComponent &rc);
5467
ConfigureLoadStore(ConfigureLoadStoreData &&);
5568

56-
auto dim() const -> uint8_t;
69+
[[nodiscard]] auto dim() const -> uint8_t;
5770
auto getOffset() -> Offset const &;
5871
auto getExtent() -> Extent const &;
5972
auto storeChunkConfig() -> internal::LoadStoreConfig;
@@ -67,34 +80,37 @@ class ConfigureLoadStore : protected internal::ConfigureLoadStoreData
6780
auto offset(Offset) -> return_type &;
6881
auto extent(Extent) -> return_type &;
6982

83+
/*
84+
* If the type is non-const, then the return type should be
85+
* ConfigureLoadStoreFromBuffer<>, ...
86+
*/
7087
template <typename T>
7188
struct shared_ptr_return_type_impl
7289
{
73-
using type = ConfigureLoadStoreFromBuffer<
74-
std::shared_ptr<std::remove_extent_t<T>>>;
90+
using type = ConfigureLoadStoreFromBuffer<std::shared_ptr<T>>;
7591
};
92+
/*
93+
* ..., but if it is a const type, Load operations make no sense, so the
94+
* return type should be ConfigureStoreChunkFromBuffer<>.
95+
*/
7696
template <typename T>
7797
struct shared_ptr_return_type_impl<T const>
7898
{
7999
using type =
80100
ConfigureStoreChunkFromBuffer<std::shared_ptr<T const>, void>;
81101
};
82-
template <typename T>
83-
struct shared_ptr_return_type_impl<T const[]>
84-
{
85-
using type =
86-
ConfigureStoreChunkFromBuffer<std::shared_ptr<T const>, void>;
87-
};
88102

89103
template <typename T>
90104
using shared_ptr_return_type =
91-
typename shared_ptr_return_type_impl<T>::type;
105+
typename shared_ptr_return_type_impl<std::remove_extent_t<T>>::type;
92106

93-
template <typename T>
94-
using normalize_dataset_type = std::remove_cv_t<std::remove_extent_t<T>>;
107+
/*
108+
* As loading into unique pointer types makes no sense, the case is simpler
109+
* for unique pointers. Just remove the array extents here.
110+
*/
95111
template <typename T>
96112
using unique_ptr_return_type = ConfigureStoreChunkFromBuffer<
97-
UniquePtrWithLambda<normalize_dataset_type<T>>,
113+
UniquePtrWithLambda<std::remove_extent_t<T>>,
98114
void>;
99115

100116
// @todo rvalue references..?
@@ -127,6 +143,19 @@ class ConfigureLoadStore : protected internal::ConfigureLoadStoreData
127143
[[nodiscard]] auto enqueueLoadVariant() -> shared_ptr_dataset_types;
128144
};
129145

146+
/** Configuration for a Store operation with a buffer type.
147+
*
148+
* This class does intentionally not support Load operations since there are
149+
* pointer types (const pointers, unique pointers) where Load operations make no
150+
* sense. See the \ref ConfigureLoadStoreFromBuffer class template for both
151+
* Load/Store operations.
152+
*
153+
* @tparam Ptr_Type The type of pointer used internally.
154+
* @tparam ChildClass CRT pattern.
155+
* The purpose is that in child classes `return *this` should return
156+
* an instance of the child class, not of ConfigureStoreChunkFromBuffer.
157+
* Instantiate with void when using without subclass.
158+
*/
130159
template <typename Ptr_Type, typename ChildClass = void>
131160
class ConfigureStoreChunkFromBuffer
132161
: public ConfigureLoadStore<std::conditional_t<
@@ -161,6 +190,12 @@ class ConfigureStoreChunkFromBuffer
161190
auto as_parent() const & -> parent_t const &;
162191

163192
auto enqueueStore() -> void;
193+
194+
/** This intentionally shadows the parent class's enqueueLoad method in
195+
* order to show a compile error when using enqueueLoad() on an object of
196+
* this class. The parent method can still be accessed through as_parent()
197+
* if needed.
198+
*/
164199
template <typename X = void>
165200
auto enqueueLoad()
166201
{
@@ -171,6 +206,14 @@ class ConfigureStoreChunkFromBuffer
171206
}
172207
};
173208

209+
/** Configuration for a Load/Store operation with a buffer type.
210+
*
211+
* Only instantiated for pointer types where Load operations make sense (e.g. no
212+
* const pointers and no unique pointers).
213+
* \ref ConfigureStoreChunkFromBuffer is used otherwise.
214+
*
215+
* @tparam Ptr_Type The type of pointer used internally.
216+
*/
174217
template <typename Ptr_Type>
175218
class ConfigureLoadStoreFromBuffer
176219
: public ConfigureStoreChunkFromBuffer<

include/openPMD/LoadStoreChunk.tpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ auto ConfigureLoadStore<ChildClass>::withUniquePtr(UniquePtrWithLambda<T> data)
2424
-> unique_ptr_return_type<T>
2525

2626
{
27+
// should we support them?
28+
static_assert(
29+
!std::is_const_v<T>,
30+
"Unique pointers to const types not supported as storeChunk buffers.");
2731
if (!data)
2832
{
2933
throw std::runtime_error(
3034
"Unallocated pointer passed during chunk store.");
3135
}
3236
return unique_ptr_return_type<T>(
33-
std::move(data).template static_cast_<normalize_dataset_type<T>>(),
37+
std::move(data).template static_cast_<std::remove_extent_t<T>>(),
3438
{std::move(*this)});
3539
}
3640
template <typename ChildClass>

0 commit comments

Comments
 (0)