Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
configParser.hpp
Go to the documentation of this file.
1#ifndef CONFIGPARSER_HPP
2#define CONFIGPARSER_HPP
3
4#include "rclcpp/rclcpp.hpp"
5#include "types.hpp"
6#include "yaml-cpp/yaml.h"
7#include <memory>
8#include <string>
9#include <vector>
10
11using namespace std;
12using namespace YAML;
13
15{
16public:
18 : node(node)
19 , type(node.Type())
20 {
21 }
22
23 NodeType::value getType();
24 Node getNode();
25 bool hasElement(string elementName);
26 vector<ConfigElement> getElements();
27 ConfigElement getElement(string elementName);
28 bool getElement(ConfigElement* element, string elementName);
29 bool getElements(vector<ConfigElement>* vec);
30 ConfigElement operator[](string elementName)
31 {
32 if (this->type != NodeType::Map)
33 {
34 throw runtime_error("Not a map but a " + to_string(this->type));
35 }
36 return this->node[elementName];
37 }
39 {
40 if (this->type != NodeType::Sequence)
41 {
42 throw runtime_error("Not a sequence but a " + to_string(this->type));
43 }
44 return this->node[i];
45 }
46 template <typename T> inline T getElement(string elementName) { return this->node[elementName].as<T>(); }
47 template <typename T> inline bool getElement(T* res, string elementName)
48 {
49 *res = this->node[elementName].as<T>();
50 return true;
51 }
52
53protected:
54 Node node;
55 NodeType::value type;
56};
57
58class Config : public ConfigElement
59{
60public:
61 Config(string path)
62 : ConfigElement(LoadFile(path))
63 {
64 }
65};
66
67#endif // CONFIGPARSER_HPP
bool hasElement(string elementName)
ConfigElement operator[](int i)
ConfigElement(Node node)
bool getElement(T *res, string elementName)
T getElement(string elementName)
ConfigElement getElement(string elementName)
ConfigElement operator[](string elementName)
NodeType::value getType()
NodeType::value type
vector< ConfigElement > getElements()
Config(string path)
Hash function for cones.
Definition cone.hpp:36