载入中...
搜索中...
未找到
Xml.h
浏览该文件的文档.
1#pragma once
2
3// Lightweight read-only XML facade for config / tileset documents (e.g. Tiled
4// TSX). Self-contained recursive-descent parser — no Poco — so EVCommon stays
5// dependency-free and modules that only need attribute-oriented XML do not pull
6// the full Poco DOM stack. Writing XML is out of scope; use data::XmlDocument
7// (Poco) only for legacy mutable encode/decode round-trips.
8//
9// Accessors never throw: a missing attribute or tag yields the supplied
10// default (or an empty Element).
11
12#include "common/Export.h"
13
14#include <cstddef>
15#include <memory>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20namespace eve::xml {
21
22struct Node;
23class Document;
24
30public:
31 Element() = default;
32
34 explicit operator bool() const { return node_ != nullptr; }
35
36 bool operator==(const Element& other) const { return node_ == other.node_; }
37 bool operator!=(const Element& other) const { return node_ != other.node_; }
38
40 std::string tagName() const;
41
43 Element parent() const;
44
45 bool hasAttribute(const char* name) const;
46 std::string getAttribute(const char* name, const std::string& fallback = {}) const;
47 int getIntAttribute(const char* name, int fallback = 0) const;
48
53 std::vector<Element> children(const char* tag = nullptr) const;
54
59 std::vector<Element> elementsByTag(const char* tag) const;
60
61private:
62 friend class Document;
63 explicit Element(const Node* node) : node_(node) {}
64 const Node* node_ = nullptr;
65};
66
71public:
74 Document(Document&&) noexcept;
75 Document& operator=(Document&&) noexcept;
76 Document(const Document&) = delete;
77 Document& operator=(const Document&) = delete;
78
83 static Document parse(const std::string& text, std::string* error = nullptr);
84
85 bool valid() const { return root_ != nullptr; }
86 Element root() const { return Element(root_.get()); }
87
88private:
89 std::unique_ptr<Node> root_;
90};
91
92} // namespace eve::xml
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string text
std::int32_t parent
std::string name
bool valid
const std::string * tag
std::string error
Definition Package.cpp:60
const RoadNode * node
int children
Definition TreeMesh.cpp:295
Element root() const
Definition Xml.h:86
Document(Document &&) noexcept
bool operator==(const Element &other) const
Definition Xml.h:36
bool operator!=(const Element &other) const
Definition Xml.h:37