SPH
|
Provides functionality for reading and writing configuration files. More...
#include <Config.h>
Public Member Functions | |
SharedPtr< ConfigNode > | addNode (const std::string &name) |
Adds a new node to the config. More... | |
SharedPtr< ConfigNode > | getNode (const std::string &name) |
Returns a node with given name. More... | |
SharedPtr< ConfigNode > | tryGetNode (const std::string &name) |
Returns a node with given name or nullptr if no such node exists. More... | |
void | read (std::stringstream &source) |
Deserializes the input string stream into nodes. More... | |
std::string | write () |
Serializes all nodes in the config into a string. More... | |
void | load (const Path &path) |
Reads content of given file and deserializes the config from the loaded string. More... | |
void | save (const Path &path) |
Serializes all nodes in the config into a file. More... | |
void | enumerate (Function< void(std::string, ConfigNode &)> func) |
Calls the provided functor for all nodes in the config. More... | |
Provides functionality for reading and writing configuration files.
Configuration files consist of key-value pair, clustered in a node hierarchy.
SharedPtr< ConfigNode > Config::addNode | ( | const std::string & | name | ) |
Adds a new node to the config.
Definition at line 81 of file Config.cpp.
void Config::enumerate | ( | Function< void(std::string, ConfigNode &)> | func | ) |
Calls the provided functor for all nodes in the config.
Definition at line 138 of file Config.cpp.
SharedPtr< ConfigNode > Config::getNode | ( | const std::string & | name | ) |
Returns a node with given name.
ConfigException | if no such node exists. |
Definition at line 85 of file Config.cpp.
void Config::load | ( | const Path & | path | ) |
Reads content of given file and deserializes the config from the loaded string.
Definition at line 131 of file Config.cpp.
void Config::read | ( | std::stringstream & | source | ) |
Deserializes the input string stream into nodes.
This removed all previously added nodes in the config.
ConfigException | if the source has invalid format. |
Definition at line 101 of file Config.cpp.
void Config::save | ( | const Path & | path | ) |
Serializes all nodes in the config into a file.
Definition at line 126 of file Config.cpp.
SharedPtr< ConfigNode > Config::tryGetNode | ( | const std::string & | name | ) |
Returns a node with given name or nullptr if no such node exists.
Definition at line 93 of file Config.cpp.
std::string Config::write | ( | ) |
Serializes all nodes in the config into a string.
Definition at line 115 of file Config.cpp.