Doxygen with github
Loading...
Searching...
No Matches
ksf::misc::ksConfig Class Reference

Implements low-level configuration file handling. More...

#include <ksConfig.h>

Public Member Functions

 ksConfig (const std::string &fileName)
 Constructor tha opens or creates configuration file.
 
virtual ~ksConfig ()
 Saves config content on the device filesystem. In case there is no modification, nothing should actually happen.
 
void setParam (const std::string &paramName, const std::string paramValue)
 Sets parameter value (creates new parameter if it does not exist).
 
const std::string & getParam (const std::string &paramName, const std::string &defaultValue=std::string()) const
 Retrieves parameter value.
 
 operator bool () const
 Operator bool override. Returns true if configFilename is not empty.
 

Protected Attributes

bool isDirty {false}
 True if config contents has been modified (and should be saved).
 
std::map< std::string, std::string > configParams
 Config parameters.
 
std::string configPath
 Config filename.
 

Detailed Description

Implements low-level configuration file handling.

Uses std::map to store configuration parameters. When any parameter is modified, the config file is marked as dirty. Upon destruction, if the file has been modified, it is saved to the filesystem.

Constructor & Destructor Documentation

◆ ksConfig()

ksf::misc::ksConfig::ksConfig ( const std::string & fileName)

Constructor tha opens or creates configuration file.

Parameters
fileNameConfig filename.

References configParams, and configPath.

Member Function Documentation

◆ getParam()

const std::string & ksf::misc::ksConfig::getParam ( const std::string & paramName,
const std::string & defaultValue = std::string() ) const

Retrieves parameter value.

Parameters
paramNameName of the parameter to retrieve.
defaultValueDefault value to return if parameter does not exist.
Returns
Parameter value string (or defaultValue).

References configParams.

Referenced by ksf::comps::ksConfigProvider::addNewParamWithConfigDefault().

◆ operator bool()

ksf::misc::ksConfig::operator bool ( ) const

Operator bool override. Returns true if configFilename is not empty.

Returns
True if configFilename is not empty, otherwise false.

◆ setParam()

void ksf::misc::ksConfig::setParam ( const std::string & paramName,
const std::string paramValue )

Sets parameter value (creates new parameter if it does not exist).

Parameters
paramNameParameter name.
paramValueParameter value (use std::move when possible).

References configParams, and isDirty.


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