1
2
3
4
5
6 #ifndef SNGXML_DOM_DOCUMENT_INCLUDED
7 #define SNGXML_DOM_DOCUMENT_INCLUDED
8 #include <sngxml/dom/Node.hpp>
9 #include <unordered_map>
10
11 namespace sngxml { namespace dom {
12
13 class Element;
14
15 class Document : public ParentNode
16 {
17 public:
18 Document();
19 Document(const Document&) = delete;
20 Document& operator=(const Document&) = delete;
21 Document(Document&&) = delete;
22 Document& operator=(Document&&) = delete;
23 std::unique_ptr<Node> CloneNode(bool deep) override;
24 Element* DocumentElement() { return documentElement; }
25 void Write(CodeFormatter& formatter) override;
26 Node* InsertBefore(std::std::unique_ptr<Node>&&newChild, Node*refChild) override;
27 std::unique_ptr<Node> ReplaceChild(std::std::unique_ptr<Node>&&newChild, Node*oldChild) override;
28 std::unique_ptr<Node> RemoveChild(Node* oldChild) override;
29 Node* AppendChild(std::std::unique_ptr<Node>&&newChild) override;
30 Element* GetElementById(const std::u32string& elementId);
31 void SetXmlStandalone(bool xmlStandalone_) { xmlStandalone = xmlStandalone_; }
32 bool XmlStandalone() const { return xmlStandalone; }
33 void SetXmlVersion(const std::u32string& xmlVersion_) { xmlVersion = xmlVersion_; }
34 const std::u32string& XmlVersion() const { return xmlVersion; }
35 void SetXmlEncoding(const std::u32string& xmlEncoding_) { xmlEncoding = xmlEncoding_; }
36 const std::u32string& XmlEncoding() const { return xmlEncoding; }
37 void Accept(Visitor& visitor) override;
38 void InternalInvalidateIndex();
39 private:
40 Element* documentElement;
41 void CheckValidInsert(Node* node, Node* refNode);
42 std::unordered_map<std::u32string, Element*> elementsByIdMap;
43 bool indexValid;
44 bool xmlStandalone;
45 std::u32string xmlVersion;
46 std::u32string xmlEncoding;
47 };
48
49 } }
50
51 #endif // SNGXML_DOM_DOCUMENT_INCLUDED
52