#include "stdafx.h"		//Precompiled header file

#include "CalcLibCalc.h"

const int CalcLibCalc_status_ok = 1;

void CalcLibCalc::initValues(DOUBLEVECTOR values, DATEVECTOR dates)
{

	unsigned length = values.size();

	for (int i = 0; i < length; i++)
	{
		double value = values.at(i);					//Get the double from the vector
		COleDateTime date = dates.at(i);				//Get the date from the vector
		CalcLibData cld = CalcLibData(value, date);		//Create an object with value and date
		m_input.push_back(cld);							//Add the object to the end of the input vector
		cld = CalcLibData();							//Create an empty object 
		cld.setDate(date);								//Set it's date explicitly
		cld.setStatus(cld.getUndefined());
		m_output.push_back(cld);						//Add the object to the end of the output vector
	}
}

void CalcLibCalc::initValues(DOUBLEVECTOR values)
{
	unsigned length = values.size();

	for (int i = 0; i < length; i++)
	{
		double value = values.at(i);
		CalcLibData cld = CalcLibData(value);
		m_input.push_back(cld);
		cld = CalcLibData();
		m_output.push_back(cld);
	}

}

CalcLibData CalcLibCalc::getOutputPointByIndex(int index)
{
	CalcLibData retval = NULL;

	if (index >= 0 && index < m_output.size())
	{
		retval = m_output.at(index);
	}

	return retval;
}

CalcLibData CalcLibCalc::getOutputPointByDate(COleDateTime date)
{
	CalcLibData retval = NULL;
	int length = m_output.size();

	for (int i = 0; i < length; i++)
	{
		CalcLibData cld = m_output.at(i);

		if (cld.getStatus() != cld.getUndefined() && date == cld.getDate())
		{
			retval = cld;
			break;
		}
	}
	return retval;
}

bool CalcLibCalc::getFirstDefinedPoint(CalcLibData &d)
{
	bool retval = false;
	int length = m_output.size();

	for (int i = 0; i < length; i++)
	{
		CalcLibData cld = m_output.at(i);

		if (cld.getStatus() != cld.getUndefined())
		{
			retval = true;
			d = cld;
			break;
		}
	}
	return retval;
}

int CalcLibCalc::getFirstDefinedPointIndex()
{
	int retval = -1;
	int length = m_output.size();

	for (int i = 0; i < length; i++)
	{
		CalcLibData cld = m_output.at(i);

		if (cld.getStatus() != cld.getUndefined())
		{
			retval = i;
			break;
		}
	}
	return retval;
}

