Doxygen with github
Loading...
Searching...
No Matches
ksConfig.h
1/*
2 * Copyright (c) 2021-2023, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFramework library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include <string>
13#include <map>
14
19#define USING_CONFIG_FILE(fileName) \
20 if (ksf::ksConfig config_file{ksf::ksConfig(fileName)})
21
22namespace ksf
23{
31 {
32 protected:
33 bool isDirty{false};
34 std::map<std::string, std::string> configParams;
35 std::string configPath;
36
37 public:
42 ksConfig(const std::string& fileName);
43
49 void setParam(const std::string& paramName, const std::string paramValue);
50
57 const std::string& getParam(const std::string& paramName, const std::string& defaultValue = std::string()) const;
58
63 operator bool() const;
64
69 virtual ~ksConfig();
70 };
71}
72
Implements low-level configuration file handling.
Definition ksConfig.h:31
std::map< std::string, std::string > configParams
Config parameters.
Definition ksConfig.h:34
virtual ~ksConfig()
Saves config content on the device filesystem. In case there is no modification, nothing should actua...
Definition ksConfig.cpp:73
const std::string & getParam(const std::string &paramName, const std::string &defaultValue=std::string()) const
Retrieves parameter value.
Definition ksConfig.cpp:62
std::string configPath
Config filename.
Definition ksConfig.h:35
void setParam(const std::string &paramName, const std::string paramValue)
Sets parameter value (creates new parameter if it does not exist).
Definition ksConfig.cpp:56
ksConfig(const std::string &fileName)
Constructor tha opens or creates configuration file.
Definition ksConfig.cpp:16
bool isDirty
True if config contents has been modified (and should be saved).
Definition ksConfig.h:33