#include "ParameterDouble.h"
using namespace std;


/*
 * Constructor
 */
ParameterDouble::ParameterDouble(std::string name):m_min(0.0),m_max(1000.0) {

	SetName(name);
	SetValue(0.0);
}


/*
 * Returns log message
 */
string ParameterDouble::ToString() {

	double value;

	GetValue(value);
	ostringstream os;
	os << value;
	
	return os.str();
}


/*
 * Control if setting value is in range
 */
void ParameterDouble::SetValue(const double& value) {

	if ((value<=m_max)&&(value>=m_min)) {

		Parameter<double>::SetValue(value);
	}
	else {

		ostringstream os;
		os << value;
		string strData = os.str();
		Log("Value out of range (" +strData+ ") ");
	} 
}


/*
 * Set limits for min, max turns
 */
void ParameterDouble::SetLimits(const double& min, const double& max) {

	double value;
	GetValue(value);

	// turns are out of the limits!
	if ((min>value)||(max<value)) {

		Log("Error: can't change limits. Turns are out of the limits!");
	}
	else {

		if ((min!=m_min)||(max!=m_max)) {

			//store new value
			m_min = min;
			m_max = max;

			//convert double value to string
			ostringstream os;
			os << "MIN: ";
			os << m_min;
			os << ", MAX: ";
			os << m_max;
			string strData = os.str();

			Log("Limits changed (" +strData+ ")");
		}
		else {

			Log("No need to change");
		}
	}
}


/*
 * Get limits for min, max turns
 */
void ParameterDouble::GetLimits(double& min, double& max) const {

	min = m_min;
	max = m_max;
}