File: ProgramVariables.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (61 lines) | stat: -rw-r--r-- 1,613 bytes parent folder | download | duplicates (2)
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 "ProgramVariables.h"

namespace actions {
namespace expression {

ProgramVariablesDefinition& ProgramVariablesDefinition::addScope(const SCP_string& name)
{
	auto scope = std::unique_ptr<ProgramVariablesDefinition>(new ProgramVariablesDefinition());

	auto scopePtr = scope.get();

	m_scopes.insert(std::make_pair(name, std::move(scope)));

	return *scopePtr;
}
void ProgramVariablesDefinition::addMember(const SCP_string& name, ValueType type)
{
	m_memberTypes[name] = type;
}
ProgramVariablesDefinition* ProgramVariablesDefinition::getScope(const SCP_string& name) const
{
	const auto iter = m_scopes.find(name);

	if (iter == m_scopes.cend()) {
		return nullptr;
	}

	return iter->second.get();
}
ValueType ProgramVariablesDefinition::getMemberType(const SCP_string& name) const
{
	const auto iter = m_memberTypes.find(name);

	if (iter == m_memberTypes.cend()) {
		return ValueType::Invalid;
	}

	return iter->second;
}

Value ProgramVariables::getValue(std::initializer_list<const char*> memberPathParts) const
{
	return getValue<decltype(memberPathParts)>(memberPathParts);
}
void ProgramVariables::setValue(std::initializer_list<const char*> memberPathParts, Value value)
{
	setValue<decltype(memberPathParts)>(memberPathParts, std::move(value));
}
Value ProgramVariables::getValue(const SCP_string& fullMemberName) const
{
	const auto iter = m_values.find(fullMemberName);

	// This should have been validated earlier
	Assertion(iter != m_values.end(), "Could not find member %s in variables!", fullMemberName.c_str());

	return iter->second;
}

} // namespace expression
} // namespace actions