aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/common/Base.hpp2
-rw-r--r--include/cru/common/PropertyTree.hpp63
-rw-r--r--include/cru/common/String.hpp5
3 files changed, 69 insertions, 1 deletions
diff --git a/include/cru/common/Base.hpp b/include/cru/common/Base.hpp
index ef5727c5..cb06cc09 100644
--- a/include/cru/common/Base.hpp
+++ b/include/cru/common/Base.hpp
@@ -36,7 +36,7 @@
classname(classname&&) = delete; \
classname& operator=(classname&&) = delete;
-#define CRU_DEFAULT_DESTRUCTOR(classname) ~classname() override = default;
+#define CRU_DEFAULT_DESTRUCTOR(classname) ~classname() = default;
#define CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(classname) \
classname() = default; \
diff --git a/include/cru/common/PropertyTree.hpp b/include/cru/common/PropertyTree.hpp
new file mode 100644
index 00000000..01b50dac
--- /dev/null
+++ b/include/cru/common/PropertyTree.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "Base.hpp"
+#include "String.hpp"
+
+#include <unordered_map>
+
+namespace cru {
+class PropertyTree;
+
+class PropertySubTreeRef {
+ public:
+ static String CombineKey(StringView left, StringView right);
+
+ explicit PropertySubTreeRef(PropertyTree* tree, String path = {});
+
+ CRU_DEFAULT_COPY(PropertySubTreeRef);
+ CRU_DEFAULT_MOVE(PropertySubTreeRef);
+
+ CRU_DEFAULT_DESTRUCTOR(PropertySubTreeRef);
+
+ public:
+ PropertyTree* GetTree() const { return tree_; }
+
+ String GetPath() const { return path_; }
+ void SetPath(String path) { path_ = std::move(path); }
+
+ PropertySubTreeRef GetParent() const;
+ PropertySubTreeRef GetChild(const String& key) const;
+
+ String GetValue(const String& key) const;
+ void SetValue(const String& key, String value);
+ void DeleteValue(const String& key);
+
+ private:
+ PropertyTree* tree_;
+ String path_;
+};
+
+class PropertyTree {
+ public:
+ static String CombineKey(StringView left, StringView right);
+
+ PropertyTree() = default;
+ explicit PropertyTree(std::unordered_map<String, String> values);
+
+ CRU_DELETE_COPY(PropertyTree);
+ CRU_DELETE_MOVE(PropertyTree);
+
+ CRU_DEFAULT_DESTRUCTOR(PropertyTree);
+
+ public:
+ String GetValue(const String& key) const;
+ void SetValue(const String& key, String value);
+ void DeleteValue(const String& key);
+
+ PropertySubTreeRef GetSubTreeRef(const String& path);
+
+ private:
+ std::unordered_map<String, String> values_;
+};
+
+} // namespace cru
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp
index 0ae223cf..8acb6a87 100644
--- a/include/cru/common/String.hpp
+++ b/include/cru/common/String.hpp
@@ -82,6 +82,8 @@ class CRU_BASE_API String {
String(std::initializer_list<value_type> l);
+ explicit String(StringView str);
+
#ifdef CRU_PLATFORM_WINDOWS
String(const wchar_t* str);
String(const wchar_t* str, Index size);
@@ -259,6 +261,7 @@ class CRU_BASE_API StringView {
~StringView() = default;
+ bool empty() const { return size_ == 0; }
Index size() const { return size_; }
const value_type* data() const { return ptr_; }
@@ -405,6 +408,8 @@ inline void String::append(StringView str) {
inline String String::From(StringView str) { return str.ToString(); }
+inline String::String(StringView str) : String(str.data(), str.size()) {}
+
inline String ToString(StringView value) { return value.ToString(); }
inline CodePoint Utf16PreviousCodePoint(StringView str, Index current,