#ifndef __RADIO_BLOCK_H__
#define __RADIO_BLOCK_H__

#include <forward_list>
#include "Exception.hpp"
#include "Buffer.hpp"

namespace Processor
{
class Block
{

	public:
	Block(size_t num_in, size_t num_out)
	: m_num_in(num_in)
	, m_num_out(num_out)
	, m_buf_in(nullptr)
	, m_buf_out(nullptr)
	, m_isEnable(true)
	, m_isBypass(false)
	{

	}
	virtual ~Block() = default;
	
	size_t num_in() const
	{
		return m_num_in;
	}

	size_t num_out() const
	{
  		return m_num_out;
	}
	
	void buffer_in_add(IBuffer *buf)
	{
		m_buf_in = buf;
	}

	void buffer_out_add(IBuffer *buf)
	{
		m_buf_out = buf;
	}

	template <typename T>
	Buffer<T>* buffer_in(size_t index=0)
	{
		Buffer<T> *buf = nullptr;
		if (m_buf_in)
		{
			buf = dynamic_cast<Processor::Buffer<T>*>(m_buf_in);
		}
		if (!buf)
		{
			EXC_EXCEPT(-1);
		}
		return buf;
	}

	template <typename T>
	Buffer<T>* buffer_out(size_t index=0)
	{
		Buffer<T> *buf = nullptr;
		if (m_buf_out)
		{
			buf = dynamic_cast<Processor::Buffer<T>*>(m_buf_out);
		}
		if (!buf)
		{
			EXC_EXCEPT(-1);
		}
		return buf;
	}

	void enable(bool enable)
	{
		m_isEnable = enable;
	}

	void bypass(bool enable)
	{
		m_isBypass = enable;
	}
	
	bool is_enable()
	{
		return m_isEnable;
	}

	bool is_bypass()
	{
		return m_isBypass;
	}

	virtual void process() = 0;
	virtual void prepare() {}

	protected:
	size_t m_num_in;
	size_t m_num_out;
	IBuffer* m_buf_in;
	IBuffer* m_buf_out;
	bool m_isEnable;
	bool m_isBypass;

};


} // Processor

#endif // __RADIO_BLOCK_H__

