#include "tcl_stringvar.h"

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

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

TclStringVar::TclStringVar(Ptr<TclInterp>& interp):TclVar(interp)
{
	set("");
}

void TclStringVar::set(const string& value)
{
	Tcl_Obj* objValue=Tcl_NewStringObj(value.c_str(),(int)value.size());
	Tcl_ObjSetVar2(interp->getInterp(), objName, 0, objValue, TCL_GLOBAL_ONLY);
}

const char* TclStringVar::get() const
{
	Tcl_Obj* obj=Tcl_ObjGetVar2(interp->getInterp(),objName,0,TCL_GLOBAL_ONLY);

	return Tcl_GetString(obj);
}


void TclStringVar::doSerialize(TiXmlElement& element) const
{
	element.SetAttribute("value",get());
}

void TclStringVar::doDeserialize(const TiXmlElement& element)
{
	const char* value=element.Attribute("value");
	set(value);
}
