blob: e4f456a29f4538d0f555b98843fb0864a731a71f (
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
|
#include "iHaveParameters.h"
#include "exceptions.h"
#include "appEngine.h"
#include <boost/foreach.hpp>
IHaveParameters::Stack IHaveParameters::scope;
IHaveParameters::IHaveParameters(const xmlpp::Element * p)
{
BOOST_FOREACH(xmlpp::Node * node, p->find("parameters/*")) {
if (const xmlpp::Element * pelem = dynamic_cast<const xmlpp::Element *>(node)) {
parameters.insert(Parameters::value_type(pelem->get_name(), Variable(pelem, boost::optional<Glib::ustring>())));
}
}
}
IHaveParameters::~IHaveParameters()
{
}
VariableType
IHaveParameters::getParameter(const Glib::ustring & name) const
{
Parameters::const_iterator i = parameters.find(name);
if (i != parameters.end()) {
return i->second;
}
throw ParamNotFound(name);
}
void
IHaveParameters::push(const IHaveParameters * p)
{
scope.push_back(p);
}
void
IHaveParameters::pop(const IHaveParameters * p)
{
assert(scope.back() == p);
scope.pop_back();
}
VariableType
IHaveParameters::getScopedParameter(const Glib::ustring & name)
{
for(Stack::const_reverse_iterator ihp = scope.rbegin(); ihp != scope.rend(); ihp++) {
Parameters::const_iterator i = (*ihp)->parameters.find(name);
if (i != (*ihp)->parameters.end()) {
return i->second;
}
}
throw ParamNotFound(name);
}
const IHaveParameters::Parameters &
IHaveParameters::allParameters() const
{
return parameters;
}
|