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