24 #include "../../Atomicrex.h" 26 #include <libxml/tree.h> 27 #include <libxml/parser.h> 28 #include <libxml/xinclude.h> 29 #include <libxml/xmlschemastypes.h> 30 #ifndef LIBXML_XINCLUDE_ENABLED 31 #error "Program requires libxml2 with XInclude support." 33 #ifndef LIBXML_SCHEMAS_ENABLED 34 #error "Program requires libxml2 with XSD Schema support." 54 template<
class T,
class D>
55 static std::unique_ptr<T, D> make_scoped(T*
const ptr, D deleter) {
56 return std::unique_ptr<T, D>(ptr, deleter);
60 inline FPString toFPString(
const xmlChar* s) {
return (
const char*)s; }
74 Element(xmlNodePtr e =
nullptr) : _el(e) {}
81 int parseIntParameterElement(
const char* tagName)
const;
85 int parseOptionalIntParameterElement(
const char* tagName,
int defaultValue)
const;
89 double parseFloatParameterElement(
const char* tagName)
const;
93 double parseOptionalFloatParameterElement(
const char* tagName,
double defaultValue)
const;
97 FPString parseStringParameterElement(
const char* tagName)
const;
105 FPString parsePathParameterElement(
const char* tagName)
const;
113 double parseFloatParameterAttribute(
const char* attributeName)
const;
117 double parseOptionalFloatParameterAttribute(
const char* attributeName,
double defaultValue)
const;
121 int parseIntParameterAttribute(
const char* attributeName)
const;
125 int parseOptionalIntParameterAttribute(
const char* attributeName,
int defaultValue)
const;
129 FPString parseStringParameterAttribute(
const char* attributeName)
const;
133 FPString parseOptionalStringParameterAttribute(
const char* attributeName,
const FPString& defaultValue =
FPString())
const;
137 FPString parsePathParameterAttribute(
const char* attributeName)
const;
141 bool parseBooleanParameterAttribute(
const char* attributeName)
const;
145 bool parseOptionalBooleanParameterAttribute(
const char* attributeName,
bool defaultValue)
const;
148 Element firstChildElement()
const;
151 Element firstChildElement(
const char* tagName)
const;
154 Element expectChildElement(
const char* tagName)
const;
157 explicit operator bool() const noexcept {
return _el !=
nullptr; }
160 bool tagEquals(
const char* tagName)
const;
163 void expectTag(
const char* tagName)
const;
166 bool hasAttribute(
const char* attrName)
const;
169 int lineNumber()
const;
175 Element nextSibling(
const char* tagName)
const;
178 const char*
tag()
const {
return (
const char*)_el->name; }
181 explicit operator xmlNodePtr() const noexcept {
return _el; }
184 Element createIntParameterElement(
const char* tagName,
int value);
187 Element createFloatParameterElement(
const char* tagName,
double value);
190 Element createStringParameterElement(
const char* tagName,
const FPString& value);
193 int attributeCount()
const;
196 void appendChild(
OElement& element);
199 void appendChild(
OElement&& element);
202 void setAttribute(
const char* attr,
const FPString& value);
205 void setTagName(
const FPString& tagName);
209 void setTextContent(
const FPString& text);
231 OElement() :
std::unique_ptr<xmlNode, void(*)(xmlNodePtr)>(nullptr, xmlFreeNode) {}
237 explicit operator bool() const noexcept {
return _el !=
nullptr; }
const char * tag() const
Returns the tag name of this element.
Definition: XMLUtilities.h:178
OElement()
Constructor that creates a null element.
Definition: XMLUtilities.h:231
Element(xmlNodePtr e=nullptr)
Constructor that takes a LibXml element.
Definition: XMLUtilities.h:74
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
Definition: XMLUtilities.h:43
xmlNodePtr _el
The internal pointer to the xmllib element.
Definition: XMLUtilities.h:218
std::string FPString
The default string type used throughout the code:
Definition: Atomicrex.h:70
Definition: XMLUtilities.h:226
Definition: XMLUtilities.h:69