18 if (
line.empty() ||
line.front() ==
'#')
continue;
23 if (type ==
"string") {
25 }
else if (type ==
"int") {
26 std::uint8_t
base = 10;
32 }
else if (type ==
"float") {
34 }
else if (type ==
"bool") {
36 }
else if (type ==
"bytes") {
55std::tuple<std::string, std::string, std::string>
Config::parseLine(
const std::string& line) {
66 if (!value.empty() && value.front() ==
'"' && value.back() ==
'"')
67 value = value.substr(1, value.size() - 2);
69 return {
key, type, value};
73 std::vector<uint8_t>
result{};
76 "Config: Invalid buffer formatting []");
87 while (std::getline(
ss,
token,
',')) {
90 [](
unsigned char c){ return std::isspace(c); }),
98 std::uint8_t
base = 10;
102 if (
sv.size() > 2 &&
sv[0] ==
'0' && (
sv[1] ==
'x' ||
sv[1] ==
'X')) {
111 std::uint8_t
tmp = 0;
113 const char*
last =
sv.data() +
sv.size();
117 if (
res.ec != std::errc{} ||
res.ptr !=
last ||
tmp > 0xFFu) {
119 std::string(
"Invalid byte value: ") + std::string(
token)};
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
#define ASSIGN_CP(var, result)
Macro to assign a result value to a variable or return an error by copy.
Represents an error with both an error code and a message.
Encapsulates a result that can hold either a value or an Error.
std::variant< std::string, int, float, bool, std::vector< uint8_t > > ConfigValue
bool isKey(const std::string &key) const
static CCSDS::ResultBuffer parseBytes(const std::string &valueStr)
Parse string "[1,2,3]" into vector<uint8_t>
std::unordered_map< std::string, ConfigValue > values
CCSDS::ResultBool load(const std::string &filename)
Load config file.
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
static std::tuple< std::string, std::string, std::string > parseLine(const std::string &line)
Parse a single line from config.
@ CONFIG_FILE_ERROR
Configuration file error.