Cogs.Core
VariableReader.cpp
1#include "VariableReader.h"
2
3#include "Foundation/Logging/Logger.h"
4
5#include "Context.h"
6
7#include "Services/Variables.h"
8
9#include "ReaderCommon.h"
10
11namespace
12{
13 Cogs::Logging::Log logger = Cogs::Logging::getLogger("VariableReader");
14}
15
16void Cogs::Core::readVariables(Variables & variables, const Value & section, const std::string & sectionHeader, bool defaults)
17{
18 for (auto & m : section.GetObject()) {
19 auto jsonKey = toKey(m.name);
20
21 auto key = sectionHeader.size() ? (sectionHeader + "." + jsonKey.to_string()) : jsonKey.to_string();
22
23 // If the variables we are reading are default values, only touch empty variables. Ensures e.g. command line
24 // variables take precedence over default config.
25 if (defaults && !variables.get(key)->isEmpty()) continue;
26
27 switch (m.value.GetType())
28 {
29 case kStringType:
30 variables.set(key, m.value.GetString());
31 break;
32 case kNumberType:
33 variables.set(key, m.value.GetDouble());
34 break;
35 case kTrueType:
36 variables.set(key, true);
37 break;
38 case kFalseType:
39 variables.set(key, false);
40 break;
41 case kObjectType:
42 readVariables(variables, m.value, key, defaults);
43 break;
44 case kArrayType:
45 {
46 auto arr = m.value.GetArray();
47 if (arr.Size() == 4) {
48 glm::vec4 value;
49 readArray(m.value, value, nullptr);
50 variables.set(key, value);
51 }
52 break;
53 }
54 default:
55 break;
56 }
57 }
58}
Log implementation class.
Definition: LogManager.h:139
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180