Doxygen with github
Loading...
Searching...
No Matches
ksConfig.h
1/*
2 * Copyright (c) 2020-2026, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFrameworkLib IoT 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::misc::ksConfig config_file{ksf::misc::ksConfig(fileName)})
21
22namespace ksf::misc
23{
31 {
32 protected:
33 bool isDirty{false};
34 std::map<std::string, std::string> configParams;
35 std::string configPath;
36
37 public:
38 inline static const std::string emptyString{};
39
44 ksConfig(const std::string& fileName);
45
50 virtual ~ksConfig();
51
57 void setParam(const std::string& paramName, std::string paramValue);
58
65 const std::string& getParam(const std::string& paramName, const std::string& defaultValue = ksConfig::emptyString) const;
66
71 operator bool() const;
72 };
73}
74
Implements low-level configuration file handling.
Definition ksConfig.h:31
virtual ~ksConfig()
Saves config content on the device filesystem. In case there is no modification, nothing should actua...
Definition ksConfig.cpp:81
void setParam(const std::string &paramName, std::string paramValue)
Sets parameter value (creates new parameter if it does not exist).
Definition ksConfig.cpp:98
const std::string & getParam(const std::string &paramName, const std::string &defaultValue=ksConfig::emptyString) const
Retrieves parameter value.
Definition ksConfig.cpp:104
std::string configPath
Config filename.
Definition ksConfig.h:35
std::map< std::string, std::string > configParams
Config parameters.
Definition ksConfig.h:34
static const std::string emptyString
Static empty string for use as default parameter.
Definition ksConfig.h:38
ksConfig(const std::string &fileName)
Constructor that opens or creates configuration file.
Definition ksConfig.cpp:20
bool isDirty
True if config contents has been modified (and should be saved).
Definition ksConfig.h:33