mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-02 01:52:49 +00:00
refactor: resolve Sonar cpp:S1117 findings (#5908)
This commit is contained in:
1 parent
36ccab48d9
commit
e2a56b3d17
34 files changed
+507
-448
No files matched your search
+60
-60
@@ -1079,15 +1079,15 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
|
||||
void string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &destination) {
|
||||
auto it = vars.find(name);
|
||||
if (it == std::end(vars)) {
|
||||
return;
|
||||
}
|
||||
|
||||
input = std::move(it->second);
|
||||
destination = std::move(it->second);
|
||||
|
||||
vars.erase(it);
|
||||
}
|
||||
@@ -1097,15 +1097,15 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param f Converter applied to the raw configuration string.
|
||||
*/
|
||||
template<typename T, typename F>
|
||||
void generic_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, T &input, F &&f) {
|
||||
void generic_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, T &destination, F &&f) {
|
||||
std::string tmp;
|
||||
string_f(vars, name, tmp);
|
||||
if (!tmp.empty()) {
|
||||
input = f(tmp);
|
||||
destination = f(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1114,16 +1114,16 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param allowed_vals Accepted string values for this setting.
|
||||
*/
|
||||
void string_restricted_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input, const std::vector<std::string_view> &allowed_vals) {
|
||||
void string_restricted_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &destination, const std::vector<std::string_view> &allowed_vals) {
|
||||
std::string temp;
|
||||
string_f(vars, name, temp);
|
||||
|
||||
for (auto &allowed_val : allowed_vals) {
|
||||
if (temp == allowed_val) {
|
||||
input = std::move(temp);
|
||||
destination = std::move(temp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1162,9 +1162,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, fs::path &input) {
|
||||
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, fs::path &destination) {
|
||||
// appdata needs to be retrieved once only
|
||||
static auto appdata = platf::appdata();
|
||||
|
||||
@@ -1172,14 +1172,14 @@ namespace config {
|
||||
string_f(vars, name, temp);
|
||||
|
||||
if (!temp.empty()) {
|
||||
input = temp;
|
||||
destination = temp;
|
||||
}
|
||||
|
||||
if (input.is_relative()) {
|
||||
input = appdata / input;
|
||||
if (destination.is_relative()) {
|
||||
destination = appdata / destination;
|
||||
}
|
||||
|
||||
auto dir = input;
|
||||
auto dir = destination;
|
||||
dir.remove_filename();
|
||||
|
||||
// Ensure the directories exists
|
||||
@@ -1193,14 +1193,14 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
|
||||
fs::path temp = input;
|
||||
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &destination) {
|
||||
fs::path temp = destination;
|
||||
|
||||
path_f(vars, name, temp);
|
||||
|
||||
input = temp.string();
|
||||
destination = temp.string();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1225,16 +1225,16 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input) {
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &destination) {
|
||||
auto it = vars.find(name);
|
||||
|
||||
if (it == std::end(vars)) {
|
||||
return;
|
||||
}
|
||||
|
||||
input = parse_config_integer(it->second);
|
||||
destination = parse_config_integer(it->second);
|
||||
vars.erase(it);
|
||||
}
|
||||
|
||||
@@ -1243,16 +1243,16 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input) {
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &destination) {
|
||||
auto it = vars.find(name);
|
||||
|
||||
if (it == std::end(vars)) {
|
||||
return;
|
||||
}
|
||||
|
||||
input = parse_config_integer(it->second);
|
||||
destination = parse_config_integer(it->second);
|
||||
vars.erase(it);
|
||||
}
|
||||
|
||||
@@ -1261,15 +1261,15 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param f Converter applied to the raw configuration string.
|
||||
*/
|
||||
template<class F>
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, F &&f) {
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &destination, F &&f) {
|
||||
std::string tmp;
|
||||
string_f(vars, name, tmp);
|
||||
if (!tmp.empty()) {
|
||||
input = f(tmp);
|
||||
destination = f(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1278,15 +1278,15 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param f Converter applied to the raw configuration string.
|
||||
*/
|
||||
template<class F>
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input, F &&f) {
|
||||
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &destination, F &&f) {
|
||||
std::string tmp;
|
||||
string_f(vars, name, tmp);
|
||||
if (!tmp.empty()) {
|
||||
input = f(tmp);
|
||||
destination = f(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,17 +1295,17 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param range Inclusive range accepted for the parsed value.
|
||||
*/
|
||||
void int_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, const std::pair<int, int> &range) {
|
||||
int temp = input;
|
||||
void int_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &destination, const std::pair<int, int> &range) {
|
||||
int temp = destination;
|
||||
|
||||
int_f(vars, name, temp);
|
||||
|
||||
TUPLE_2D_REF(lower, upper, range);
|
||||
if (temp >= lower && temp <= upper) {
|
||||
input = temp;
|
||||
destination = temp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1333,9 +1333,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void bool_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, bool &input) {
|
||||
void bool_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, bool &destination) {
|
||||
std::string tmp;
|
||||
string_f(vars, name, tmp);
|
||||
|
||||
@@ -1343,7 +1343,7 @@ namespace config {
|
||||
return;
|
||||
}
|
||||
|
||||
input = to_bool(tmp);
|
||||
destination = to_bool(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1351,9 +1351,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void double_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input) {
|
||||
void double_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &destination) {
|
||||
std::string tmp;
|
||||
string_f(vars, name, tmp);
|
||||
|
||||
@@ -1368,7 +1368,7 @@ namespace config {
|
||||
return;
|
||||
}
|
||||
|
||||
input = val;
|
||||
destination = val;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1376,17 +1376,17 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
* @param range Inclusive range accepted for the parsed value.
|
||||
*/
|
||||
void double_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input, const std::pair<double, double> &range) {
|
||||
double temp = input;
|
||||
void double_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &destination, const std::pair<double, double> &range) {
|
||||
double temp = destination;
|
||||
|
||||
double_f(vars, name, temp);
|
||||
|
||||
TUPLE_2D_REF(lower, upper, range);
|
||||
if (temp >= lower && temp <= upper) {
|
||||
input = temp;
|
||||
destination = temp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1395,9 +1395,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void list_string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<std::string> &input) {
|
||||
void list_string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<std::string> &destination) {
|
||||
std::string string;
|
||||
string_f(vars, name, string);
|
||||
|
||||
@@ -1405,7 +1405,7 @@ namespace config {
|
||||
return;
|
||||
}
|
||||
|
||||
input.clear();
|
||||
destination.clear();
|
||||
|
||||
auto begin = std::cbegin(string);
|
||||
if (*begin == '[') {
|
||||
@@ -1424,7 +1424,7 @@ namespace config {
|
||||
} else if (*pos == ']') {
|
||||
break;
|
||||
} else if (*pos == ',') {
|
||||
input.emplace_back(begin, pos);
|
||||
destination.emplace_back(begin, pos);
|
||||
pos = begin = std::find_if_not(pos + 1, std::cend(string), whitespace);
|
||||
} else {
|
||||
++pos;
|
||||
@@ -1432,7 +1432,7 @@ namespace config {
|
||||
}
|
||||
|
||||
if (pos != begin) {
|
||||
input.emplace_back(begin, pos);
|
||||
destination.emplace_back(begin, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1441,9 +1441,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void list_prep_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<prep_cmd_t> &input) {
|
||||
void list_prep_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<prep_cmd_t> &destination) {
|
||||
std::string string;
|
||||
string_f(vars, name, string);
|
||||
|
||||
@@ -1465,7 +1465,7 @@ namespace config {
|
||||
auto undo_cmd = prep_cmd.get_optional<std::string>("undo"s);
|
||||
auto elevated = prep_cmd.get_optional<bool>("elevated"s);
|
||||
|
||||
input.emplace_back(do_cmd.value_or(""), undo_cmd.value_or(""), elevated.value_or(false));
|
||||
destination.emplace_back(do_cmd.value_or(""), undo_cmd.value_or(""), elevated.value_or(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1474,9 +1474,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void list_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<int> &input) {
|
||||
void list_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<int> &destination) {
|
||||
std::vector<std::string> list;
|
||||
list_string_f(vars, name, list);
|
||||
|
||||
@@ -1488,7 +1488,7 @@ namespace config {
|
||||
// The framerate list must be cleared before adding values from the file configuration.
|
||||
// If the list is not cleared, then the specified parameters do not affect the behavior of the sunshine server.
|
||||
// That is, if you set only 30 fps in the configuration file, it will not work because by default, during initialization the list includes 10, 30, 60, 90 and 120 fps.
|
||||
input.clear();
|
||||
destination.clear();
|
||||
for (auto &el : list) {
|
||||
std::string_view val = el;
|
||||
|
||||
@@ -1505,7 +1505,7 @@ namespace config {
|
||||
} else {
|
||||
tmp = (int) util::from_view(val);
|
||||
}
|
||||
input.emplace_back(tmp);
|
||||
destination.emplace_back(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1514,9 +1514,9 @@ namespace config {
|
||||
*
|
||||
* @param vars Parsed configuration entries; consumed keys are erased.
|
||||
* @param name Configuration key to consume.
|
||||
* @param input Destination field updated when the setting exists and parses successfully.
|
||||
* @param destination Destination field updated when the setting exists and parses successfully.
|
||||
*/
|
||||
void map_int_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::unordered_map<int, int> &input) {
|
||||
void map_int_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::unordered_map<int, int> &destination) {
|
||||
std::vector<int> list;
|
||||
list_int_f(vars, name, list);
|
||||
|
||||
@@ -1531,7 +1531,7 @@ namespace config {
|
||||
auto key = list[x++];
|
||||
auto val = list[x++];
|
||||
|
||||
input.emplace(key, val);
|
||||
destination.emplace(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user