File: dom_tree.hpp

package info (click to toggle)
liborcus 0.7.0%2Bdfsg-9
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,416 kB
  • ctags: 3,153
  • sloc: cpp: 18,133; sh: 11,224; xml: 2,836; makefile: 928; python: 351
file content (114 lines) | stat: -rw-r--r-- 2,775 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef __ORCUS_DOM_TREE_HPP__
#define __ORCUS_DOM_TREE_HPP__

#include "pstring.hpp"
#include "types.hpp"

#include <vector>
#include <ostream>

#include <boost/ptr_container/ptr_vector.hpp>

namespace orcus {

class xmlns_context;
struct dom_tree_impl;

/**
 * Ordinary DOM tree representing the structure of a XML content in full.
 */
class ORCUS_DLLPUBLIC dom_tree
{
    dom_tree(const dom_tree&); // disabled
    dom_tree& operator= (const dom_tree&); // disabled

public:

    struct entity_name
    {
        xmlns_id_t ns;
        pstring name;

        entity_name();
        entity_name(xmlns_id_t _ns, const pstring& _name);

        void print(std::ostream& os, const xmlns_context& cxt) const;
    };

    struct attr
    {
        entity_name name;
        pstring value;

        attr(xmlns_id_t _ns, const pstring& _name, const pstring& _value);

        void print(std::ostream& os, const xmlns_context& cxt) const;
    };

    typedef std::vector<attr> attrs_type;

    enum node_type { node_element, node_content };

    struct node
    {
        node_type type;

        node(node_type _type) : type(_type) {}

        virtual ~node() = 0;
        virtual void print(std::ostream& os, const xmlns_context& cxt) const = 0;
    };

    typedef boost::ptr_vector<node> nodes_type;

    struct element : public node
    {
        entity_name name;
        attrs_type attrs;
        nodes_type child_nodes;

        element(xmlns_id_t _ns, const pstring& _name);
        virtual void print(std::ostream& os, const xmlns_context& cxt) const;
        virtual ~element();
    };

    typedef std::vector<element*> element_stack_type;

    struct content : public node
    {
        pstring value;

        content(const pstring& _value);
        virtual void print(std::ostream& os, const xmlns_context& cxt) const;
        virtual ~content();
    };

    dom_tree(xmlns_context& cxt);
    ~dom_tree();

    void start_declaration(const pstring& name);
    void end_declaration(const pstring& name);
    void start_element(xmlns_id_t ns, const pstring& name);
    void end_element(xmlns_id_t ns, const pstring& name);
    void set_characters(const pstring& val);
    void set_attribute(xmlns_id_t ns, const pstring& name, const pstring& val);

    const attrs_type* get_declaration_attributes(const pstring& name) const;

    void dump_compact(std::ostream& os) const;

private:
    dom_tree_impl* mp_impl;
};

}

#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */