SPH
Public Member Functions | List of all members
Config Class Reference

Provides functionality for reading and writing configuration files. More...

#include <Config.h>

Public Member Functions

SharedPtr< ConfigNodeaddNode (const std::string &name)
 Adds a new node to the config. More...
 
SharedPtr< ConfigNodegetNode (const std::string &name)
 Returns a node with given name. More...
 
SharedPtr< ConfigNodetryGetNode (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...
 

Detailed Description

Provides functionality for reading and writing configuration files.

Configuration files consist of key-value pair, clustered in a node hierarchy.

Definition at line 272 of file Config.h.

Member Function Documentation

◆ addNode()

SharedPtr< ConfigNode > Config::addNode ( const std::string &  name)

Adds a new node to the config.

Definition at line 81 of file Config.cpp.

◆ enumerate()

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.

◆ getNode()

SharedPtr< ConfigNode > Config::getNode ( const std::string &  name)

Returns a node with given name.

Exceptions
ConfigExceptionif no such node exists.

Definition at line 85 of file Config.cpp.

◆ load()

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.

◆ read()

void Config::read ( std::stringstream &  source)

Deserializes the input string stream into nodes.

This removed all previously added nodes in the config.

Exceptions
ConfigExceptionif the source has invalid format.

Definition at line 101 of file Config.cpp.

◆ save()

void Config::save ( const Path path)

Serializes all nodes in the config into a file.

Definition at line 126 of file Config.cpp.

◆ tryGetNode()

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.

◆ write()

std::string Config::write ( )

Serializes all nodes in the config into a string.

Definition at line 115 of file Config.cpp.


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