Loading [MathJax]/extensions/tex2jax.js
azure-storage-common
All Classes Functions Variables Pages
xml_wrapper.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include <cstdint>
7#include <memory>
8#include <string>
9
10namespace Azure { namespace Storage { namespace _internal {
11
12 enum class XmlNodeType
13 {
14 StartTag,
15 EndTag,
16 Text,
17 Attribute,
18 End,
19 };
20
21 struct XmlNode final
22 {
23 explicit XmlNode(XmlNodeType type, std::string name = std::string())
24 : Type(type), Name(std::move(name))
25 {
26 }
27
28 explicit XmlNode(XmlNodeType type, std::string name, std::string value)
29 : Type(type), Name(std::move(name)), Value(std::move(value)), HasValue(true)
30 {
31 }
32
33 XmlNodeType Type;
34 std::string Name;
35 std::string Value;
36 bool HasValue = false;
37 };
38
39 class XmlReader final {
40 public:
41 explicit XmlReader(const char* data, size_t length);
42 XmlReader(const XmlReader& other) = delete;
43 XmlReader& operator=(const XmlReader& other) = delete;
44 XmlReader(XmlReader&& other) noexcept;
45 XmlReader& operator=(XmlReader&& other) noexcept;
46 ~XmlReader();
47
48 XmlNode Read();
49
50 private:
51 struct XmlReaderContext;
52 std::unique_ptr<XmlReaderContext> m_context;
53 };
54
55 class XmlWriter final {
56 public:
57 explicit XmlWriter();
58 XmlWriter(const XmlWriter& other) = delete;
59 XmlWriter& operator=(const XmlWriter& other) = delete;
60 XmlWriter(XmlWriter&& other) noexcept;
61 XmlWriter& operator=(XmlWriter&& other) noexcept;
62 ~XmlWriter();
63
64 void Write(XmlNode node);
65
66 std::string GetDocument();
67
68 private:
69 struct XmlWriterContext;
70 std::unique_ptr<XmlWriterContext> m_context;
71 };
72
73}}} // namespace Azure::Storage::_internal