00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __ENVIRONMENT_H__
00013 #define __ENVIRONMENT_H__
00014
00015 #include <wx/hashmap.h>
00016 #include <vector>
00017 #include "parameter.h"
00018
00019
00021 #ifndef REGISTER_PARAM
00022 #define REGISTER_PARAM(paramId, value) \
00023 { wxCommandEvent paramEvt = Event::GET_EVT_PARAM_REGISTER(paramId, value); \
00024 PostToKernel(paramEvt); }
00025 #endif // REGISTER_PARAM
00026
00028 #ifndef SET_PARAM
00029 #define SET_PARAM(paramId, value) \
00030 { wxCommandEvent paramEvt = Event::GET_EVT_PARAM_SET_DO(paramId, value, false); \
00031 PostToKernel(paramEvt); }
00032 #endif // SET_PARAM
00033
00035 #ifndef SET_DEFAULT_PARAM
00036 #define SET_DEFAULT_PARAM(paramId, value) \
00037 { wxCommandEvent paramEvt = Event::GET_EVT_PARAM_SET_DO(paramId, value, true); \
00038 PostToKernel(paramEvt); }
00039 #endif // SET_DEFAULT_PARAM
00040
00042 #define IS_PARAM(_evt, _paramID) \
00043 Parameter::ParameterIdentificator::FromEvent(_evt) == _paramID
00044
00047 #ifndef UPDATE_PARAM_FROM_EVENT_STRING
00048 #define UPDATE_PARAM_FROM_EVENT_STRING(paramId, target, event) \
00049 { \
00050 if (IS_PARAM(event, paramId)) \
00051 target = ((wxString *)event.GetClientData())->AfterFirst('='); \
00052 }
00053 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00054
00057 #ifndef UPDATE_PARAM_FROM_EVENT_INT
00058 #define UPDATE_PARAM_FROM_EVENT_INT(paramId, target, event) \
00059 { \
00060 if (IS_PARAM(event, paramId)) \
00061 { \
00062 long val = 0; \
00063 if (((wxString *)event.GetClientData())->AfterFirst('=').ToLong(&val)) \
00064 target = int(val); \
00065 else \
00066 LOGERROR(wxT("<Param>Invalid parameter type")); \
00067 } \
00068 }
00069 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00070
00073 #ifndef UPDATE_PARAM_FROM_EVENT_LONG
00074 #define UPDATE_PARAM_FROM_EVENT_LONG(paramId, target, event) \
00075 { \
00076 if (IS_PARAM(event, paramId)) \
00077 { \
00078 long val = 0; \
00079 if (((wxString *)event.GetClientData())->AfterFirst('=').ToLong(&val)) \
00080 target = val; \
00081 else \
00082 LOGERROR(wxT("<Param>Invalid parameter type")); \
00083 } \
00084 }
00085 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00086
00089 #ifndef UPDATE_PARAM_FROM_EVENT_UNSIGNED
00090 #define UPDATE_PARAM_FROM_EVENT_UNSIGNED(paramId, target, event) \
00091 { \
00092 if (IS_PARAM(event, paramId)) \
00093 { \
00094 long val = 0; \
00095 if (((wxString *)event.GetClientData())->AfterFirst('=').ToLong(&val)) \
00096 target = unsigned(val); \
00097 else \
00098 LOGERROR(wxT("<Param>Invalid parameter type")); \
00099 } \
00100 }
00101 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00102
00105 #ifndef UPDATE_PARAM_FROM_EVENT_ID
00106 #define UPDATE_PARAM_FROM_EVENT_ID(paramId, target, event) \
00107 { \
00108 if (IS_PARAM(event, paramId)) \
00109 { \
00110 long val = 0; \
00111 if (((wxString *)event.GetClientData())->AfterFirst('=').ToLong(&val)) \
00112 target = VRUT::_ID(val); \
00113 else \
00114 LOGERROR(wxT("<Param>Invalid parameter type")); \
00115 } \
00116 }
00117 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00118
00121 #ifndef UPDATE_PARAM_FROM_EVENT_FLOAT
00122 #define UPDATE_PARAM_FROM_EVENT_FLOAT(paramId, target, event) \
00123 { \
00124 if (IS_PARAM(event, paramId)) \
00125 { \
00126 double val = 0; \
00127 if (((wxString *)event.GetClientData())->AfterFirst('=').ToDouble(&val)) \
00128 target = float(val); \
00129 else \
00130 LOGERROR(wxT("<Param>Invalid parameter type")); \
00131 } \
00132 }
00133 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00134
00137 #ifndef UPDATE_PARAM_FROM_EVENT_BOOl
00138 #define UPDATE_PARAM_FROM_EVENT_BOOL(paramId, target, event) \
00139 { \
00140 if (IS_PARAM(event, paramId)) \
00141 target = isTrue(((wxString *)event.GetClientData())->AfterFirst('=')); \
00142 }
00143 #endif // UPDATE_PARAM_FROM_EVENT_STRING
00144
00145
00146
00147 namespace VRUT
00148 {
00149 class Module;
00150
00152 class Environment
00153 {
00154 protected:
00156 WX_DECLARE_STRING_HASH_MAP(Parameter, InstParamList);
00158 WX_DECLARE_STRING_HASH_MAP(InstParamList, NameInstParamList);
00160 WX_DECLARE_STRING_HASH_MAP(NameInstParamList, PoolNameInstParamList);
00161
00163 PoolNameInstParamList registeredParameters;
00164
00165 public:
00166 typedef std::pair<wxString, wxString> NameValue;
00167
00169 Environment();
00171 ~Environment();
00172
00176 wxString GetParam(const Parameter::ParameterIdentificator & paramId) const;
00180 void GetParams(const Parameter::ParameterIdentificator & paramId, std::vector<NameValue> * values) const;
00187 bool SetParam(const Parameter::ParameterIdentificator & paramId, const wxString & value, bool forceDefault = false);
00192 bool RegisterParam(const Parameter::ParameterIdentificator & paramId, const wxString & value);
00196 bool UnregisterParam(const Parameter::ParameterIdentificator & paramId);
00200 void ApplyPendingParams(Module * module, const wxString altName = wxEmptyString);
00201 };
00202 };
00203
00204
00205 #endif