Orcus
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 "pstring.hpp"
12#include "types.hpp"
13
14#include <vector>
15#include <ostream>
16#include <memory>
17
18namespace orcus {
19
20class xmlns_context;
21
22namespace sax {
23
24struct doctype_declaration;
25
26}
27
28namespace dom {
29
30class document_tree;
31
32enum class node_t : uint8_t
33{
34 unset,
35 declaration,
36 element,
37};
38
39struct ORCUS_DLLPUBLIC entity_name
40{
41 xmlns_id_t ns;
42 pstring name;
43
45 entity_name(const pstring& _name);
46 entity_name(xmlns_id_t _ns, const pstring& _name);
47
48 bool operator== (const entity_name& other) const;
49 bool operator!= (const entity_name& other) const;
50};
51
52class ORCUS_DLLPUBLIC const_node
53{
54 friend class document_tree;
55
56 struct impl;
57 std::unique_ptr<impl> mp_impl;
58
59 const_node(std::unique_ptr<impl>&& _impl);
60public:
61 const_node();
62 const_node(const const_node& other);
63 const_node(const_node&& other);
64
66
67 node_t type() const;
68
69 size_t child_count() const;
70
71 const_node child(size_t index) const;
72
73 entity_name name() const;
74
75 pstring attribute(const entity_name& name) const;
76 pstring attribute(const pstring& name) const;
77
78 size_t attribute_count() const;
79
80 const_node parent() const;
81
82 void swap(const_node& other);
83
84 const_node& operator= (const const_node& other);
85
86 bool operator== (const const_node& other) const;
87 bool operator!= (const const_node& other) const;
88};
89
93class ORCUS_DLLPUBLIC document_tree
94{
95 struct impl;
96 std::unique_ptr<impl> mp_impl;
97
98public:
99 document_tree(const document_tree&) = delete;
100 document_tree& operator= (const document_tree&) = delete;
101
105
111 void load(const std::string& strm);
112
113 void load(const char* p_strm, size_t n_strm);
114
115 dom::const_node root() const;
116
117 dom::const_node declaration(const pstring& name) const;
118
124 void swap(document_tree& other);
125
126 const sax::doctype_declaration* get_doctype() const;
127
128 void dump_compact(std::ostream& os) const;
129};
130
131} // namespace dom
132
133}
134
135#endif
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: dom_tree.hpp:53
Definition: dom_tree.hpp:94
void swap(document_tree &other)
void load(const std::string &strm)
Definition: pstring.hpp:28
Definition: xml_namespace.hpp:83
Definition: dom_tree.hpp:40
Definition: sax_parser_base.hpp:46