Files
dragonpilot/selfdrive/common/params.h
Dean Lee 7222d0f20d Cleanup selfdrive/ includes (#20822)
* cleanup include path

* continue

* format includes

* fix testraw.cc

* remove include path from SConstruct

* regroup

* rebase master

* almost done

* apply review

* rename FileReader.xx to filereader.xx

* rename Unlogger.x->unlogger.x

* rename FrameReader.xx -> framereader.xx

* apply reviews

* ui.h

* continue

* fix framebuffer.cc build error:mv util.h up

* full path to msm_media_info

* fix qcom2 camerad

Co-authored-by: Comma Device <device@comma.ai>
2021-05-08 22:15:17 -07:00

77 lines
1.7 KiB
C++

#pragma once
#include <stddef.h>
#include <map>
#include <sstream>
#include <string>
#define ERR_NO_VALUE -33
enum ParamKeyType {
PERSISTENT = 0x02,
CLEAR_ON_MANAGER_START = 0x04,
CLEAR_ON_PANDA_DISCONNECT = 0x08,
CLEAR_ON_IGNITION = 0x10,
ALL = 0x02 | 0x04 | 0x08 | 0x10
};
class Params {
private:
std::string params_path;
public:
Params(bool persistent_param = false);
Params(const std::string &path);
bool checkKey(const std::string &key);
// Delete a value
int remove(const char *key);
inline int remove(const std::string &key) {
return remove (key.c_str());
}
void clearAll(ParamKeyType type);
// read all values
int readAll(std::map<std::string, std::string> *params);
// helpers for reading values
std::string get(const char *key, bool block = false);
inline std::string get(const std::string &key, bool block = false) {
return get(key.c_str(), block);
}
template <class T>
std::optional<T> get(const char *key, bool block = false) {
std::istringstream iss(get(key, block));
T value{};
iss >> value;
return iss.fail() ? std::nullopt : std::optional(value);
}
inline bool getBool(const std::string &key) {
return getBool(key.c_str());
}
inline bool getBool(const char *key) {
return get(key) == "1";
}
// helpers for writing values
int put(const char* key, const char* val, size_t value_size);
inline int put(const std::string &key, const std::string &val) {
return put(key.c_str(), val.data(), val.size());
}
inline int putBool(const char *key, bool val) {
return put(key, val ? "1" : "0", 1);
}
inline int putBool(const std::string &key, bool val) {
return putBool(key.c_str(), val);
}
};