blob: 8eecc3b9e2b2a616072c600a3b70e7366255da2e (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 | #pragma once
#include "Base.h"
#include <string>
#include <string_view>
#include <unordered_map>
namespace cru {
class PropertyTree;
class CRU_BASE_API PropertySubTreeRef {
 public:
  static std::string CombineKey(std::string_view left, std::string_view right);
  explicit PropertySubTreeRef(PropertyTree* tree, std::string path = {});
 public:
  PropertyTree* GetTree() const { return tree_; }
  std::string GetPath() const { return path_; }
  void SetPath(std::string path) { path_ = std::move(path); }
  PropertySubTreeRef GetParent() const;
  PropertySubTreeRef GetChild(const std::string& key) const;
  std::string GetValue(const std::string& key) const;
  void SetValue(const std::string& key, std::string value);
  void DeleteValue(const std::string& key);
 private:
  PropertyTree* tree_;
  std::string path_;
};
class CRU_BASE_API PropertyTree : public Object2 {
 public:
  static std::string CombineKey(std::string_view left, std::string_view right);
  PropertyTree() = default;
  explicit PropertyTree(std::unordered_map<std::string, std::string> values);
 public:
  std::string GetValue(const std::string& key) const;
  void SetValue(const std::string& key, std::string value);
  void DeleteValue(const std::string& key);
  PropertySubTreeRef GetSubTreeRef(const std::string& path);
 private:
  std::unordered_map<std::string, std::string> values_;
};
}  // namespace cru
 |