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