@@ -37,150 +37,172 @@ namespace internal
3737
3838namespace auxiliary ::detail
3939{
40- using future_to_shared_ptr_dataset_types =
40+ using shared_ptr_dataset_types =
4141 map_variant<as_shared_pointer, dataset_types>::type;
4242} // namespace auxiliary::detail
4343
44- namespace auxiliary
44+ namespace compose
4545{
46- template <typename possibly_void, typename alternative>
47- using non_void_or = std::conditional_t <
48- !std::is_void_v<possibly_void>,
49- /* then*/ possibly_void,
50- /* else*/ alternative>;
51- } // namespace auxiliary
46+ template <typename ChildClass>
47+ class ConfigureLoadStore ;
48+ template <typename ChildClass>
49+ class ConfigureLoadStoreFromBuffer ;
50+ } // namespace compose
5251
5352enum class EnqueuePolicy
5453{
5554 Defer,
5655 Immediate
5756};
5857
59- /*
60- * Actual data members of `ConfigureLoadStore<>` and methods that don't depend
61- * on the ChildClass template parameter. By extracting the members to this
62- * struct, we can pass them around between different instances of the class
63- * template. Numbers of method instantiations can be reduced.
64- */
65- struct ConfigureLoadStoreCore
58+ namespace core
6659{
67- ConfigureLoadStoreCore (RecordComponent &);
68-
69- RecordComponent &m_rc;
70- std::optional<Offset> m_offset;
71- std::optional<Extent> m_extent;
72-
73- protected:
74- [[nodiscard]] auto dim () const -> uint8_t;
75- auto getOffset () -> Offset const &;
76- auto getExtent () -> Extent const &;
77- auto storeChunkConfig () -> internal::LoadStoreConfig;
78-
79- public:
80- /*
81- * If the type is non-const, then the return type should be
82- * ConfigureLoadStoreFromBuffer<>, ...
83- */
84- template <typename T>
85- struct shared_ptr_return_type_impl
86- {
87- using type = ConfigureLoadStoreFromBuffer<std::shared_ptr<T>>;
88- };
8960 /*
90- * ..., but if it is a const type, Load operations make no sense, so the
91- * return type should be ConfigureStoreChunkFromBuffer<>.
61+ * Actual data members of `ConfigureLoadStore<>` and methods that don't
62+ * depend on the ChildClass template parameter. By extracting the members to
63+ * this struct, we can pass them around between different instances of the
64+ * class template. Numbers of method instantiations can be reduced.
9265 */
93- template <typename T>
94- struct shared_ptr_return_type_impl <T const >
66+ class ConfigureLoadStore
9567 {
96- using type = ConfigureStoreChunkFromBuffer<std::shared_ptr<T const >>;
97- };
98-
99- template <typename T>
100- using shared_ptr_return_type =
101- typename shared_ptr_return_type_impl<std::remove_extent_t <T>>::type;
102-
103- /*
104- * As loading into unique pointer types makes no sense, the case is simpler
105- * for unique pointers. Just remove the array extents here.
106- */
107- template <typename T>
108- using unique_ptr_return_type = ConfigureStoreChunkFromBuffer<
109- UniquePtrWithLambda<std::remove_extent_t <T>>>;
110-
111- // @todo rvalue references..?
112- template <typename T>
113- auto withSharedPtr (std::shared_ptr<T>) -> shared_ptr_return_type<T>;
114- template <typename T>
115- auto withUniquePtr (UniquePtrWithLambda<T>) -> unique_ptr_return_type<T>;
116- template <typename T, typename Del>
117- auto withUniquePtr (std::unique_ptr<T, Del>) -> unique_ptr_return_type<T>;
118- template <typename T>
119- auto withRawPtr (T *data) -> shared_ptr_return_type<T>;
120- template <typename T_ContiguousContainer>
121- auto withContiguousContainer (T_ContiguousContainer &data)
122- -> std::enable_if_t<
123- auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
124- shared_ptr_return_type<typename T_ContiguousContainer::value_type>>;
125-
126- template <typename T>
127- [[nodiscard]] auto enqueueStore () -> DynamicMemoryView<T>;
128- // definition for this one is in RecordComponent.tpp since it needs the
129- // definition of class RecordComponent.
130- template <typename T, typename F>
131- [[nodiscard]] auto enqueueStore (F &&createBuffer) -> DynamicMemoryView<T>;
132-
133- template <typename T>
134- [[nodiscard]] auto enqueueLoad () -> std::future<std::shared_ptr<T>>;
135-
136- template <typename T>
137- [[nodiscard]] auto load (EnqueuePolicy) -> std::shared_ptr<T>;
138-
139- [[nodiscard]] auto enqueueLoadVariant ()
140- -> std::future<auxiliary::detail::future_to_shared_ptr_dataset_types>;
141- };
68+ template <typename ChildClass>
69+ friend class compose ::ConfigureLoadStore;
70+ template <typename ChildClass>
71+ friend class compose ::ConfigureLoadStoreFromBuffer;
14272
143- template <typename Ptr_Type>
144- class ConfigureStoreChunkFromBufferCore : public ConfigureLoadStoreCore
145- {
146- public:
147- Ptr_Type m_buffer;
148- std::optional<MemorySelection> m_mem_select;
73+ protected:
74+ ConfigureLoadStore (RecordComponent &);
75+ RecordComponent &m_rc;
14976
150- ConfigureStoreChunkFromBufferCore (
151- Ptr_Type buffer, ConfigureLoadStoreCore &&) ;
77+ std::optional<Offset> m_offset;
78+ std::optional<Extent> m_extent ;
15279
153- auto storeChunkConfig () -> internal::LoadStoreConfigWithBuffer;
80+ [[nodiscard]] auto dim () const -> uint8_t;
81+ auto storeChunkConfig () -> internal::LoadStoreConfig;
15482
155- auto enqueueStore () -> void;
83+ public:
84+ auto getOffset () -> Offset const &;
85+ auto getExtent () -> Extent const &;
86+ /*
87+ * If the type is non-const, then the return type should be
88+ * ConfigureLoadStoreFromBuffer<>, ...
89+ */
90+ template <typename T>
91+ struct shared_ptr_return_type_impl
92+ {
93+ using type = ConfigureLoadStoreFromBuffer<std::shared_ptr<T>>;
94+ };
95+ /*
96+ * ..., but if it is a const type, Load operations make no sense, so the
97+ * return type should be ConfigureStoreChunkFromBuffer<>.
98+ */
99+ template <typename T>
100+ struct shared_ptr_return_type_impl <T const >
101+ {
102+ using type =
103+ ConfigureStoreChunkFromBuffer<std::shared_ptr<T const >>;
104+ };
105+
106+ template <typename T>
107+ using shared_ptr_return_type =
108+ typename shared_ptr_return_type_impl<std::remove_extent_t <T>>::type;
109+
110+ /*
111+ * As loading into unique pointer types makes no sense, the case is
112+ * simpler for unique pointers. Just remove the array extents here.
113+ */
114+ template <typename T>
115+ using unique_ptr_return_type = ConfigureStoreChunkFromBuffer<
116+ UniquePtrWithLambda<std::remove_extent_t <T>>>;
117+
118+ // @todo rvalue references..?
119+ template <typename T>
120+ auto withSharedPtr (std::shared_ptr<T>) -> shared_ptr_return_type<T>;
121+ template <typename T>
122+ auto withUniquePtr (UniquePtrWithLambda<T>) -> unique_ptr_return_type<T>;
123+ template <typename T, typename Del>
124+ auto
125+ withUniquePtr (std::unique_ptr<T, Del>) -> unique_ptr_return_type<T>;
126+ template <typename T>
127+ auto withRawPtr (T *data) -> shared_ptr_return_type<T>;
128+ template <typename T_ContiguousContainer>
129+ auto withContiguousContainer (T_ContiguousContainer &data)
130+ -> std::enable_if_t<
131+ auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
132+ shared_ptr_return_type<
133+ typename T_ContiguousContainer::value_type>>;
134+
135+ template <typename T>
136+ [[nodiscard]] auto enqueueStore () -> DynamicMemoryView<T>;
137+ // definition for this one is in RecordComponent.tpp since it needs the
138+ // definition of class RecordComponent.
139+ template <typename T, typename F>
140+ [[nodiscard]] auto
141+ enqueueStore (F &&createBuffer) -> DynamicMemoryView<T>;
142+
143+ template <typename T>
144+ [[nodiscard]] auto enqueueLoad () -> std::future<std::shared_ptr<T>>;
145+
146+ template <typename T>
147+ [[nodiscard]] auto load (EnqueuePolicy) -> std::shared_ptr<T>;
148+
149+ [[nodiscard]] auto enqueueLoadVariant ()
150+ -> std::future<auxiliary::detail::shared_ptr_dataset_types>;
151+
152+ [[nodiscard]] auto loadVariant (EnqueuePolicy)
153+ -> auxiliary::detail::shared_ptr_dataset_types;
154+ };
156155
157- /* * This intentionally shadows the parent class's enqueueLoad method in
158- * order to show a compile error when using enqueueLoad() on an object of
159- * this class. The parent method can still be accessed through as_parent()
160- * if needed.
161- */
162- template <typename X = void >
163- auto enqueueLoad ()
156+ template <typename Ptr_Type>
157+ class ConfigureStoreChunkFromBuffer : public ConfigureLoadStore
164158 {
165- static_assert (
166- auxiliary::dependent_false_v<X>,
167- " Cannot load chunk data into a buffer that is const or a "
168- " unique_ptr." );
169- }
170- };
159+ public:
160+ Ptr_Type m_buffer;
161+ std::optional<MemorySelection> m_mem_select;
162+
163+ ConfigureStoreChunkFromBuffer (Ptr_Type buffer, ConfigureLoadStore &&);
164+
165+ auto storeChunkConfig () -> internal::LoadStoreConfigWithBuffer;
166+
167+ auto enqueueStore () -> void;
168+
169+ /* * This intentionally shadows the parent class's enqueueLoad methods in
170+ * order to show a compile error when using enqueueLoad() on an object
171+ * of this class. The parent method can still be accessed through
172+ * as_parent() if needed.
173+ */
174+ template <typename X = void >
175+ auto enqueueLoad ()
176+ {
177+ static_assert (
178+ auxiliary::dependent_false_v<X>,
179+ " Cannot load chunk data into a buffer that is const or a "
180+ " unique_ptr." );
181+ }
182+
183+ template <typename X = void >
184+ auto load (EnqueuePolicy)
185+ {
186+ static_assert (
187+ auxiliary::dependent_false_v<X>,
188+ " Cannot load chunk data into a buffer that is const or a "
189+ " unique_ptr." );
190+ }
191+ };
171192
172- template <typename Ptr_Type>
173- class ConfigureLoadStoreFromBufferCore
174- : public ConfigureStoreChunkFromBufferCore <Ptr_Type>
175- {
176- public:
177- using ConfigureStoreChunkFromBufferCore <
178- Ptr_Type>::ConfigureStoreChunkFromBufferCore ;
193+ template <typename Ptr_Type>
194+ class ConfigureLoadStoreFromBuffer
195+ : public ConfigureStoreChunkFromBuffer <Ptr_Type>
196+ {
197+ public:
198+ using ConfigureStoreChunkFromBuffer <
199+ Ptr_Type>::ConfigureStoreChunkFromBuffer ;
179200
180- auto enqueueLoad () -> void;
201+ auto enqueueLoad () -> void;
181202
182- auto load (EnqueuePolicy) -> void;
183- };
203+ auto load (EnqueuePolicy) -> void;
204+ };
205+ } // namespace core
184206
185207namespace compose
186208{
@@ -222,41 +244,41 @@ namespace compose
222244} // namespace compose
223245
224246class ConfigureLoadStore
225- : public ConfigureLoadStoreCore
247+ : public core::ConfigureLoadStore
226248 , public compose::ConfigureLoadStore<ConfigureLoadStore>
227249{
228250 friend class RecordComponent ;
229- friend struct ConfigureLoadStoreCore ;
251+ friend class core ::ConfigureLoadStore ;
230252
231253 ConfigureLoadStore (RecordComponent &rc);
232- ConfigureLoadStore (ConfigureLoadStoreCore &&);
254+ ConfigureLoadStore (core::ConfigureLoadStore &&);
233255};
234256
235257template <typename Ptr_Type>
236258class ConfigureStoreChunkFromBuffer
237- : public ConfigureStoreChunkFromBufferCore <Ptr_Type>
259+ : public core::ConfigureStoreChunkFromBuffer <Ptr_Type>
238260 , public compose::ConfigureLoadStore<
239261 ConfigureStoreChunkFromBuffer<Ptr_Type>>
240262 , public compose::ConfigureStoreChunkFromBuffer<
241263 ConfigureStoreChunkFromBuffer<Ptr_Type>>
242264{
243- friend struct ConfigureLoadStoreCore ;
265+ friend class core ::ConfigureLoadStore ;
244266
245- using ConfigureStoreChunkFromBufferCore <
246- Ptr_Type>::ConfigureStoreChunkFromBufferCore ;
267+ using core::ConfigureStoreChunkFromBuffer <
268+ Ptr_Type>::ConfigureStoreChunkFromBuffer ;
247269};
248270
249271template <typename Ptr_Type>
250272class ConfigureLoadStoreFromBuffer
251- : public ConfigureLoadStoreFromBufferCore <Ptr_Type>
273+ : public core::ConfigureLoadStoreFromBuffer <Ptr_Type>
252274 , public compose::ConfigureLoadStore<ConfigureLoadStoreFromBuffer<Ptr_Type>>
253275 , public compose::ConfigureStoreChunkFromBuffer<
254276 ConfigureLoadStoreFromBuffer<Ptr_Type>>
255277{
256- friend struct ConfigureLoadStoreCore ;
278+ friend class ConfigureLoadStoreCore ;
257279
258- using ConfigureLoadStoreFromBufferCore <
259- Ptr_Type>::ConfigureLoadStoreFromBufferCore ;
280+ using core::ConfigureLoadStoreFromBuffer <
281+ Ptr_Type>::ConfigureLoadStoreFromBuffer ;
260282};
261283} // namespace openPMD
262284
0 commit comments