2020-06-09 14:46:49 -06:00
|
|
|
#pragma once
|
2021-03-30 04:54:59 -06:00
|
|
|
|
2020-01-17 12:01:02 -07:00
|
|
|
#include <map>
|
2021-05-08 23:15:17 -06:00
|
|
|
#include <string>
|
2020-10-13 08:23:23 -06:00
|
|
|
|
2021-05-04 11:49:26 -06:00
|
|
|
enum ParamKeyType {
|
|
|
|
PERSISTENT = 0x02,
|
|
|
|
CLEAR_ON_MANAGER_START = 0x04,
|
2022-01-14 06:13:18 -07:00
|
|
|
CLEAR_ON_IGNITION_ON = 0x08,
|
|
|
|
CLEAR_ON_IGNITION_OFF = 0x10,
|
|
|
|
DONT_LOG = 0x20,
|
2021-08-22 14:09:14 -06:00
|
|
|
ALL = 0xFFFFFFFF
|
2021-05-04 11:49:26 -06:00
|
|
|
};
|
|
|
|
|
2020-10-13 08:23:23 -06:00
|
|
|
class Params {
|
2020-10-17 18:07:40 -06:00
|
|
|
public:
|
2021-11-01 04:22:34 -06:00
|
|
|
Params(const std::string &path = {});
|
2021-05-04 11:49:26 -06:00
|
|
|
bool checkKey(const std::string &key);
|
2021-08-02 21:16:38 -06:00
|
|
|
ParamKeyType getKeyType(const std::string &key);
|
2021-11-01 04:22:34 -06:00
|
|
|
inline std::string getParamPath(const std::string &key = {}) {
|
|
|
|
return key.empty() ? params_path + "/d" : params_path + "/d/" + key;
|
|
|
|
}
|
2021-05-04 11:49:26 -06:00
|
|
|
|
2021-03-30 04:54:59 -06:00
|
|
|
// Delete a value
|
2021-11-01 04:22:34 -06:00
|
|
|
int remove(const std::string &key);
|
2021-05-04 11:49:26 -06:00
|
|
|
void clearAll(ParamKeyType type);
|
2020-10-13 08:23:23 -06:00
|
|
|
|
2021-05-04 11:49:26 -06:00
|
|
|
// helpers for reading values
|
2021-11-01 04:22:34 -06:00
|
|
|
std::string get(const std::string &key, bool block = false);
|
2021-04-07 07:36:37 -06:00
|
|
|
inline bool getBool(const std::string &key) {
|
2021-03-30 04:54:59 -06:00
|
|
|
return get(key) == "1";
|
|
|
|
}
|
2021-11-01 04:22:34 -06:00
|
|
|
std::map<std::string, std::string> readAll();
|
2021-03-30 04:54:59 -06:00
|
|
|
|
2021-05-04 11:49:26 -06:00
|
|
|
// helpers for writing values
|
2021-11-01 04:22:34 -06:00
|
|
|
int put(const char *key, const char *val, size_t value_size);
|
2021-03-30 04:54:59 -06:00
|
|
|
inline int put(const std::string &key, const std::string &val) {
|
|
|
|
return put(key.c_str(), val.data(), val.size());
|
|
|
|
}
|
2021-04-07 07:36:37 -06:00
|
|
|
inline int putBool(const std::string &key, bool val) {
|
2021-11-01 04:22:34 -06:00
|
|
|
return put(key.c_str(), val ? "1" : "0", 1);
|
2021-04-07 07:36:37 -06:00
|
|
|
}
|
2021-08-20 17:57:45 -06:00
|
|
|
|
|
|
|
private:
|
2021-11-01 04:22:34 -06:00
|
|
|
std::string params_path;
|
2020-10-13 08:23:23 -06:00
|
|
|
};
|