7 #ifndef _FCITX_CONFIG_RAWCONFIG_H_ 8 #define _FCITX_CONFIG_RAWCONFIG_H_ 16 #include <fcitx-config/fcitxconfig_export.h> 18 #include <fcitx-utils/macros.h> 24 using RawConfigPtr = std::shared_ptr<RawConfig>;
26 class RawConfigPrivate;
30 FCITX_DECLARE_VIRTUAL_DTOR_COPY(
RawConfig)
32 std::shared_ptr<RawConfig>
get(
const std::string &path,
34 std::shared_ptr<const RawConfig>
get(
const std::string &path)
const;
35 bool remove(
const std::string &path);
37 void setValue(std::string value);
38 void setComment(std::string comment);
39 void setLineNumber(
unsigned int lineNumber);
40 const std::string &name()
const;
41 const std::string &comment()
const;
42 const std::string &value()
const;
43 unsigned int lineNumber()
const;
44 bool hasSubItems()
const;
45 size_t subItemsSize()
const;
46 std::vector<std::string> subItems()
const;
47 void setValueByPath(
const std::string &path, std::string value) {
48 (*this)[path] = std::move(value);
51 const std::string *valueByPath(
const std::string &path)
const {
52 auto config =
get(path);
53 return config ? &config->value() :
nullptr;
56 RawConfig &operator[](
const std::string &path) {
return *
get(path,
true); }
58 setValue(std::move(value));
62 bool operator==(
const RawConfig &other)
const {
66 if (value() != other.value()) {
69 if (subItemsSize() != other.subItemsSize()) {
73 [&other](
const RawConfig &subConfig,
const std::string &path) {
74 auto otherSubConfig = other.get(path);
75 return (otherSubConfig && *otherSubConfig == subConfig);
79 bool operator!=(
const RawConfig &config)
const {
80 return !(*
this == config);
84 std::shared_ptr<RawConfig> detach();
87 std::function<
bool(
RawConfig &,
const std::string &path)> callback,
88 const std::string &path =
"",
bool recursive =
false,
89 const std::string &pathPrefix =
"");
91 std::function<
bool(
const RawConfig &,
const std::string &path)>
93 const std::string &path =
"",
bool recursive =
false,
94 const std::string &pathPrefix =
"")
const;
95 void visitItemsOnPath(
96 std::function<
void(
RawConfig &,
const std::string &path)> callback,
97 const std::string &path);
98 void visitItemsOnPath(
99 std::function<
void(
const RawConfig &,
const std::string &path)>
101 const std::string &path)
const;
106 std::shared_ptr<RawConfig> createSub(std::string name);
108 std::unique_ptr<RawConfigPrivate> d_ptr;
115 #endif // _FCITX_CONFIG_RAWCONFIG_H_