Fcitx
Public Member Functions | Friends | List of all members
fcitx::RawConfig Class Reference

A raw configuration tree that stores key-value pairs in a hierarchical structure. More...

#include <fcitx-config/rawconfig.h>

Public Member Functions

 RawConfig ()
 Construct a RawConfig with an empty name. More...
 
std::shared_ptr< RawConfigget (const std::string &path, bool create=false)
 Get a sub-item by path. More...
 
std::shared_ptr< const RawConfigget (const std::string &path) const
 
bool remove (const std::string &path)
 Remove a sub-item by path. More...
 
void removeAll ()
 Remove all sub-items. More...
 
void setValue (std::string value)
 Set the value of this node. More...
 
void setComment (std::string comment)
 Set the comment for this node. More...
 
void setLineNumber (unsigned int lineNumber)
 Set the line number where this node was parsed from. More...
 
void setImplicit (bool implicit)
 Mark this config node as implicit (default value that won't be written to INI). More...
 
const std::string & name () const
 Get the name of this node. More...
 
const std::string & comment () const
 Get the comment for this node. More...
 
const std::string & value () const
 Get the value of this node. More...
 
unsigned int lineNumber () const
 Get the line number where this node was parsed from. More...
 
bool isImplicitSelf () const
 Check if this node itself is marked as implicit. More...
 
bool isImplicit () const
 Check if this node or any of its ancestors is marked as implicit. More...
 
bool hasSubItems () const
 Check if this node has any sub-items. More...
 
size_t subItemsSize () const
 Get the number of sub-items. More...
 
std::vector< std::string > subItems () const
 Get a list of sub-item names. More...
 
void setValueByPath (const std::string &path, std::string value)
 Set a value by path, creating intermediate nodes if needed. More...
 
const std::string * valueByPath (const std::string &path) const
 Get a value by path. More...
 
RawConfigoperator[] (const std::string &path)
 Get or create a sub-item by path. More...
 
RawConfigoperator= (std::string value)
 Assign a string value to this node. More...
 
bool operator== (const RawConfig &other) const
 Check if two RawConfig trees are equal. More...
 
bool operator!= (const RawConfig &config) const
 Check if two RawConfig trees are not equal. More...
 
RawConfigparent () const
 Get the parent node. More...
 
std::shared_ptr< RawConfigdetach ()
 Detach this node from its parent. More...
 
bool visitSubItems (std::function< bool(RawConfig &, const std::string &path)> callback, const std::string &path="", bool recursive=false, const std::string &pathPrefix="")
 Visit all sub-items. More...
 
bool visitSubItems (std::function< bool(const RawConfig &, const std::string &path)> callback, const std::string &path="", bool recursive=false, const std::string &pathPrefix="") const
 
void visitItemsOnPath (std::function< void(RawConfig &, const std::string &path)> callback, const std::string &path)
 Visit all items on a path. More...
 
void visitItemsOnPath (std::function< void(const RawConfig &, const std::string &path)> callback, const std::string &path) const
 

Friends

class RawConfigPrivate
 

Detailed Description

A raw configuration tree that stores key-value pairs in a hierarchical structure.

RawConfig represents a configuration as a tree of nodes, where each node can have a value and sub-items. For example, It supports reading from and writing to INI format, and can represent configuration with implicit (default) values.

Definition at line 37 of file rawconfig.h.

Constructor & Destructor Documentation

◆ RawConfig()

fcitx::RawConfig::RawConfig ( )

Construct a RawConfig with an empty name.

Definition at line 132 of file rawconfig.cpp.

Member Function Documentation

◆ comment()

const std::string & fcitx::RawConfig::comment ( ) const

Get the comment for this node.

Definition at line 212 of file rawconfig.cpp.

◆ detach()

std::shared_ptr< RawConfig > fcitx::RawConfig::detach ( )

Detach this node from its parent.

Returns
shared pointer to the detached node, or empty if already root

Definition at line 268 of file rawconfig.cpp.

◆ get() [1/2]

std::shared_ptr< RawConfig > fcitx::RawConfig::get ( const std::string &  path,
bool  create = false 
)

Get a sub-item by path.

Parameters
pathpath to the sub-item, using '/' as separator
createif true, create intermediate nodes if they don't exist
Returns
shared pointer to the sub-item, or nullptr if not found and create is false

Definition at line 153 of file rawconfig.cpp.

◆ get() [2/2]

std::shared_ptr< const RawConfig > fcitx::RawConfig::get ( const std::string &  path) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 164 of file rawconfig.cpp.

◆ hasSubItems()

bool fcitx::RawConfig::hasSubItems ( ) const

Check if this node has any sub-items.

Returns
true if this node has sub-items

Definition at line 243 of file rawconfig.cpp.

◆ isImplicit()

bool fcitx::RawConfig::isImplicit ( ) const

Check if this node or any of its ancestors is marked as implicit.

Returns
true if this node or any ancestor is marked as implicit
Since
5.1.22

Definition at line 232 of file rawconfig.cpp.

◆ isImplicitSelf()

bool fcitx::RawConfig::isImplicitSelf ( ) const

Check if this node itself is marked as implicit.

Returns
true if this node is marked as implicit
Since
5.1.22

Definition at line 227 of file rawconfig.cpp.

◆ lineNumber()

unsigned int fcitx::RawConfig::lineNumber ( ) const

Get the line number where this node was parsed from.

Definition at line 222 of file rawconfig.cpp.

◆ name()

const std::string & fcitx::RawConfig::name ( ) const

Get the name of this node.

Definition at line 207 of file rawconfig.cpp.

◆ operator!=()

bool fcitx::RawConfig::operator!= ( const RawConfig config) const
inline

Check if two RawConfig trees are not equal.

Parameters
configthe other RawConfig to compare with
Returns
true if the trees are not equal

Definition at line 218 of file rawconfig.h.

◆ operator=()

RawConfig & fcitx::RawConfig::operator= ( std::string  value)
inline

Assign a string value to this node.

Parameters
valuethe value to assign
Returns
reference to this node

Definition at line 184 of file rawconfig.h.

◆ operator==()

bool fcitx::RawConfig::operator== ( const RawConfig other) const
inline

Check if two RawConfig trees are equal.

Parameters
otherthe other RawConfig to compare with
Returns
true if the trees are equal

Definition at line 195 of file rawconfig.h.

◆ operator[]()

RawConfig& fcitx::RawConfig::operator[] ( const std::string &  path)
inline

Get or create a sub-item by path.

Parameters
pathpath to the sub-item, using '/' as separator
Returns
reference to the sub-item

Definition at line 176 of file rawconfig.h.

◆ parent()

RawConfig * fcitx::RawConfig::parent ( ) const

Get the parent node.

Returns
pointer to the parent node, or nullptr if this is the root

Definition at line 263 of file rawconfig.cpp.

◆ remove()

bool fcitx::RawConfig::remove ( const std::string &  path)

Remove a sub-item by path.

Parameters
pathpath to the item to remove
Returns
true if the item was removed, false if not found or invalid path

Definition at line 169 of file rawconfig.cpp.

◆ removeAll()

void fcitx::RawConfig::removeAll ( )

Remove all sub-items.

Definition at line 182 of file rawconfig.cpp.

◆ setComment()

void fcitx::RawConfig::setComment ( std::string  comment)

Set the comment for this node.

Parameters
commentthe comment to set

Definition at line 192 of file rawconfig.cpp.

◆ setImplicit()

void fcitx::RawConfig::setImplicit ( bool  implicit)

Mark this config node as implicit (default value that won't be written to INI).

Parameters
implicittrue to mark as implicit, false otherwise
Since
5.1.22

Definition at line 202 of file rawconfig.cpp.

◆ setLineNumber()

void fcitx::RawConfig::setLineNumber ( unsigned int  lineNumber)

Set the line number where this node was parsed from.

Parameters
lineNumberthe line number

Definition at line 197 of file rawconfig.cpp.

◆ setValue()

void fcitx::RawConfig::setValue ( std::string  value)

Set the value of this node.

Parameters
valuethe value to set

Definition at line 187 of file rawconfig.cpp.

◆ setValueByPath()

void fcitx::RawConfig::setValueByPath ( const std::string &  path,
std::string  value 
)
inline

Set a value by path, creating intermediate nodes if needed.

Parameters
pathpath to the value, using '/' as separator
valuethe value to set

Definition at line 155 of file rawconfig.h.

◆ subItems()

std::vector< std::string > fcitx::RawConfig::subItems ( ) const

Get a list of sub-item names.

Returns
list of sub-item names

Definition at line 253 of file rawconfig.cpp.

◆ subItemsSize()

size_t fcitx::RawConfig::subItemsSize ( ) const

Get the number of sub-items.

Returns
number of sub-items

Definition at line 248 of file rawconfig.cpp.

◆ value()

const std::string & fcitx::RawConfig::value ( ) const

Get the value of this node.

Definition at line 217 of file rawconfig.cpp.

◆ valueByPath()

const std::string* fcitx::RawConfig::valueByPath ( const std::string &  path) const
inline

Get a value by path.

Parameters
pathpath to the value, using '/' as separator
Returns
pointer to the value, or nullptr if not found

Definition at line 165 of file rawconfig.h.

◆ visitItemsOnPath() [1/2]

void fcitx::RawConfig::visitItemsOnPath ( std::function< void(RawConfig &, const std::string &path)>  callback,
const std::string &  path 
)

Visit all items on a path.

Parameters
callbackfunction to call for each item on the path
paththe path to visit

Definition at line 316 of file rawconfig.cpp.

◆ visitItemsOnPath() [2/2]

void fcitx::RawConfig::visitItemsOnPath ( std::function< void(const RawConfig &, const std::string &path)>  callback,
const std::string &  path 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 321 of file rawconfig.cpp.

◆ visitSubItems() [1/2]

bool fcitx::RawConfig::visitSubItems ( std::function< bool(RawConfig &, const std::string &path)>  callback,
const std::string &  path = "",
bool  recursive = false,
const std::string &  pathPrefix = "" 
)

Visit all sub-items.

Parameters
callbackfunction to call for each sub-item, return false to stop
pathpath to start visiting from, empty for root
recursiveif true, visit sub-items recursively
pathPrefixprefix to prepend to paths in callback
Returns
true if all items were visited, false if stopped early

Definition at line 279 of file rawconfig.cpp.

◆ visitSubItems() [2/2]

bool fcitx::RawConfig::visitSubItems ( std::function< bool(const RawConfig &, const std::string &path)>  callback,
const std::string &  path = "",
bool  recursive = false,
const std::string &  pathPrefix = "" 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 297 of file rawconfig.cpp.


The documentation for this class was generated from the following files: