libzypp 17.32.5
logichelpers.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_NG_LOGICHELPERS_INCLUDED
10#define ZYPP_NG_LOGICHELPERS_INCLUDED
11
12#include <zypp-core/zyppng/async/AsyncOp>
13
14namespace zyppng
15{
16
17 namespace detail {
18 template <typename Op, typename = void>
19 struct LogicBaseExec : public Op { };
20
21 template <typename Op>
22 struct LogicBaseExec<Op, std::enable_if_t<detail::is_async_op_v<Op>>> : public Op
23 {
24 protected:
26 };
27
28 }
29
121 template <typename Executor, typename OpType>
122 struct LogicBase : public detail::LogicBaseExec<OpType> {
123
125 using Result = typename OpType::value_type;
126
130 template<class Type>
132
134 virtual ~LogicBase(){}
135
136 template <typename ...Args, typename FOpType = OpType>
138 auto op = std::make_shared<Executor>( std::forward<Args>(args)... );
139 op->asyncExecute();
140 return op;
141 }
142
143 template <typename ...Args, typename FOpType = OpType>
145 return Executor( std::forward<Args>(args)... ).execute();
146 }
147
148
154 return static_cast<Executor *>(this);
155 }
156
161 template <typename T>
162 inline auto makeReadyResult( T &&res ) {
164 }
165
166 private:
167 template <typename FOpType = OpType>
169 this->_innerPipeline = static_cast<Executor*>(this)->execute();
170 this->_innerPipeline->onReady([this]( auto &&val ){
171 this->setReady( std::forward<decltype(val)>(val) );
172 });
173 }
174 };
175
180 template <typename Result>
181 struct SyncOp : public Base {
182 using value_type = Result;
183 };
184
185
186 template <template<typename, typename> typename Logic , typename OpType>
187 struct SimpleExecutor : public Logic<SimpleExecutor<Logic, OpType>, OpType>
188 {
189 public:
190 template <typename ...Args>
191 SimpleExecutor( Args &&...args ) : Logic<SimpleExecutor<Logic, OpType>, OpType>( std::forward<Args>(args)...) {}
192 };
193
194
199 #define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType) \
200 using LogicBase<Executor, OpType>::executor; \
201 using LogicBase<Executor, OpType>::makeReadyResult; \
202 template<class T> \
203 using MaybeAsyncRef = typename LogicBase<Executor, OpType>:: template MaybeAsyncRef<T>
204
205
206 template <typename Sub>
207 struct LogicHelper {
208
209 template<class Type>
211
212 virtual ~LogicHelper(){}
213
214 inline Sub *subClass () {
215 return static_cast<Sub *>(this);
216 }
217
218 template <typename T>
219 inline auto makeReadyResult( T &&res ) {
221 }
222 };
223
224#define ZYPP_ENABLE_LOGIC_HELPER(Sub) \
225 using LogicHelper<Sub>::subClass; \
226 using LogicHelper<Sub>::makeReadyResult; \
227 template<class T> \
228 using MaybeAsyncRef = typename LogicHelper<Sub>:: template MaybeAsyncRef<T>
229
230
231}
232
233
234#endif
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Definition Arch.h:364
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:42
typename conditional< B, T, F >::type conditional_t
Definition TypeTraits.h:39
std::conditional_t< detail::is_async_op_v< OpType >, AsyncOpRef< Type >, Type > MaybeAsyncRef
Executor * executor()
static std::enable_if_t< detail::is_async_op_v< FOpType >, AsyncOpRef< Result > > run(Args &&...args)
static std::enable_if_t< !detail::is_async_op_v< FOpType >, Result > run(Args &&...args)
typename OpType::value_type Result
std::enable_if_t< detail::is_async_op_v< FOpType >, void > asyncExecute()
auto makeReadyResult(T &&res)
auto makeReadyResult(T &&res)
std::conditional_t< detail::is_async_op_v< Sub >, AsyncOpRef< Type >, Type > MaybeAsyncRef
SimpleExecutor(Args &&...args)