Go to the documentation of this file.
34 #include <experimental/source_location>
55 std::string
name()
const override
57 return "armarx::exceptions::local::RapidXmlWrapperException";
74 std::shared_ptr<rapidxml::xml_document<> > doc;
75 std::shared_ptr<char[]> cstr;
77 : node(node), doc(doc), cstr(cstr)
79 void check(
const std::string& msg =
"",
85 std::stringstream
str;
86 str <<
"RapidXmlWrapper NullPointerException\n"
87 <<
"from " << location.file_name() <<
':' << location.line()
88 <<
" (" << location.function_name() <<
")\nTrace:\n";
91 str <<
"\nmsg: " << msg;
92 throw exceptions::local::RapidXmlReaderException(
str.str());
96 char* get_attrib_value(
const char* attrName)
const
104 throw exceptions::local::RapidXmlReaderException(std::string(
"Attribute '") + attrName +
"' does not exist in node " +
getPath());
107 return attrib->value();
114 std::stringstream
str;
151 if (n.has_attribute_with_value(attrName, attrValue))
158 std::vector<RapidXmlReaderNode>
nodes(
const char*
name =
nullptr)
const
161 std::vector<RapidXmlReaderNode> vec;
165 void nodes(
const char*
name, std::vector<RapidXmlReaderNode>& vec)
const
173 void nodes(
const char* name1,
const char* name2, std::vector<RapidXmlReaderNode>& vec)
const
181 std::vector<RapidXmlReaderNode>
nodes(
const char* name1,
const char* name2)
const
183 std::vector<RapidXmlReaderNode> vec;
184 nodes(name1, name2, vec);
187 std::vector<RapidXmlReaderNode>
nodes(
const char* name1,
const char* name2,
const char* name3)
const
189 std::vector<RapidXmlReaderNode> vec;
193 n.nodes(name2, name3, vec);
200 return std::string(get_attrib_value(attrName));
222 return std::string(attrib->value()) == std::string(attrValue);
235 return std::string(attrib->value());
238 bool attribute_as_bool(
const char* attrName,
const std::string& trueValue,
const std::string& falseValue)
const
240 std::string
value = std::string(get_attrib_value(attrName));
242 if (
value == trueValue)
246 else if (
value == falseValue)
266 std::string
value = std::string(attrib->value());
268 if (
value == trueValue)
272 else if (
value == falseValue)
284 return static_cast<float>(atof(get_attrib_value(attrName)));
289 std::stringstream strValue(get_attrib_value(attrName));
291 strValue >> retValue;
298 std::vector<std::pair<std::string, std::string>> attributes;
304 std::string
name = std::string(attrib->name());
305 std::string
value = std::string(attrib->value());
316 return std::string(node->value());
322 return static_cast<float>(atof(node->value()));
340 return static_cast<int32_t
>(std::stoul(node->value(),
nullptr, 0));
346 return static_cast<int16_t
>(std::stoul(node->value(),
nullptr, 0));
352 return std::string(node->name());
371 return std::string(childNode->value());
384 return std::string(childNode->value());
394 return node !=
nullptr;
405 result = std::string(p->name()) +
"/" + result;
417 static void collect_child_names(std::vector<std::string>& out,
const RapidXmlReaderNode& n,
const std::string& pre)
421 const auto cs = n.
nodes();
425 out.emplace_back(
name);
429 for (
const auto&
c : cs)
431 collect_child_names(out,
c,
name);
438 std::vector<std::string> result;
450 std::shared_ptr<rapidxml::xml_document<> > doc;
451 std::shared_ptr<char[]> cstr;
456 cstr.reset(
new char[xml.size() + 1]);
457 strcpy(cstr.get(), xml.c_str());
458 doc->parse<0>(cstr.get());
465 std::string absolutePath;
466 if (path.front() ==
'/')
476 std::ifstream t(absolutePath);
477 if (!found || !t.is_open())
483 t.seekg(0, std::ios::end);
484 str.reserve(t.tellg());
485 t.seekg(0, std::ios::beg);
487 str.assign((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
static RapidXmlReaderPtr FromFile(const std::string &path)
experimental::source_location source_location
unsigned int toUInt(const std::string &input)
RapidXmlReaderNode next_sibling(const char *name=nullptr) const
int16_t value_as_int16() const
xml_node< Ch > * next_sibling(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets next sibling node, optionally matching node name.
static std::string ReadFileContents(const std::string &path)
RapidXmlReaderNode first_node_with_attr_value(const char *tagName, const char *attrName, const char *attrValue) const
static RapidXmlReaderPtr FromXmlString(const std::string &xml)
rapidxml::node_type type()
xml_attribute< Ch > * next_attribute(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets next attribute, optionally matching attribute name.
bool attribute_as_optional_bool(const char *name, const std::string &trueValue, const std::string &falseValue, bool defaultValue) const
static RapidXmlReaderNode NullNode()
std::string attribute_value(const char *attrName) const
std::string name() const override
std::string getParentPath() const
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
RapidXmlReaderNode getDocument()
std::vector< std::string > getChildPaths() const
xml_attribute< Ch > * first_attribute(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets first attribute of node, optionally matching attribute name.
std::vector< RapidXmlReaderNode > nodes(const char *name1, const char *name2) const
std::vector< std::pair< std::string, std::string > > get_all_attributes() const
uint32_t attribute_as_uint(const char *attrName) const
Class representing attribute node of XML document.
bool attribute_as_bool(const char *attrName, const std::string &trueValue, const std::string &falseValue) const
float attribute_as_float(const char *attrName) const
bool has_node(const char *nodeName) const
bool has_attribute(const char *attrName) const
rapidxml::xml_node * get_node_ptr() const
get_node_ptr only for legacy code.
RapidXmlReaderNode parent_node() const
float value_as_float() const
uint16_t value_as_uint16() const
RapidXmlReaderException(const std::string &message) noexcept
void nodes(const char *name, std::vector< RapidXmlReaderNode > &vec) const
bool has_attribute_with_value(const char *attrName, const char *attrValue) const
std::string tagName(ConfigTag tag)
void nodes(const char *name1, const char *name2, std::vector< RapidXmlReaderNode > &vec) const
xml_node< Ch > * first_node(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets first child node, optionally matching node name.
This class represents root of the DOM hierarchy.
std::string value() const
std::string getPath() const
std::vector< RapidXmlReaderNode > nodes(const char *name1, const char *name2, const char *name3) const
std::string toString() const
Class representing a node of XML document.
node_type
Enumeration listing all node types produced by the parser.
node_type type() const
Gets type of node.
int32_t value_as_int32() const
std::string first_node_value_or_default(const char *name, const std::string &defaultValue) const
~RapidXmlReaderException() noexcept override
std::vector< RapidXmlReaderNode > nodes(const char *name=nullptr) const
uint32_t value_as_uint32() const
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
RapidXmlReaderNode first_node(const char *name=nullptr) const
std::string first_node_value(const char *nodeName=nullptr) const
static void PrintExceptionBacktrace(std::ostream &out, const std::string &pre="")
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string attribute_value_or_default(const char *attrName, const std::string &defaultValue) const
RapidXmlReaderNode getRoot(const char *name=nullptr)