ConfigParser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <Eigen/Geometry>
5 
11 
14 
16 {
17  std::string createErrorMessageWithContext(std::string message, RapidXmlReaderNode& context);
18 
20  {
21  public:
23  ConfigParser(RapidXmlReaderNode& hardwareConfigNode);
24 
25  /**
26  * @brief Parse the input nodes given in constructor
27  * @throws ParserError if some kind of error occured
28  */
29  void parse();
30 
31  /**
32  * @brief Get warnings that occured during parsing
33  * These are additional messages that the parser generated and are meant to be useful
34  * find logic issues within the file.
35  * @return vector of warning strings
36  */
37  std::vector<std::string>& getWarnings();
38 
39  /**
40  * @brief Get the parsed Config object hierarchy.
41  * If the ConfigParser::Parse did throw an exception the best appoximation is returned.
42  * If ConfigParser::Parse was not called before then the HardwareConfig object is empty.
43  */
45 
46  private:
47  // These are the internal parser functions. They take a reference to a shared ptr to
48  // their config object and create the config within it.
49  // The ...node attribute should point to the xml node that contains all needed other nodes.
50  // For example parseSlave needs the '<Slave ...' node and parseProfiles needs the
51  // '<Profiles>' node.
52  bool parseDevice(std::shared_ptr<DeviceConfig>& deviceConfig,
53  RapidXmlReaderNode& deviceNode);
54 
55  bool parseDeviceProfile(std::shared_ptr<DeviceConfigBase>& deviceConfig,
56  RapidXmlReaderNode& deviceNode);
57 
58  bool parseSubDevice(std::shared_ptr<DeviceConfigBase>& subDeviceConfig,
59  RapidXmlReaderNode& subDeviceNode);
60 
61  bool parseSlave(std::shared_ptr<SlaveConfig>& slaveConfig,
62  RapidXmlReaderNode& slaveNode,
63  SlaveType type);
64 
65  bool parseSlaveProfile(std::shared_ptr<SlaveProfile>& slaveConfig,
66  RapidXmlReaderNode& slaveNode);
67 
68  void parseConfigNode(Config& config, RapidXmlReaderNode& configNode, ConfigTag tag);
69 
70  void parseController(ControllerConfig& config,
71  RapidXmlReaderNode& controllerNode,
72  ConfigTag tag);
73 
74  void parseProfiles(RapidXmlReaderNode& profilesNode);
75 
76  void parseSlaveIdentifier(SlaveIdentifierConfig& identifier,
77  RapidXmlReaderNode& identifierNode,
78  std::optional<std::string> name,
79  ConfigTag tag,
80  bool checkIdentifierValid);
81 
82  /**
83  * @brief Search for a Profile with given name and type.
84  * @param ref The result (if something was found)
85  * @param type device / slave type
86  * @param profileName profilename
87  * @param map The map in which the search should take place
88  * @return If a profile was found
89  */
90  template <typename T>
91  bool findProfile(std::shared_ptr<T>& ref,
92  std::string type,
93  std::string profileName,
94  std::string debugName,
95  std::map<std::string, std::map<std::string, std::shared_ptr<T>>>& map);
96 
97  /**
98  * @brief Parse a list type
99  * @param str The content of the list node
100  * @param func conversion function
101  * @return parsed list
102  */
103  template <typename T>
104  std::list<T> parseList(std::string str, std::function<T(std::string)> func);
105 
106  /**
107  * @brief Parse a matrix
108  * @param str The content of the matrix node
109  * @param func conversion function
110  * @return parsed matrix
111  */
112  template <typename T>
114  parseMatrix(RapidXmlReaderNode& node, std::function<T(std::string)> func);
115 
116  bool strToBool(std::string s);
117 
118  void testSlaveIdentifierUnique(SlaveIdentifierConfig& identifier);
119 
120  // Store the document node
121  MultiNodeRapidXMLReader hardwareConfigNode;
122 
123  // Store parsed data
124  HardwareConfig config;
125 
126  // Profiles for SlaveConfig and DeviceConfig construction with a profile
127  // Type -> Name -> Profile
128  std::map<std::string, std::map<std::string, std::shared_ptr<DeviceConfigBase>>>
129  deviceProfiles;
130  std::map<std::string, std::map<std::string, std::shared_ptr<SlaveProfile>>> slaveProfiles;
131 
132  // References to all SlaveIdentifiers that have been parsed (for testing SlaveIdentifier uniqueness)
133  std::vector<SlaveIdentifierConfig> identifiers;
134 
135  // Store errors from parser
136  std::vector<std::string> errors;
137 
138  // Store warnings from parser
139  std::vector<std::string> warnings;
140  };
141 } // namespace armarx::control::hardware_config
armarx::control::hardware_config::SlaveIdentifierConfig
Data structure holding the information necessary to create a SlaveIdentifier.
Definition: SlaveIdentifierConfig.h:15
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
armarx::MultiNodeRapidXMLReader
Definition: MultiNodeRapidXMLReader.h:34
armarx::control::hardware_config
Definition: Config.cpp:3
armarx::control::hardware_config::ConfigParser::getWarnings
std::vector< std::string > & getWarnings()
Get warnings that occured during parsing These are additional messages that the parser generated and ...
Definition: ConfigParser.cpp:89
armarx::control::hardware_config::ConfigParser::ConfigParser
ConfigParser(MultiNodeRapidXMLReader nodes)
Definition: ConfigParser.cpp:17
armarx::control::hardware_config::ConfigParser
Definition: ConfigParser.h:19
armarx::control::hardware_config::ConfigTag
ConfigTag
The ConfigTag is used when setting a config value.
Definition: Config.h:61
DefaultRapidXmlReader.h
armarx::control::hardware_config::createErrorMessageWithContext
std::string createErrorMessageWithContext(std::string message, const Config &context)
Create an error message that prints part of the current Config object to make it easiier to find the ...
Definition: Config.cpp:326
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:68
SlaveIdentifierConfig.h
HardwareConfig.h
armarx::control::hardware_config::ConfigParser::getHardwareConfig
HardwareConfig & getHardwareConfig()
Get the parsed Config object hierarchy.
Definition: ConfigParser.cpp:95
armarx::control::hardware_config::ConfigParser::parse
void parse()
Parse the input nodes given in constructor.
Definition: ConfigParser.cpp:27
armarx::control::hardware_config::Config
The Config class is the base class of all specialized configurations that have a direct key -> value ...
Definition: Config.h:91
RapidXmlReader.h
MultiNodeRapidXMLReader.h
armarx::control::hardware_config::HardwareConfig
Root of the config structure.
Definition: HardwareConfig.h:14
StringHelperTemplates.h
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
Logging.h
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::control::hardware_config::ControllerConfig
Config with additional Config objects for controllers.
Definition: Config.h:349
armarx::control::hardware_config::SlaveType
SlaveType
Definition: SlaveConfig.h:60