libzypp  17.32.4
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 
14 namespace 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:
25  AsyncOpRef<typename Op::value_type> _innerPipeline;
26  };
27 
28  }
29 
121  template <typename Executor, typename OpType>
122  struct LogicBase : public detail::LogicBaseExec<OpType> {
123 
124  using ExecutorType = Executor;
125  using Result = typename OpType::value_type;
126 
130  template<class Type>
132 
133  LogicBase( ){ }
134  virtual ~LogicBase(){}
135 
136  template <typename ...Args, typename FOpType = OpType>
137  static std::enable_if_t< detail::is_async_op_v<FOpType>, AsyncOpRef<Result>> run( Args &&...args ) {
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 
153  Executor *executor () {
154  return static_cast<Executor *>(this);
155  }
156 
161  template <typename T>
162  inline auto makeReadyResult( T &&res ) {
163  return zyppng::makeReadyResult<T, zyppng::detail::is_async_op_v<OpType>> ( std::forward<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 ) {
220  return zyppng::makeReadyResult<T, zyppng::detail::is_async_op_v<Sub>> ( std::forward<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
virtual ~LogicHelper()
Definition: logichelpers.h:212
SimpleExecutor(Args &&...args)
Definition: logichelpers.h:191
static std::enable_if_t< !detail::is_async_op_v< FOpType >, Result > run(Args &&...args)
Definition: logichelpers.h:144
auto makeReadyResult(T &&res)
Definition: logichelpers.h:162
Definition: Arch.h:363
auto makeReadyResult(T &&res)
Definition: logichelpers.h:219
static std::enable_if_t< detail::is_async_op_v< FOpType >, AsyncOpRef< Result > > run(Args &&...args)
Definition: logichelpers.h:137
typename enable_if< B, T >::type enable_if_t
Definition: TypeTraits.h:42
Executor * executor()
Definition: logichelpers.h:153
virtual ~LogicBase()
Definition: logichelpers.h:134
std::enable_if_t< detail::is_async_op_v< FOpType >, void > asyncExecute()
Definition: logichelpers.h:168
std::conditional_t< detail::is_async_op_v< zyppng::AsyncOp< bool > >, AsyncOpRef< Type >, Type > MaybeAsyncRef
Definition: logichelpers.h:131
typename conditional< B, T, F >::type conditional_t
Definition: TypeTraits.h:39
std::conditional_t< detail::is_async_op_v< Sub >, AsyncOpRef< Type >, Type > MaybeAsyncRef
Definition: logichelpers.h:210