TGUI  1.3-dev
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
26#ifndef TGUI_DATA_IO_HPP
27#define TGUI_DATA_IO_HPP
28
30
31#include <TGUI/String.hpp>
32
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
34 #include <sstream>
35 #include <memory>
36 #include <vector>
37 #include <string>
38 #include <map>
39 #include <cstdio>
40#endif
41
43
44TGUI_MODULE_EXPORT namespace tgui
45{
50 class TGUI_API DataIO
51 {
52 public:
53 struct ValueNode;
54
58 struct Node
59 {
60 Node() = default;
61 Node(Node&&) = default;
62 Node& operator=(const Node&) = delete; // Not implemented because current code has no use for it
63 Node& operator=(Node&&) = default;
64
65 Node(const Node& other) :
66 parent{other.parent},
67 children{},
68 propertyValuePairs{},
69 name{other.name}
70 {
71 for (const auto& child : other.children)
72 children.push_back(std::make_unique<Node>(*child));
73 for (const auto& pair : other.propertyValuePairs)
74 propertyValuePairs[pair.first] = std::make_unique<ValueNode>(*pair.second);
75 }
76
77 Node* parent = nullptr;
78 std::vector<std::unique_ptr<Node>> children;
79 std::map<String, std::unique_ptr<ValueNode>> propertyValuePairs;
80 String name;
81 };
82
83
87 struct ValueNode
88 {
89 ValueNode(String v = U"") : value(std::move(v)) {}
90
91 String value;
92 bool listNode = false;
93 std::vector<String> valueList;
94 };
95
96
105 TGUI_NODISCARD static std::unique_ptr<Node> parse(std::stringstream& stream);
106
107
115 static void emit(const std::unique_ptr<Node>& rootNode, std::stringstream& stream);
116 };
117
119}
120
122
123#endif // TGUI_DATA_IO_HPP
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39