#include "vardef.h"
#include "varinst.h"
#include "../exceptions/exceptions.h"

const char* VarDef::type="VarDef";
const char* VarDef::getType() const
{
	return type;
}


/// must match var
const char* VarDef::var_names[]=
{
	"bool",
	"char",
	"int",
	"double",
	"string"
};

VarInst* VarDef::instantiate(IModule *m)
{
	VarInst* var;
	switch(itype)
	{
		case VAR_BOOL:
			var=new VarBool(this,m);
			break;
		case VAR_CHAR:
			var=new VarChar(this,m);
			break;
		case VAR_INT:
			var=new VarInteger(this,m);
			break;
		case VAR_DOUBLE:
			var=new VarDouble(this,m);
			break;
		case VAR_STRING:
			var=new VarString(this,m);
			break;
		default:
			throw new Exception("VarDef","Trying to instantiate variable of undefined type (code %d) !",(int)itype);
			break;
	}
	var->setNotification(false);
	if (defval!=0) var->fromString(defval);
	var->setNotification(true);
	return var;
}
