basic-xml 1.0.1
Very basic loader/writer of XML tags with attributes and content.
node.h
Go to the documentation of this file.
1// Copyright (c) 2019-2024 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/prinbee
4// contact@m2osw.com
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18#pragma once
19
20
27// C++
28//
29#include <deque>
30#include <map>
31#include <memory>
32#include <ostream>
33#include <vector>
34
35
36
37namespace basic_xml
38{
39
40
41
42class node
43 : public std::enable_shared_from_this<node>
44{
45public:
46 typedef std::shared_ptr<node> pointer_t;
47 typedef std::map<std::string, pointer_t>
48 map_t;
49 typedef std::weak_ptr<node> weak_pointer_t;
50 typedef std::map<std::string, std::string>
51 attribute_map_t;
52 typedef std::vector<pointer_t> vector_t;
53 typedef std::deque<pointer_t> deque_t;
54
55 node(std::string const & name);
56
57 std::string const & tag_name() const;
58 std::string text(bool trim = true) const;
59 void set_text(std::string const & text);
60 void append_text(std::string const & text);
61 attribute_map_t all_attributes() const;
62 std::string attribute(std::string const & name) const;
63 void set_attribute(std::string const & name, std::string const & value);
64 void append_child(pointer_t n);
65
66 pointer_t root() const;
67 pointer_t parent() const;
68 pointer_t first_child() const;
69 pointer_t last_child() const;
70 pointer_t next() const;
71 pointer_t previous() const;
72
73private:
74 std::string const f_name;
75 std::string f_text = std::string();
76 attribute_map_t f_attributes = attribute_map_t();
77
78 pointer_t f_next = pointer_t();
79 weak_pointer_t f_previous = weak_pointer_t();
80
81 pointer_t f_child = pointer_t();
82 weak_pointer_t f_parent = weak_pointer_t();
83};
84
85
86extern std::string convert_to_entity(std::string const & raw, std::string const & which);
87extern std::ostream & operator << (std::ostream & out, node const & n);
88
89
90
91} // namespace basic_xml
92// vim: ts=4 sw=4 et

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.