summaryrefslogtreecommitdiff
path: root/project2/variables-modparam.cpp
blob: a932412c05647d0a86df07cd1de260ced41030e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "variables.h"
#include "xmlObjectLoader.h"
#include "xmlStorage.h"
#include "appEngine.h"

/// Variable implementation to access call parameters
class VariableParam : public VariableImplDyn {
	public:
		VariableParam(const xmlpp::Element * e) :
			VariableImplDyn(e),
			name(e->get_attribute_value("name"))
		{
		}
		const VariableType & value() const
		{
			if (!cacheValid) {
				try {
					cache = ApplicationEngine::getCurrent()->env()->getParamQuery(name);
				}
				catch (ParamNotFound) {
					if (!defaultValue) {
						throw;
					}
					cache = (*defaultValue)();
				}
				cacheValid = true;
			}
			return cache;
		}
	private:
		const Glib::ustring name;
};
DECLARE_COMPONENT_LOADER("param", VariableParam, VariableLoader);