#pragma once #include "block.h" namespace dsp { template class Operator : public block { using base_type = block; public: Operator() {} Operator(stream* a, stream* b) { init(a, b); } virtual void init(stream* a, stream* b) { _a = a; _b = b; base_type::registerInput(_a); base_type::registerInput(_b); base_type::registerOutput(&out); base_type::_block_init = true; } virtual void setInputs(stream* a, stream* b) { assert(_block_init); std::lock_guard lck(ctrlMtx); base_type::tempStop(); base_type::unregisterInput(_a); base_type::unregisterInput(_b); _a = a; _b = b; base_type::registerInput(_a); base_type::registerInput(_b); base_type::tempStart(); } virtual void setInputA(stream* a) { assert(_block_init); std::lock_guard lck(ctrlMtx); base_type::tempStop(); base_type::unregisterInput(_a); _a = a; base_type::registerInput(_a); base_type::tempStart(); } virtual void setInputB(stream* b) { assert(_block_init); std::lock_guard lck(ctrlMtx); base_type::tempStop(); base_type::unregisterInput(_b); _b = b; base_type::registerInput(_b); base_type::tempStart(); } virtual int run() = 0; stream out; protected: stream* _a; stream* _b; }; }