#include "tk_booloption.h"
#include "../../../exceptions/exceptions.h"

const char* TkBoolOption::type="TkBoolOption";

const char* TkBoolOption::getType() const
{
	return type;
}

const string TkBoolOption::TRUE_VALUE="1";
const string TkBoolOption::FALSE_VALUE="0";

void TkBoolOption::doSerialize(TiXmlElement& element) const
{
	element.SetAttribute("value",value?1:0);
}

void TkBoolOption::doDeserialize(const TiXmlElement& element)
{
	int intValue;
	element.Attribute("value",&intValue);
	value=(intValue!=0);
}

TkBoolOption::TkBoolOption()
{
	this->value=false;
}

TkBoolOption::TkBoolOption(bool value)
{
	this->value=value;
}

const string& TkBoolOption::toString() const
{
	return value?TRUE_VALUE:FALSE_VALUE;
}

void TkBoolOption::fromObject(Tcl_Obj* object)
{
	int intValue;
	Tcl_GetBooleanFromObj(TclInterp::defaultInterp->getInterp(),object,&intValue);
	value=(intValue!=0);
}

