diff options
author | crupest <crupest@outlook.com> | 2022-01-08 21:17:56 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-08 21:17:56 +0800 |
commit | 6b90be37d3ba7e094837bd01a19381bd59657041 (patch) | |
tree | 31bc841e7bc958e7ef31a3860321e8570bbef821 /include/cru/common/PropertyTree.hpp | |
parent | 45ae34c5f31eca1258f6df278c9862ff829f39db (diff) | |
download | cru-6b90be37d3ba7e094837bd01a19381bd59657041.tar.gz cru-6b90be37d3ba7e094837bd01a19381bd59657041.tar.bz2 cru-6b90be37d3ba7e094837bd01a19381bd59657041.zip |
...
Diffstat (limited to 'include/cru/common/PropertyTree.hpp')
-rw-r--r-- | include/cru/common/PropertyTree.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
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 |