/*
 * $Id: environment.h,v 1.4 2008-09-14 20:12:51 kybav1 Exp $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __PARAMETER_H__
#define __PARAMETER_H__

#include <wx/event.h>
#include "common.h"
#include "moddefs.h"
#include "textparser.h"
#include "VrutApi.h"

namespace VRUT
{
	class Module;

	///Parameter data
	class VRUT_CORE_API Parameter
	{
	public:
		///Full parameter identifier
		struct VRUT_CORE_API ParameterIdentifier
		{
			///Pool identifier
			wxString poolName;
			///Parameter identifier
			wxString paramName;
			///Pool instance identifier
			wxString instName;
			///parameter description (short help, used also for ToolTip in GUI)
			wxString description;

			///Constructor
			ParameterIdentifier(const wxString & pool = wxT("*"), const wxString & param = wxT("*"), const wxString & inst = wxT("*"), const wxString & _description = wxT(""))
				: poolName(pool), paramName(param), instName(inst), description(_description)  {}
			///Constructor - from module
			ParameterIdentifier(const wxString & pool, const wxString & param, const MODULE_ID &moduleID, const wxString & _description=wxT(""))
				: poolName(pool), paramName(param), instName(wxString::Format(wxT("%lu"), (unsigned long)moduleID.GetInstanceID())), description(_description)   {}
			ParameterIdentifier(const wxString & pool, const wxString & param, const MODULE_INSTANCE_ID &moduleInstanceID, const wxString & _description=wxT(""))
				: poolName(pool), paramName(param), instName(wxString::Format(wxT("%lu"), (unsigned long)moduleInstanceID)), description(_description)   {}
			///Copy constructor
			ParameterIdentifier(const ParameterIdentifier & pi)
				: poolName(CloneWxString(pi.poolName)), paramName(CloneWxString(pi.paramName)), instName(CloneWxString(pi.instName)), description(CloneWxString(pi.description))  {}

			///Comparison
			bool operator==(const ParameterIdentifier & pi) const
			{
				return pi.poolName.IsSameAs(poolName) && pi.paramName.IsSameAs(paramName) && pi.instName.IsSameAs(instName);
			}
			///Comparison
			bool operator!=(const ParameterIdentifier & pi) const
			{
				return !operator==(pi);
			}
			///Comparison
			bool Matches(const ParameterIdentifier & maskPi) const
			{
				return poolName.Matches(maskPi.poolName) && paramName.Matches(maskPi.paramName) && instName.Matches(maskPi.instName);
			}
			///Check if valid - \c poolName and \c paramName must be defined without any '*' or '?'
			bool IsValid() const
			{
				return !poolName.IsEmpty() && !paramName.IsEmpty() && (poolName.Find('*') == wxNOT_FOUND) && (poolName.Find('?') == wxNOT_FOUND) && (paramName.Find('*') == wxNOT_FOUND)
					&& (paramName.Find('?') == wxNOT_FOUND);
			}
			///Create from full param name format 'pool.param[.inst]'
			///Should be checked if valid afterwards
			static ParameterIdentifier FromParamName(const wxString & fullName)
			{
				TextParser textParser(fullName.utf8_str());
				ParameterIdentifier pi;
				if (!textParser.IsEmpty())
					pi.poolName = textParser.GetWxStringUtf8(".");
				if (!textParser.IsEmpty())
					pi.paramName = textParser.GetWxStringUtf8(".");
				if (!textParser.IsEmpty())
					pi.instName = textParser.GetWxStringUtf8(". \t\n\r");
				return pi;
			}
			///Get full parameter name in 'pool.param.inst' format
			wxString ToString() const
			{
				return poolName+wxT(".")+paramName+wxT(".")+instName;
			}
			///Get deep copy
			ParameterIdentifier * Clone() const
			{
				return new ParameterIdentifier(*this);
			}
		};

		///Value
		wxString value;

		///Class constructor
		Parameter(const wxString _value = wxEmptyString) : value(CloneWxString(_value)) {}
	};
}

#endif
