libzypp: zyppng::LogicBase< Executor, OpType > Struct Template Reference

libzypp 17.36.6

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
zyppng::LogicBase< Executor, OpType > Struct Template Reference

`#include <zypp/ng/workflows/logichelpers.h>`

Inheritance diagram for zyppng::LogicBase< Executor, OpType >:

## Public Types
using | ExecutorType = Executor
using | Result = typename OpType::value_type
Public Types inherited from zyppng::MaybeAsyncMixin< detail::is_async_op_v< OpType > >
using | MaybeAsyncRef

## Public Member Functions
| LogicBase ()
virtual | ~LogicBase ()
Executor * | executor ()

## Static Public Member Functions
template<typename ... Args, typename FOpType = OpType>
static std::enable_if_t< detail::is_async_op_v< FOpType >, AsyncOpRef< Result > > | run (Args &&...args)
template<typename ... Args, typename FOpType = OpType>
static std::enable_if_t< !detail::is_async_op_v< FOpType >, Result > | run (Args &&...args)

## Private Member Functions
template<typename FOpType = OpType>
std::enable_if_t< detail::is_async_op_v< FOpType >, void > | asyncExecute ()

## Additional Inherited Members
Static Public Attributes inherited from zyppng::MaybeAsyncMixin< detail::is_async_op_v< OpType > >
static constexpr bool | is_async
Protected Member Functions inherited from zyppng::MaybeAsyncMixin< detail::is_async_op_v< OpType > >
auto | makeReadyResult (T &&res)

## Detailed Description

template<typename Executor, typename OpType>
struct zyppng::LogicBase< Executor, OpType >

Logic base class template, this allows us to implement certain workflows in a sync/async agnostic way, based on the OpType the code is either sync or async:

// ------------------ computeint.h ---------------------------
// the public interface for the workflows are just functions, usually with some
// context object just save passing a gazillion of arguments to the func and
// to carry some state.
AsyncOpRef<expected<int>> computeInt( ContextRef context );
expected<int> computeInt( SyncContextRef context );
// ------------------ computeint.cc ---------------------------
namespace {
template <
typename Executor
, typename OpType
>
struct ComputeIntLogic : public LogicBase<Executor, OpType>
{
// declare some helper tools from the base
ZYPP_ENABLE_LOGIC_BASE(Executor, OpType);
// declare our context type based on the OpType we are
using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
// all arguments to the sync/async function are passed to the constructor
LogicImpl( ZyppContextRefType ctx )
: LogicBase<Executor>()
, _ctx( std::move(ctx) )
{}
// every logic type must implement execute() without any arguments, returning
// the result type. In async world the pipeline will be stored in the object until its ready
MaybeAsyncRef<<expected<int>> execute() {
return executor()->computeSomeInt()
| and_then( [this]( int result ) {
std::cout<< "Int calculated as: " << result << std::endl;
return expected<int>::success(result);
});
}
protected:
ZyppContextRefType _ctx;
};
// AsyncOp Executor for ComputeIntLogic implementation,
// here we put all code that can not be implementedin a
// sync/async agnostic way. Usually sending reports to the user.
// If no such code is required, simply use the \ref SimpleExecutor template
class ComputeIntAsyncExecutor : public ComputeIntLogic<ComputeIntAsyncExecutor, AsyncOp<int>>
{
// usually we just want to use Logic's constructors
using ComputeIntLogic<ComputeIntAsyncExecutor, AsyncOp<int>>::ComputeIntLogic;
AsyncOpRef<expected<int>> computeSomeInt() {
// .... some implementation that asynchronously computes a int and returns it
}
};
// SyncOp Executor for ComputeIntLogic implementation,
// here we put all the sync variants of code that can not be implemented in a
// sync/async agnostic way. Usually sending reports to the user.
// If no such code is required, simply use the \ref SimpleExecutor template
class ComputeIntSyncExecutor : public ComputeIntLogic<ComputeIntAsyncExecutor, SyncOp<int>>
{
using ComputeIntLogic<ComputeIntAsyncExecutor, SyncOp<int>>::ComputeIntLogic;
expected<int> computeSomeInt(){
// .... some implementation that synchronously computes a int and returns it
}
};
} //namespace
// by overloading this function on the (Sync)ContextRef type other workflow implementations
// can call the async/sync version just by passing the right parameters
AsyncOpRef<expected<int>> computeInt( ContextRef context ) {
// the run() static method is provided by the LogicBase subclass
return ComputeIntAsyncExecutor::run( std::move(context) );
}
expected<int> computeInt( SyncContextRef context ) {
// the run() static method is provided by the LogicBase subclass
return ComputeIntSyncExecutor::run( std::move(context) );
}
zyppng::expected
Definition expected.h:27
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:115
ZYPP_ENABLE_LOGIC_BASE
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
Definition logichelpers.h:223
std
Definition Arch.h:364
zyppng::AsyncOpRef
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
zyppng::and_then
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition expected.h:423
zyppng::MaybeAsyncContextRef
std::conditional_t< detail::is_async_op_v< OpType >, ContextRef, SyncContextRef > MaybeAsyncContextRef
Definition contextfacade.h:51
zyppng::LogicBase::executor
Executor * executor()
Definition logichelpers.h:186
zyppng::LogicBase::LogicBase
LogicBase()
Definition logichelpers.h:166
zyppng::MaybeAsyncMixin< detail::is_async_op_v< OpType > >::MaybeAsyncRef
std::conditional_t< isAsync, AsyncOpRef< Type >, Type > MaybeAsyncRef
Definition logichelpers.h:44

Definition at line 161 of file logichelpers.h.

## Member Typedef Documentation

## ◆ ExecutorType

template<typename Executor, typename OpType>

using zyppng::LogicBase< Executor, OpType >::ExecutorType = Executor

Definition at line 163 of file logichelpers.h.

## ◆ Result

template<typename Executor, typename OpType>

using zyppng::LogicBase< Executor, OpType >::Result = typename OpType::value_type

Definition at line 164 of file logichelpers.h.

## Constructor & Destructor Documentation

## ◆ LogicBase()

template<typename Executor, typename OpType>

zyppng::LogicBase< Executor, OpType >::LogicBase | ( |  | ) |
| inline

Definition at line 166 of file logichelpers.h.

## ◆ ~LogicBase()

template<typename Executor, typename OpType>

virtual zyppng::LogicBase< Executor, OpType >::~LogicBase | ( |  | ) |
| inlinevirtual

Definition at line 167 of file logichelpers.h.

## Member Function Documentation

## ◆ run() [1/2]

template<typename Executor, typename OpType>
template<typename ... Args, typename FOpType = OpType>

static std::enable_if_t< detail::is_async_op_v< FOpType >, AsyncOpRef< Result > > zyppng::LogicBase< Executor, OpType >::run | ( | Args &&... | args | ) |
| inlinestatic

Definition at line 170 of file logichelpers.h.

## ◆ run() [2/2]

template<typename Executor, typename OpType>
template<typename ... Args, typename FOpType = OpType>

static std::enable_if_t< !detail::is_async_op_v< FOpType >, Result > zyppng::LogicBase< Executor, OpType >::run | ( | Args &&... | args | ) |
| inlinestatic

Definition at line 177 of file logichelpers.h.

## ◆ executor()

template<typename Executor, typename OpType>

Executor * zyppng::LogicBase< Executor, OpType >::executor | ( |  | ) |
| inline

Allows access to functionality provided by the Executor parent class, usually used for sending user reports because those are too different for sync and async.

Definition at line 186 of file logichelpers.h.

## ◆ asyncExecute()

template<typename Executor, typename OpType>
template<typename FOpType = OpType>

std::enable_if_t< detail::is_async_op_v< FOpType >, void > zyppng::LogicBase< Executor, OpType >::asyncExecute | ( |  | ) |
| inlineprivate

Definition at line 192 of file logichelpers.h.

The documentation for this struct was generated from the following file:

- zypp/ng/workflows/logichelpers.h