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

libzypp 17.38.15

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
template<class Type>
using | MaybeAsyncRef = MaybeAwaitable<Type>

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

## Static Public Member Functions
template<typename ... Args>
static auto | run (Args &&...args)

## Additional Inherited Members
Static Public Attributes inherited from zyppng::MaybeAsyncMixin
static constexpr bool | is_async = ZYPP_IS_ASYNC

## 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:56
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:178
ZYPP_ENABLE_LOGIC_BASE
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
Definition logichelpers.h:210
std
Definition ansi.h:855
zyppng::and_then
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition expected.h:520
zyppng::LogicBase::executor
Executor * executor()
Definition logichelpers.h:172
zyppng::LogicBase::LogicBase
LogicBase()
Definition logichelpers.h:154
zyppng::MaybeAsyncMixin::MaybeAsyncRef
MaybeAwaitable< Type > MaybeAsyncRef
Definition logichelpers.h:44

Definition at line 149 of file logichelpers.h.

## Member Typedef Documentation

## ◆ ExecutorType

template<typename Executor, typename OpType>

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

Definition at line 151 of file logichelpers.h.

## ◆ Result

template<typename Executor, typename OpType>

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

Definition at line 152 of file logichelpers.h.

## Constructor & Destructor Documentation

## ◆ LogicBase()

template<typename Executor, typename OpType>

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

Definition at line 154 of file logichelpers.h.

## ◆ ~LogicBase()

template<typename Executor, typename OpType>

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

Definition at line 155 of file logichelpers.h.

## Member Function Documentation

## ◆ run()

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

auto zyppng::LogicBase< Executor, OpType >::run | ( | Args &&... | args | ) |
| inlinestatic

Definition at line 158 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 172 of file logichelpers.h.

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

- zypp/ng/workflows/logichelpers.h