Orcus
Loading...
Searching...
No Matches
dom_tree.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8#ifndef INCLUDED_ORCUS_DOM_TREE_HPP
9#define INCLUDED_ORCUS_DOM_TREE_HPP
10
11#include "types.hpp"
12
13#include <vector>
14#include <ostream>
15#include <memory>
16
17namespace orcus {
18
19class xmlns_context;
20
21namespace sax {
22
24
25}
26
27namespace dom {
28
29class document_tree;
30
31enum class node_t : uint8_t
32{
33 unset,
34 declaration,
35 element,
36};
37
38struct ORCUS_DLLPUBLIC entity_name
39{
40 xmlns_id_t ns;
41 std::string_view name;
42
43 entity_name();
44 entity_name(std::string_view _name);
45 entity_name(xmlns_id_t _ns, std::string_view _name);
46
47 bool operator== (const entity_name& other) const;
48 bool operator!= (const entity_name& other) const;
49};
50
51class ORCUS_DLLPUBLIC const_node
52{
53 friend class document_tree;
54
55 struct impl;
56 std::unique_ptr<impl> mp_impl;
57
58 const_node(std::unique_ptr<impl>&& _impl);
59public:
60 const_node();
61 const_node(const const_node& other);
62 const_node(const_node&& other);
63
64 ~const_node();
65
66 node_t type() const;
67
68 size_t child_count() const;
69
70 const_node child(size_t index) const;
71
72 entity_name name() const;
73
74 std::string_view attribute(const entity_name& name) const;
75 std::string_view attribute(std::string_view name) const;
76
77 size_t attribute_count() const;
78
79 const_node parent() const;
80
81 void swap(const_node& other);
82
83 const_node& operator= (const const_node& other);
84
85 bool operator== (const const_node& other) const;
86 bool operator!= (const const_node& other) const;
87};
88
92class ORCUS_DLLPUBLIC document_tree
93{
94 struct impl;
95 std::unique_ptr<impl> mp_impl;
96
97public:
98 document_tree(const document_tree&) = delete;
99 document_tree& operator= (const document_tree&) = delete;
100
101 document_tree(xmlns_context& cxt);
102 document_tree(document_tree&& other);
103 ~document_tree();
104
110 void load(std::string_view strm);
111
112 dom::const_node root() const;
113
114 dom::const_node declaration(std::string_view name) const;
115
121 void swap(document_tree& other);
122
123 const sax::doctype_declaration* get_doctype() const;
124
125 void dump_compact(std::ostream& os) const;
126};
127
128} // namespace dom
129
130}
131
132#endif
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition dom_tree.hpp:52
Definition dom_tree.hpp:93
void swap(document_tree &other)
void load(std::string_view strm)
Definition xml_namespace.hpp:100
Definition dom_tree.hpp:39
Definition sax_parser_base.hpp:37