sptk2 logo
SPTK Home Page
Document.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/xdoc/Node.h>
30
31namespace sptk::xdoc {
32
33class SP_EXPORT Document
34{
35public:
36 explicit Document(Node::Type rootType = Node::Type::Object)
37 : m_root(std::make_shared<Node>("", rootType))
38 {
39 }
40
41 void clear() const
42 {
43 m_root->clear();
44 }
45
46 [[nodiscard]] SNode& root()
47 {
48 return m_root;
49 }
50
51 [[nodiscard]] const SNode& root() const
52 {
53 return m_root;
54 }
55
56 void load(const Buffer& data, bool xmlKeepFormatting = false) const;
57
58 void load(const String& data, bool xmlKeepFormatting = false) const;
59
60 void exportTo(DataFormat dataFormat, Buffer& data, bool formatted = false) const
61 {
62 m_root->exportTo(dataFormat, data, formatted);
63 }
64
65 void exportTo(DataFormat dataFormat, std::ostream& data, bool formatted = false) const
66 {
67 m_root->exportTo(dataFormat, data, formatted);
68 }
69
70 [[maybe_unused]] [[nodiscard]] SNode& findOrCreate(const String& name)
71 {
72 return m_root->findOrCreate(name);
73 }
74
75 [[nodiscard]] SNode findFirst(const String& name, SearchMode searchMode = SearchMode::Recursive) const
76 {
77 return m_root->findFirst(name, searchMode);
78 }
79
80 [[nodiscard]] Node::Vector select(const String& xpath) const
81 {
82 return m_root->select(xpath);
83 }
84
85private:
86 SNode m_root;
87};
88
89using SDocument = std::shared_ptr<Document>;
90
91} // namespace sptk::xdoc
Definition: Buffer.h:51
Definition: String.h:49
Definition: Document.h:34

Fri Oct 14 2022 09:58:32: SPTK 5.4.1