TGUI  1.6.1
Loading...
Searching...
No Matches
DataIO.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_DATA_IO_HPP
26#define TGUI_DATA_IO_HPP
27
29
30#include <TGUI/String.hpp>
31
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
33 #include <sstream>
34 #include <memory>
35 #include <vector>
36 #include <string>
37 #include <map>
38 #include <cstdio>
39#endif
40
42
43TGUI_MODULE_EXPORT namespace tgui
44{
49 class TGUI_API DataIO
50 {
51 public:
52 struct ValueNode;
53
57 struct Node
58 {
59 Node() = default;
60 Node(Node&&) = default;
61 Node& operator=(const Node&) = delete; // Not implemented because current code has no use for it
62 Node& operator=(Node&&) = default;
63
64 Node(const Node& other) :
65 parent{other.parent},
66 children{},
67 propertyValuePairs{},
68 name{other.name}
69 {
70 for (const auto& child : other.children)
71 children.push_back(std::make_unique<Node>(*child));
72 for (const auto& pair : other.propertyValuePairs)
73 propertyValuePairs[pair.first] = std::make_unique<ValueNode>(*pair.second);
74 }
75
76 Node* parent = nullptr;
77 std::vector<std::unique_ptr<Node>> children;
78 std::map<String, std::unique_ptr<ValueNode>> propertyValuePairs;
79 String name;
80 };
81
85 struct ValueNode
86 {
87 ValueNode(String v = U"") : value(std::move(v)) {}
88
89 String value;
90 bool listNode = false;
91 std::vector<String> valueList;
92 };
93
101 TGUI_NODISCARD static std::unique_ptr<Node> parse(std::stringstream& stream);
102
109 static void emit(const std::unique_ptr<Node>& rootNode, std::stringstream& stream);
110 };
111
113}
114
116
117#endif // TGUI_DATA_IO_HPP
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38