summaryrefslogtreecommitdiff
path: root/project2/common/variables/session.cpp
blob: d3331c04e15c4eaa6dcf9405d35089266bc03542 (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
#include <pch.hpp>
#include "../variables.h"
#include "../execContext.h"
#include "../scriptLoader.h"
#include "../scriptStorage.h"

/// Variable implementation to access session contents
class VariableSession : public VariableImplDyn {
	public:
		VariableSession(ScriptNodePtr e) :
			VariableImplDyn(e),
			name(e->value("name", NULL).as<Glib::ustring>())
		{
		}
		VariableType value(ExecContext * ec) const
		{
			try {
				return ec->getSession()->GetValue(name);
			}
			catch (Session::VariableNotFound) {
				if (!defaultValue) {
					throw;
				}
				return (*defaultValue)(ec);
			}
		}
	private:
		const Glib::ustring name;
};
NAMEDFACTORY("session", VariableSession, VariableFactory);