inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
properties.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <iostream>
5#include <string_view>
6#include <unordered_map>
7
14{
16 // Add more properties here as needed
17};
18
29{
30 GlobalProps gprops;
31
42 auto reportWarning =
43 [](const std::string& field, const std::string_view& value, const std::string& default_val)
44 {
45 std::cerr << "!! Warning: Invalid value '" << value << "' detected for field '" << field
46 << "'. Using default value '" << default_val << "'." << std::endl;
47 };
48
60 auto handle_bool_prop = [&](const std::string_view& value, const std::string& field,
61 bool default_val) -> bool
62 {
63 if (value.empty())
64 {
65 reportWarning(field, value, default_val ? "true" : "false");
66 return default_val;
67 }
68
69 std::string value_lower;
70 value_lower.reserve(value.size());
71 for (char c : value)
72 {
73 value_lower += std::tolower(c);
74 }
75
76 if (value_lower == "true" || value_lower == "1" || value_lower == "yes")
77 {
78 return true;
79 }
80 if (value_lower == "false" || value_lower == "0" || value_lower == "no")
81 {
82 return false;
83 }
84
85 reportWarning(field, value, default_val ? "true" : "false");
86 return default_val;
87 };
88
89 const std::unordered_map<std::string, std::pair<bool&, bool>> field_map = {
90 {"show_bitrate", {gprops.show_bitrate, false}},
91 };
92
93 for (const auto& [field, field_info] : field_map)
94 {
95 const auto& [field_ref, default_val] = field_info;
96 std::string_view value = parseTOMLField(PARENT_UI, field);
97 field_ref = handle_bool_prop(value, field, default_val);
98 }
99
100 return gprops;
101}
auto parseProps() -> GlobalProps
Parses the global properties from the TOML configuration.
Definition properties.hpp:28
Struct to hold global property settings.
Definition properties.hpp:14
bool show_bitrate
Definition properties.hpp:15
#define PARENT_UI
Definition toml_parser.hpp:39
auto parseTOMLField(string parent, string field) -> string_view
Parses a string field from the TOML configuration.
Definition toml_parser.hpp:144