/*
 * ValuePrinterAbstraction.hpp
 *
 *  Created on: 11. 7. 2017
 *	  Author: Jan Travnicek
 */

#ifndef _VALUE_PRINTER_ABSTRACTION_HPP_
#define _VALUE_PRINTER_ABSTRACTION_HPP_

#include <memory>

#include <abstraction/NaryOperationAbstraction.hpp>
#include <abstraction/ValueOperationAbstraction.hpp>

namespace abstraction {

template < class ParamType >
class ValuePrinterAbstraction : virtual public NaryOperationAbstraction < ParamType >, virtual public ValueOperationAbstraction < void > {
	std::ostream & m_ostream;

public:
	ValuePrinterAbstraction ( std::ostream & os ) : m_ostream ( os ) {
	}

	std::shared_ptr < abstraction::Value > run ( ) override {
		std::pair < std::shared_ptr < abstraction::Value >, bool > & param = std::get < 0 > ( this->getParams ( ) );
		m_ostream << retrieveValue < const ParamType & > ( param.first, param.second ) << std::endl;
		return std::make_shared < abstraction::Void > ( this->getProxyAbstraction ( ) );
	}
};

template < >
class ValuePrinterAbstraction < void > : virtual public NaryOperationAbstraction < >, virtual public ValueOperationAbstraction < void > {
public:
	ValuePrinterAbstraction ( std::ostream & ) {
	}

	std::shared_ptr < abstraction::Value > run ( ) override {
		return std::make_shared < abstraction::Void > ( this->getProxyAbstraction ( ) );
	}
};

} /* namespace abstraction */

#endif /* _VALUE_PRINTER_ABSTRACTION_HPP_ */
