libzypp 17.37.17
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
34 template <bool isAsync>
36 {
37 // Make the isAsync flag accessible for subclasses.
38 static constexpr bool is_async = isAsync;
39
43 template<class Type>
45
46
47 protected:
52 template <typename T>
53 inline auto makeReadyResult( T &&res ) {
54 return zyppng::makeReadyResult<T, isAsync> ( std::forward<T>(res) );
55 }
56 };
57
62 #define ZYPP_ENABLE_MAYBE_ASYNC_MIXIN( IsAsync ) \
63 using MaybeAsyncMixin<IsAsync>::makeReadyResult; \
64 template<class T> \
65 using MaybeAsyncRef = typename MaybeAsyncMixin<IsAsync>:: template MaybeAsyncRef<T>
66
67
68
160 template <typename Executor, typename OpType>
161 struct LogicBase : public detail::LogicBaseExec<OpType>, public MaybeAsyncMixin<detail::is_async_op_v<OpType>> {
162
163 using ExecutorType = Executor;
164 using Result = typename OpType::value_type;
165
167 virtual ~LogicBase(){}
168
169 template <typename ...Args, typename FOpType = OpType>
171 auto op = std::make_shared<Executor>( std::forward<Args>(args)... );
172 op->asyncExecute();
173 return op;
174 }
175
176 template <typename ...Args, typename FOpType = OpType>
178 return Executor( std::forward<Args>(args)... ).execute();
179 }
180
181
186 Executor *executor () {
187 return static_cast<Executor *>(this);
188 }
189
190 private:
191 template <typename FOpType = OpType>
193 this->_innerPipeline = static_cast<Executor*>(this)->execute();
194 this->_innerPipeline->onReady([this]( auto &&val ){
195 this->setReady( std::forward<decltype(val)>(val) );
196 });
197 }
198 };
199
204 template <typename Result>
205 struct SyncOp : public Base {
206 using value_type = Result;
207 };
208
209
210 template <template<typename, typename> typename Logic , typename OpType>
211 struct SimpleExecutor : public Logic<SimpleExecutor<Logic, OpType>, OpType>
212 {
213 public:
214 template <typename ...Args>
215 SimpleExecutor( Args &&...args ) : Logic<SimpleExecutor<Logic, OpType>, OpType>( std::forward<Args>(args)...) {}
216 };
217
218
223 #define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType) \
224 using LogicBase<Executor, OpType>::executor; \
225 using LogicBase<Executor, OpType>::makeReadyResult; \
226 template<class T> \
227 using MaybeAsyncRef = typename LogicBase<Executor, OpType>:: template MaybeAsyncRef<T>
228}
229#endif
Definition Arch.h:364
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
typename conditional< B, T, F >::type conditional_t
Definition TypeTraits.h:39
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
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()
std::conditional_t< isAsync, AsyncOpRef< Type >, Type > MaybeAsyncRef
auto makeReadyResult(T &&res)
static constexpr bool is_async
SimpleExecutor(Args &&...args)