53 : name(name_), value(value_) {}
54 [[nodiscard]] std::string_view
getName()
const {
return name; }
55 [[nodiscard]] std::string_view
getValue()
const {
return value; }
56 void setValue(
const char* value_) { value = value_; }
59 assert(!nextAttribute);
60 nextAttribute = attribute;
94 struct ChildIterator {
95 using difference_type = ptrdiff_t;
97 using pointer = value_type*;
98 using reference = value_type&;
99 using iterator_category = std::forward_iterator_tag;
104 ChildIterator operator++() { elem = elem->nextSibling;
return *
this; }
105 [[nodiscard]]
bool operator==(
const ChildIterator& i)
const {
return elem == i.elem; }
109 [[nodiscard]] ChildIterator
begin()
const {
return {elem->firstChild}; }
110 [[nodiscard]] ChildIterator
end()
const {
return {
nullptr}; }
113 struct NamedChildIterator {
114 using difference_type = ptrdiff_t;
116 using pointer = value_type*;
117 using reference = value_type&;
118 using iterator_category = std::forward_iterator_tag;
121 const std::string_view name;
123 NamedChildIterator(
const XMLElement* elem_, std::string_view name_)
124 : elem(elem_), name(name_)
126 while (elem && elem->
getName() != name) {
127 elem = elem->nextSibling;
132 NamedChildIterator operator++() {
134 elem = elem->nextSibling;
135 }
while (elem && elem->
getName() != name);
138 [[nodiscard]]
bool operator==(
const NamedChildIterator& i)
const {
return elem == i.elem; }
140 struct NamedChildRange {
142 std::string_view name;
143 [[nodiscard]] NamedChildIterator
begin()
const {
return {elem->firstChild, name}; }
144 [[nodiscard]] NamedChildIterator
end()
const {
return {
nullptr, std::string_view{}}; }
147 struct AttributeIterator {
148 using difference_type = ptrdiff_t;
150 using pointer = value_type*;
151 using reference = value_type&;
152 using iterator_category = std::forward_iterator_tag;
157 AttributeIterator operator++() { attr = attr->nextAttribute;
return *
this; }
158 [[nodiscard]]
bool operator==(
const AttributeIterator& i)
const {
return attr == i.attr; }
160 struct AttributeRange {
162 [[nodiscard]] AttributeIterator
begin()
const {
return {elem->firstAttribute}; }
163 [[nodiscard]] AttributeIterator
end()
const {
return {
nullptr}; }
168 XMLElement(
const char* name_,
const char* data_) : name(name_), data(data_) {}
170 [[nodiscard]] std::string_view
getName()
const {
return name; }
173 [[nodiscard]] std::string_view
getData()
const {
174 return data ? std::string_view(data) : std::string_view();
187 [[nodiscard]] std::string_view
getChildData(std::string_view childName)
const;
188 [[nodiscard]] std::string_view
getChildData(std::string_view childName,
189 std::string_view defaultValue)
const;
190 [[nodiscard]]
bool getChildDataAsBool(std::string_view childName,
bool defaultValue)
const;
191 [[nodiscard]]
int getChildDataAsInt(std::string_view childName,
int defaultValue)
const;
195 [[nodiscard]] NamedChildRange
getChildren(std::string_view childName)
const {
return {
this, childName}; }
199 [[nodiscard]] std::string_view
getAttributeValue(std::string_view attrName)
const;
201 std::string_view defaultValue)
const;
203 bool defaultValue)
const;
205 int defaultValue)
const;
217 assert(!nextSibling);
218 nextSibling = sibling;
222 assert(!firstAttribute);
223 firstAttribute = attribute;
229 const char* data =
nullptr;
262 template<
typename ...Args>
264 : allocator(
std::forward<Args>(args)...) {}
267 void load(
const std::string& filename, std::string_view systemID);
281 template<
typename Range,
typename UnaryOp>
285 for (
auto& r : range) {
289 next = &elem->nextSibling;
321 template<
typename Archive>
322 void serialize(Archive& ar,
unsigned version);
std::string_view getName() const
XMLAttribute * setNextAttribute(XMLAttribute *attribute)
void setValue(const char *value_)
XMLAttribute(const char *name_, const char *value_)
std::string_view getValue() const
XMLElement * setChildData(XMLElement &parent, const char *childName, const char *childData)
void serialize(MemInputArchive &ar, unsigned version)
XMLElement * getOrCreateChild(XMLElement &parent, const char *childName, const char *childData)
void generateList(XMLElement &parent, const char *itemName, Range &&range, UnaryOp op)
void setRoot(XMLElement *root_)
static XMLDocument & getStaticDocument()
XMLDocument(Args &&...args)
void setAttribute(XMLElement &elem, const char *attrName, const char *attrValue)
const char * allocateString(std::string_view str)
const XMLElement * getRoot() const
XMLElement * allocateElement(const char *name)
XMLAttribute * allocateAttribute(const char *name, const char *value)
void load(const std::string &filename, std::string_view systemID)
std::string_view getName() const
size_t numChildren() const
NamedChildRange getChildren(std::string_view childName) const
XMLElement * setData(const char *data_)
XMLAttribute * setFirstAttribute(XMLAttribute *attribute)
XMLAttribute ** findAttributePointer(std::string_view attrName)
XMLElement * setNextSibling(XMLElement *sibling)
XMLElement(const char *name_)
int getChildDataAsInt(std::string_view childName, int defaultValue) const
AttributeRange getAttributes() const
const XMLAttribute * findAttribute(std::string_view attrName) const
const XMLElement * findChild(std::string_view childName) const
static void removeAttribute(XMLAttribute **attrPtr)
std::string_view getAttributeValue(std::string_view attrName) const
size_t numAttributes() const
int getAttributeValueAsInt(std::string_view attrName, int defaultValue) const
XMLElement * setFirstChild(XMLElement *child)
const XMLAttribute & getAttribute(std::string_view attrName) const
const XMLElement & getChild(std::string_view childName) const
std::string_view getChildData(std::string_view childName) const
std::string_view getData() const
bool getChildDataAsBool(std::string_view childName, bool defaultValue) const
bool getAttributeValueAsBool(std::string_view attrName, bool defaultValue) const
ChildRange getChildren() const
const XMLElement * getFirstChild() const
XMLElement(const char *name_, const char *data_)
This file implemented 3 utility functions:
bool operator==(const Event &x, const Event &y)
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
void serialize(Archive &ar, unsigned version)
std::vector< OldXMLElement > children
std::vector< std::pair< std::string, std::string > > attributes
static std::unique_ptr< FileContext > getLastSerializedFileContext()
constexpr uint128 operator*(const uint128 &a, const uint128 &b)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)