Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
configParser.cpp
Go to the documentation of this file.
1#include "configParser.hpp"
2
3NodeType::value ConfigElement::getType() { return this->type; }
4
5Node ConfigElement::getNode() { return this->node; }
6
7vector<ConfigElement> ConfigElement::getElements()
8{
9 if (this->type != NodeType::Sequence)
10 {
11 throw runtime_error("Not a sequence but a " + to_string(this->type));
12 }
13
14 vector<ConfigElement> res;
15 for (const_iterator it = this->node.begin(); it != this->node.end(); ++it)
16 {
17 Node child = *it;
18 res.push_back(ConfigElement(child));
19 }
20 return res;
21}
22
24{
25 if (this->type != NodeType::Map)
26 {
27 throw runtime_error("Not a map but a " + to_string(this->type));
28 }
29
30 if (!this->hasElement(elementName))
31 {
32 throw runtime_error(elementName + " is not a member of this config item");
33 }
34 return this->node[elementName];
35}
36
37bool ConfigElement::hasElement(string elementName)
38{
39 if (this->type != NodeType::Map && this->type != NodeType::Scalar)
40 {
41 return false;
42 }
43 if (!this->node[elementName])
44 {
45 return false;
46 }
47 return true;
48}
49
50bool ConfigElement::getElement(ConfigElement* element, string elementName)
51{
52 if (this->type != NodeType::Map && this->type != NodeType::Scalar)
53 {
54 return false;
55 }
56 *element = this->node[elementName];
57 return true;
58}
59
60bool ConfigElement::getElements(vector<ConfigElement>* vec)
61{
62 if (this->type != NodeType::Sequence)
63 {
64 return false;
65 }
66 for (const_iterator it = this->node.begin(); it != this->node.end(); ++it)
67 {
68 Node child = *it;
69 vec->push_back(ConfigElement(child));
70 }
71 return true;
72}
bool hasElement(string elementName)
ConfigElement getElement(string elementName)
NodeType::value getType()
NodeType::value type
vector< ConfigElement > getElements()