48 using std::runtime_error::runtime_error;
51#ifndef DOXYGEN_SHOULD_IGNORE_THIS
53inline std::string trim(
const std::string& str)
55 auto start = std::find_if_not(str.begin(), str.end(), ::isspace);
56 auto end = std::find_if_not(str.rbegin(), str.rend(), ::isspace).base();
57 return (start < end) ? std::string(start, end) : std::string();
96 if constexpr (std::is_same_v<T, bool>) {
99 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
103 else if (str ==
"false") {
107 if (!(iss >> value)) {
108 throw std::invalid_argument(
"Failed to convert attribute value [" + iss.str() +
"] to the specified type");
161 template <
typename T>
164 static_assert(!std::is_same_v<T, bool>,
"Do not use getTextAs with bool type. Simply assign true. (The presence of the node means true.)");
167 if (iss.str().empty()) {
171 using ValueType = std::conditional_t<
172 std::is_same_v<T, char>
173 || std::is_same_v<T, uint8_t>
174 || std::is_same_v<T, char16_t>
175 || std::is_same_v<T, char32_t>, int, T>;
176 ValueType value = ValueType(defaultValue);
178 if (!(iss >> value)) {
179 throw std::invalid_argument(
"Failed to convert text content [" + iss.str() +
"] to the specified type");
196 virtual std::shared_ptr<IXmlAttribute>
findAttribute(
const std::string& name)
const = 0;
Interface for an XML attribute.
Definition XmlInterface.h:65
std::string getValueTrimmed() const
Gets the text content of the attribute with whitespace trimmed.
Definition XmlInterface.h:84
virtual std::string getValue() const =0
Gets the value of the attribute.
virtual std::shared_ptr< IXmlAttribute > nextAttribute() const =0
Advances to the next attribute.
T getValueAs() const
Gets the value of the attribute, converted to the specified type.
Definition XmlInterface.h:93
virtual std::string getName() const =0
Gets the name of the attribute.
Interface for an XML document.
Definition XmlInterface.h:230
virtual std::shared_ptr< IXmlElement > getRootElement() const =0
Gets the root element of the document.
virtual void loadFromString(const std::string &xmlContent)=0
Loads XML content from a string.
virtual void loadFromString(const std::vector< char > &xmlContent)=0
Loads XML content from a vector of characters.
Interface for an XML element.
Definition XmlInterface.h:133
virtual XmlElementPtr getPreviousSibling(const std::string &tagName={}) const =0
Gets the previous sibling element.
virtual XmlElementPtr getParent() const =0
Gets the parent element.
virtual XmlElementPtr getNextSibling(const std::string &tagName={}) const =0
Gets the next sibling element.
virtual std::shared_ptr< IXmlAttribute > getFirstAttribute() const =0
Gets the first attribute.
virtual std::string getText() const =0
Gets the text content of the element.
std::string getTextTrimmed() const
Gets the text content of the element with whitespace trimmed.
Definition XmlInterface.h:152
T getTextAs(T defaultValue={}) const
Gets the text content of the element, converted to the specified type.
Definition XmlInterface.h:162
virtual XmlElementPtr getFirstChildElement(const std::string &tagName={}) const =0
Finds the first child element.
virtual std::shared_ptr< IXmlAttribute > findAttribute(const std::string &name) const =0
Finds the first attribute.
virtual std::string getTagName() const =0
Gets the tag name of the element.
Exception for load xml error.
Definition XmlInterface.h:46
std::tuple< const std::string_view, XmlElementPopulator< T > > XmlElementDescriptor
associates an xml node name with and XmlElementPopulator
Definition XmlInterface.h:125
std::vector< XmlElementDescriptor< T > > XmlElementArray
an array type for XmlElementDescriptor instances.
Definition XmlInterface.h:127
std::shared_ptr< IXmlElement > XmlElementPtr
shared pointer to IXmlElement
Definition XmlInterface.h:121
std::function< void(const XmlElementPtr &, const std::shared_ptr< T > &)> XmlElementPopulator
function type for populating a field from an IXmlElement
Definition XmlInterface.h:123
object model for musx file (enigmaxml)
Definition BaseClasses.h:32