#ifndef _VARDEF_H_
#define _VARDEF_H_

#include "../tobject.h"
#include "../exceptions/modexception.h"
#include <string.h>

class IModule;
class VarInst;

/**
 * \brief Class defining module variables.
 * 
 * \date 01-29-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo
 *
 * \bug 
 *
 */
class VarDef:public TObject
{
public:
	/// variable instance types
	typedef enum itypes
	{
		VAR_BOOL=0,
		VAR_CHAR=1,
		VAR_INT=2,
		VAR_DOUBLE=3,
		VAR_STRING=4
	};
private:
	static const char* var_names[];
	const char *name;
	const char *descr;
	const char *defval;
	const itypes itype;
	/// empty ctor - acts as "last element in variables definition array"
	VarDef():name(0),descr(0),itype(VAR_BOOL) {}
public:
	static const char* type;
	const char* getType() const;

	/// return name of variable
	inline const char* getName() const
	{
		return name;
	}

	/// return variable description
	inline const char* getDescr() const
	{
		return descr;
	}

	/// return variable instance type
	inline const itypes getIType() const
	{
		return itype;
	}
	
	/// return variable instance type name
	inline const char* getITypeName() const
	{
		return var_names[(int)itype];
	}

	/**
	 * \brief ctor
	 * \param name unique identifier, representating name of variable
	 * \param descr description of variable
	 * \param itype one of VAR_BOOL,VAR_CHAR,VAR_INT,VAR_DOUBLE,VAR_STRING
	 */
	VarDef(const char* name,const char* descr,const itypes itype):name(name),descr(descr),itype(itype),defval(0)
	{
	}

	/**
	 * \brief ctor
	 * \param name unique identifier, representating name of variable  
	 * \param descr description of variable
	 * \param itype one of VAR_BOOL,VAR_CHAR,VAR_INT,VAR_DOUBLE,VAR_STRING
	 * \param defval default value of variable
	 * \return 
	 */
	VarDef(const char* name,const char* descr,const itypes itype,const char* defval):name(name),descr(descr),itype(itype),defval(defval)
	{
		//for(unsigned int i=0;i<strlen(name);i++)
		//	if (name[i]<'a'||name[i]>'z') throw(ModuleException("VarDef","Name of variable can contain only characters 'a'-'z'."));
	}

	inline bool operator==(const VarDef& varDef) const
	{
		return name==varDef.name;
	}

	/**
	 * \brief Create variable instance in module instance.
	 * \param m module instance
	 * \return variable instance
	 */
	VarInst* instantiate(IModule* m);
};

#endif/*_VARDEF_H_*/
