// XmlMemberValidation_Interval.cpp
//

#include "stdafx.h"
#include "XmlMemberValidation_Interval.h"

CXmlMemberValidation_Interval::CXmlMemberValidation_Interval()
{
	SetDefaults();
}

CXmlMemberValidation_Interval::~CXmlMemberValidation_Interval()
{
	Clear();
}

bool CXmlMemberValidation_Interval::BuildFromXml(IXMLDOMNode* node)
{
	Clear();

	ExtractMemberNode(node,	_T("MinValue"), minValue_);
	ExtractMemberNode(node,	_T("MaxValue"), maxValue_);
	ExtractMemberNode(node,	_T("Precision"), precision_);
		
	return true;
}

bool CXmlMemberValidation_Interval::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	bool ret;
	HRESULT hr;

	hr = xmlDoc->createElement(CComBSTR((const TCHAR*)GetXmlNodeName()), &newElement);

	ret = CXmlBaseElement::AppendToDOMDocument(xmlDoc, newElement);
	if (!ret)
		return false;

	// serialize members
	//
	AppendMemberNode(_T("MinValue"), minValue_, precision_, newElement, xmlDoc);
	AppendMemberNode(_T("MaxValue"), maxValue_, precision_, newElement, xmlDoc);
	AppendMemberNode(_T("Precision"), precision_, newElement, xmlDoc);
	
	// append node to parent element
	//
	IXMLDOMNode* newOutNode;

	if (parentElement)
		hr = parentElement->appendChild(newElement, &newOutNode);
	else
		hr = xmlDoc->appendChild(newElement, &newOutNode);
	newOutNode->Release();

	return ret;
}
	

void CXmlMemberValidation_Interval::SetMinValue(double minValue)
{
	minValue_ = minValue;
}

double CXmlMemberValidation_Interval::GetMinValue() const
{
	return minValue_;
}

void CXmlMemberValidation_Interval::SetMaxValue(double maxValue)
{
	maxValue_ = maxValue;
}

double CXmlMemberValidation_Interval::GetMaxValue() const
{
	return maxValue_;
}

void CXmlMemberValidation_Interval::Clear()
{
	SetDefaults();
	
}
	
void CXmlMemberValidation_Interval::SetDefaults()
{
	minValue_ = 0;
	maxValue_ = 0;
	precision_ = 0;
}

void CXmlMemberValidation_Interval::SetPrecision(int precision)
{
	precision_ = precision;
}

int CXmlMemberValidation_Interval::GetPrecision() const
{
	return precision_;
}
