#include "tk_optiondef.h"
#include "../../../exceptions/exceptions.h"

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

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

void TkOptionDef::doSerialize(TiXmlElement& element) const
{
	element.SetAttribute("name",name.c_str());
	element.SetAttribute("optionType",optionType);
	element.SetAttribute("quote",quote?1:0);
	element.SetAttribute("simpleOption",simpleOption?1:0);
}

void TkOptionDef::doDeserialize(const TiXmlElement& element)
{
	int intValue;

	name=element.Attribute("name");
	
	const char* cOptionType=element.Attribute("optionType");
	optionType=TXmlObject::getClassUid(cOptionType);
	if (optionType==0) throw new ExceptionNullPtr(cOptionType);
	
	element.Attribute("quote",&intValue);
	quote=(intValue!=0);
	
	element.Attribute("simpleOption",&intValue);
	simpleOption=(intValue!=0);
}

TkOptionDef::TkOptionDef():
	name(""),optionType(0),quote(true),simpleOption(true)
{
}
	
TkOptionDef::TkOptionDef(const string& name,const char* optionType,bool quote,bool simpleOption):
	name(name),optionType(optionType),quote(quote),simpleOption(simpleOption) 
{
}

TkOptionDef::TkOptionDef(const string& name,const char* optionType,bool quote):
	name(name),optionType(optionType),quote(quote),simpleOption(true) 
{
}

TkOptionDef::TkOptionDef(const string& name,const char* optionType):
	name(name),optionType(optionType),quote(true),simpleOption(true) 
{
}
