summaryrefslogtreecommitdiff
path: root/project2/common/execContext.cpp
blob: aaf725e7e4416c4df5c4420338fdb1b79b515f85 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "execContext.h"
#include "logger.h"
#include "presenter.h"
#include "rowSet.h"
#include "iHaveParameters.h"

void
ExecContext::logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m)
{
	if (writeLog) {
		Logger()->messagebf(LOG_NOTICE, "%s: %s: %s", __PRETTY_FUNCTION__, g, m);
	}
	messages.push_back(std::make_shared<Message>(g, m));
}

void
ExecContext::addContextData(const MultiRowSetPresenter * p) const
{
	// Message log
	p->addNewRowSet("messages", Scripts::scriptNamespacePrefix);
	p->addNewArray("message", true);
	for (const Messages::value_type & m : messages) {
		p->addNewRow("message");
		p->addAttribute("group", m->group);
		p->addAttribute("text", m->message);
		p->finishRow();
	}
	p->finishArray(true);
	p->finishRowSet();
}

ExecContext::Message::Message(const Glib::ustring & g, const Glib::ustring & m) :
	group(g),
	message(m)
{
}

void
ExecContext::RowValuesPush(const RowState * rs)
{
	rowValuesStack.push_back(rs);
}

void
ExecContext::RowValuesPop()
{
	rowValuesStack.pop_back();
}

const RowState *
ExecContext::RowValues(size_t depth) const
{
	if (depth < 1 || depth > rowValuesStack.size()) {
		throw RowSet::ParentOutOfRange(depth);
	}
	return rowValuesStack.at(rowValuesStack.size() - depth);
}

void
ExecContext::ParametersPush(const IHaveParameters * p)
{
	parameterStack.push_back(p);
}

void
ExecContext::ParametersPop()
{
	parameterStack.pop_back();
}

VariableType
ExecContext::getScopedParameter(const Glib::ustring & name)
{
	for(auto ihp = parameterStack.rbegin(); ihp != parameterStack.rend(); ++ihp) {
		auto i = (*ihp)->allParameters().find(name);
		if (i != (*ihp)->allParameters().end()) {
			return i->second(this);
		}
	}
	throw ParamNotFound(name);
}