-
Notifications
You must be signed in to change notification settings - Fork 793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node configuration auto updater #4579
Changes from all commits
2f1f895
39f4528
ccefffc
41edc27
48ebf8d
aa97829
0b79fdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,38 @@ void nano::tomlconfig::erase_default_values (tomlconfig & defaults_a) | |
erase_defaults (defaults_l.get_tree (), self.get_tree (), get_tree ()); | ||
} | ||
|
||
// Merges two TOML configurations and commenting values that are identical | ||
std::string nano::tomlconfig::merge_defaults (nano::tomlconfig & current_config, nano::tomlconfig & default_config) | ||
{ | ||
// Serialize both configs to commented strings | ||
std::string defaults_str = default_config.to_string (true); | ||
std::string current_str = current_config.to_string (true); | ||
|
||
// Read both configs line by line | ||
std::istringstream stream_defaults (defaults_str); | ||
std::istringstream stream_current (current_str); | ||
std::string line_defaults, line_current, result; | ||
|
||
while (std::getline (stream_defaults, line_defaults) && std::getline (stream_current, line_current)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop will only work correctly if the defaults and current lists are sorted and have the same number of elements. Is this guranteed to happen? If yes, how do you know? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current list and default list will always follow the exact same layout. This is because we use the serialize_toml function to create the configs. That function will create all the tree nodes, config items, and docs based on the input |
||
{ | ||
if (line_defaults == line_current) | ||
{ | ||
// Use default value | ||
result += line_defaults + "\n"; | ||
} | ||
else | ||
{ | ||
// Non default value. Removing the # to uncomment | ||
dsiganos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size_t pos = line_current.find ('#'); | ||
debug_assert (pos != std::string::npos); | ||
debug_assert (pos < line_current.length ()); | ||
result += line_current.substr (0, pos) + line_current.substr (pos + 1) + "\n"; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
std::string nano::tomlconfig::to_string (bool comment_values) | ||
{ | ||
std::stringstream ss, ss_processed; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case, a systest would had been a better option.
But you have done it now...