1#ifndef TINYURDF_PROPERTYPARSER_H
2#define TINYURDF_PROPERTYPARSER_H
7#include <unordered_map>
9#include <loguru/loguru.hpp>
41 p_ = std::make_shared<std::unordered_map<std::string,T>>();
44 void print(std::ostream& os)
override {
45 os <<
"Parsed Property-Values = [";
47 for (
const auto& pair : *p_) {
48 if (!first) os <<
", ";
49 os << pair.first <<
"=" << pair.second;
64 return "property_value_parser";
67 bool isA(
const char* name)
override {
68 return std::string(name) ==
"property_value_parser";
71 void parse(
const tinyxml2::XMLElement* xml)
74 const tinyxml2::XMLAttribute* attr = xml->FirstAttribute();
77 if constexpr (std::is_same_v<T, double>) {
80 (*p_)[std::string(attr->Name())] = val;
81 }
else if constexpr (std::is_same_v<T, std::string>) {
82 (*p_)[std::string(attr->Name())] = std::string(attr->Value());
84 LOG_F(ERROR,
"failed to parse attribute: unsupported type for conversion");
90 std::shared_ptr<std::unordered_map<std::string,T>>
get()
override {
return p_;};
95 std::shared_ptr<std::unordered_map<std::string,T>> p_;
Definition parser_base.h:16
A basic parser for general property value definitions in XML. Parses a single XML element where a pro...
Definition property_parser.h:38
PropertyParser()
Definition property_parser.h:40
const char * getTypename() override
Definition property_parser.h:63
void parse(const tinyxml2::XMLElement *xml)
Definition property_parser.h:71
std::shared_ptr< std::unordered_map< std::string, T > > get() override
Definition property_parser.h:90
~PropertyParser()
Definition property_parser.h:92
void clear() override
Definition property_parser.h:59
bool isA(const char *name) override
Definition property_parser.h:67
void print(std::ostream &os) override
Definition property_parser.h:44
bool empty() const override
Definition property_parser.h:55
void str2double(const char *in, double &num_)
a locale-safe version of string-to-double
Definition utils.cc:14