Doxygen with github
Loading...
Searching...
No Matches
ksf::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.
 
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.
 
virtual ~ksConfig ()
 Saves config content on the device filesystem. In case there is no modification, nothing should actually happen.
 

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. Then on destruction, the config file is saved if it has been modified (marked as dirty) into the filesystem.

Constructor & Destructor Documentation

◆ ksConfig()

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

Constructor tha opens or creates configuration file.

Parameters
fileNameConfig filename.

References configPath, and setParam().

Member Function Documentation

◆ getParam()

const std::string & ksf::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::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::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.

Referenced by ksConfig().


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