add LambdaBase
This commit is contained in:
parent
3089bccf55
commit
ac9e2af70e
@ -6,6 +6,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "iface/common/dealer.hh"
|
||||
#include "iface/common/exception.hh"
|
||||
#include "iface/common/observer.hh"
|
||||
#include "iface/common/value.hh"
|
||||
|
||||
namespace nf7 {
|
||||
@ -13,10 +15,9 @@ namespace nf7 {
|
||||
class Lambda {
|
||||
public:
|
||||
Lambda() = delete;
|
||||
Lambda(std::shared_ptr<Taker<Value>>&& taker,
|
||||
std::shared_ptr<Maker<Value>>&& maker) noexcept
|
||||
: taker_(std::move(taker)), maker_(maker) {
|
||||
}
|
||||
Lambda(const std::shared_ptr<Taker<Value>>& taker,
|
||||
const std::shared_ptr<Maker<Value>>& maker) noexcept
|
||||
: taker_(std::move(taker)), maker_(maker) { }
|
||||
virtual ~Lambda() = default;
|
||||
|
||||
Lambda(const Lambda&) = delete;
|
||||
@ -32,4 +33,31 @@ class Lambda {
|
||||
const std::shared_ptr<Maker<Value>> maker_;
|
||||
};
|
||||
|
||||
class LambdaBase : public Lambda, private Observer<Value> {
|
||||
public:
|
||||
LambdaBase(DealerMeta&& takerMeta = {}, DealerMeta&& makerMeta = {})
|
||||
try : LambdaBase(std::make_shared<Taker<Value>>(std::move(takerMeta)),
|
||||
std::make_shared<Emitter<Value>>(std::move(makerMeta))) {
|
||||
} catch (const std::bad_alloc&) {
|
||||
throw Exception {"memory shortage"};
|
||||
}
|
||||
|
||||
private:
|
||||
LambdaBase(const std::shared_ptr<Taker<Value>>& taker,
|
||||
const std::shared_ptr<Emitter<Value>>& maker)
|
||||
: Lambda(taker, maker), Observer<Value>(*taker), emitter_(maker) { }
|
||||
|
||||
protected:
|
||||
virtual void Main(const Value&) noexcept = 0;
|
||||
|
||||
const std::shared_ptr<Emitter<Value>>& emitter() const noexcept {
|
||||
return emitter_;
|
||||
}
|
||||
|
||||
private:
|
||||
void Notify(const Value& v) noexcept override { Main(v); }
|
||||
|
||||
const std::shared_ptr<Emitter<Value>> emitter_;
|
||||
};
|
||||
|
||||
} // namespace nf7
|
||||
|
Loading…
x
Reference in New Issue
Block a user