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> 25 using RawConfigPtr = std::shared_ptr<RawConfig>;
27 class RawConfigPrivate;
41 FCITX_DECLARE_VIRTUAL_DTOR_COPY(
RawConfig)
51 std::shared_ptr<RawConfig>
get(
const std::string &path,
54 std::shared_ptr<const RawConfig>
get(
const std::string &path)
const;
62 bool remove(
const std::string &path);
72 void setValue(std::string value);
79 void setComment(std::string comment);
86 void setLineNumber(
unsigned int lineNumber);
96 void setImplicit(
bool implicit);
99 const std::string &name()
const;
102 const std::string &comment()
const;
105 const std::string &value()
const;
108 unsigned int lineNumber()
const;
117 bool isImplicitSelf()
const;
126 bool isImplicit()
const;
133 bool hasSubItems()
const;
140 size_t subItemsSize()
const;
147 std::vector<std::string> subItems()
const;
156 (*this)[path] = std::move(value);
166 auto config =
get(path);
167 return config ? &config->value() :
nullptr;
185 setValue(std::move(value));
196 if (
this == &other) {
199 if (value() != other.
value()) {
205 return visitSubItems(
206 [&other](
const RawConfig &subConfig,
const std::string &path) {
207 auto otherSubConfig = other.
get(path);
208 return (otherSubConfig && *otherSubConfig == subConfig);
219 return !(*
this == config);
234 std::shared_ptr<RawConfig> detach();
246 std::function<
bool(
RawConfig &,
const std::string &path)> callback,
247 const std::string &path =
"",
bool recursive =
false,
248 const std::string &pathPrefix =
"");
251 std::function<
bool(
const RawConfig &,
const std::string &path)>
253 const std::string &path =
"",
bool recursive =
false,
254 const std::string &pathPrefix =
"")
const;
262 void visitItemsOnPath(
263 std::function<
void(
RawConfig &,
const std::string &path)> callback,
264 const std::string &path);
267 void visitItemsOnPath(
268 std::function<
void(
const RawConfig &,
const std::string &path)>
270 const std::string &path)
const;
275 std::shared_ptr<RawConfig> createSub(std::string name);
277 std::unique_ptr<RawConfigPrivate> d_ptr;
291 #endif // _FCITX_CONFIG_RAWCONFIG_H_ RawConfig & operator=(std::string value)
Assign a string value to this node.
void setValueByPath(const std::string &path, std::string value)
Set a value by path, creating intermediate nodes if needed.
RawConfig & operator[](const std::string &path)
Get or create a sub-item by path.
A raw configuration tree that stores key-value pairs in a hierarchical structure. ...
const std::string * valueByPath(const std::string &path) const
Get a value by path.
std::shared_ptr< RawConfig > get(const std::string &path, bool create=false)
Get a sub-item by path.
bool operator!=(const RawConfig &config) const
Check if two RawConfig trees are not equal.
size_t subItemsSize() const
Get the number of sub-items.
bool operator==(const RawConfig &other) const
Check if two RawConfig trees are equal.
const std::string & value() const
Get the value of this node.