13 #ifndef ARGOS_CONFIGURATION_H
14 #define ARGOS_CONFIGURATION_H
16 #include <argos3/core/utility/datatypes/datatypes.h>
17 #include <argos3/core/utility/configuration/argos_exception.h>
18 #include <argos3/core/utility/configuration/tinyxml/ticpp.h>
45 const std::string& str_tag)
throw() {
47 it = it.begin(&t_node);
64 const std::string& str_tag) {
67 it = it.begin(&t_node);
73 catch(ticpp::Exception& ex) {
91 t_parent_node.InsertEndChild(t_child_node);
93 catch(ticpp::Exception& ex) {
127 template <
typename T>
131 t_node.GetText(&t_buffer);
133 catch(std::exception& ex) {
151 template <
typename T>
154 const T& t_default) {
156 t_node.GetTextOrDefault(&t_buffer, t_default);
158 catch(std::exception& ex) {
173 const std::string& str_attribute) {
174 return t_node.HasAttribute(str_attribute);
207 template <
typename T>
209 const std::string& str_attribute,
212 t_node.GetAttribute(str_attribute, &t_buffer,
true);
214 catch(ticpp::Exception& ex) {
232 const std::string& str_attribute,
234 std::string strBuffer;
236 t_node.GetAttribute(str_attribute, &strBuffer,
true);
237 if(strBuffer ==
"true") {
240 else if(strBuffer ==
"false") {
244 THROW_ARGOSEXCEPTION(
"Cannot convert '" << strBuffer <<
"' into a bool. Accepted values: 'true', 'false'.");
247 catch(ticpp::Exception& ex) {
265 const std::string& str_attribute,
269 t_node.GetAttribute(str_attribute, &unTmpBuffer,
true);
270 un_buffer = unTmpBuffer;
272 catch(ticpp::Exception& ex) {
290 const std::string& str_attribute,
294 t_node.GetAttribute(str_attribute, &nTmpBuffer,
true);
295 n_buffer = nTmpBuffer;
297 catch(ticpp::Exception& ex) {
317 template <
typename T>
319 const std::string& str_attribute,
321 const T& t_default) {
323 t_node.GetAttributeOrDefault(str_attribute, &t_buffer, t_default);
325 catch(ticpp::Exception& ex) {
345 const std::string& str_attribute,
347 const bool b_default) {
348 std::string strBuffer;
349 const std::string strDefault = (b_default ?
"true" :
"false");
351 t_node.GetAttributeOrDefault(str_attribute, &strBuffer, strDefault);
352 if(strBuffer ==
"true") {
355 else if(strBuffer ==
"false") {
359 THROW_ARGOSEXCEPTION(
"Cannot convert '" << strBuffer <<
"' into a bool. Accepted values: 'true', 'false'.");
362 catch(ticpp::Exception& ex) {
382 const std::string& str_attribute,
384 const UInt8 un_default) {
387 t_node.GetAttributeOrDefault(str_attribute, &unTmpBuffer,
static_cast<UInt32>(un_default));
388 un_buffer = unTmpBuffer;
390 catch(ticpp::Exception& ex) {
410 const std::string& str_attribute,
412 const SInt8 n_default) {
415 t_node.GetAttributeOrDefault(str_attribute, &nTmpBuffer,
static_cast<SInt32>(n_default));
416 n_buffer = nTmpBuffer;
418 catch(ticpp::Exception& ex) {
433 template <
typename T>
435 const std::string& str_attribute,
437 t_node.SetAttribute(str_attribute, t_value);
452 const std::string& str_attribute,
453 const bool b_value) {
455 t_node.SetAttribute(str_attribute,
"true");
458 t_node.SetAttribute(str_attribute,
"false");
474 const std::string& str_attribute,
475 const SInt8 n_value) {
476 t_node.SetAttribute(str_attribute,
static_cast<SInt32>(n_value));
491 const std::string& str_attribute,
492 const UInt8 un_value) {
493 t_node.SetAttribute(str_attribute,
static_cast<UInt32>(un_value));
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
signed int SInt32
32-bit signed integer.
unsigned int UInt32
32-bit unsigned integer.
unsigned char UInt8
8-bit unsigned integer.
signed char SInt8
8-bit signed integer.
The namespace containing all the ARGoS related code.
void SetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, const T &t_value)
Sets the value of the wanted node's attribute.
ticpp::Iterator< ticpp::Element > TConfigurationNodeIterator
The iterator for the ARGoS configuration XML node.
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
bool NodeAttributeExists(TConfigurationNode &t_node, const std::string &str_attribute)
Returns true if the specified attribute of a node exists.
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
bool NodeExists(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns true if one of its child nodes has the wanted name.
ticpp::Iterator< ticpp::Attribute > TConfigurationAttributeIterator
The iterator for the attributes of an XML node.
void AddChildNode(TConfigurationNode &t_parent_node, TConfigurationNode &t_child_node)
Adds an XML node as child of another XML node.
void GetNodeTextOrDefault(TConfigurationNode &t_node, T &t_buffer, const T &t_default)
Returns the text of the passed XML node, or the passed default value.
void GetNodeText(TConfigurationNode &t_node, T &t_buffer)
Returns the text of the passed XML node A node text is as follows:
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.