Skip to content
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

Updated PrintParams to not print info text to config files per #3943 #3947

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/ccutil/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,44 @@ bool ParamUtils::GetParamAsString(const char *name, const ParamsVectors *member_

void ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
int num_iterations = (member_params == nullptr) ? 1 : 2;
// When printing to stdout info text is included.
// Info text is omitted when printing to a file (would result in an invalid config file).
bool print_info = (fp == stdout) ? true : false;
std::ostringstream stream;
stream.imbue(std::locale::classic());
for (int v = 0; v < num_iterations; ++v) {
const ParamsVectors *vec = (v == 0) ? GlobalParams() : member_params;
for (auto int_param : vec->int_params) {
stream << int_param->name_str() << '\t' << (int32_t)(*int_param) << '\t'
<< int_param->info_str() << '\n';
if (print_info) {
stream << int_param->name_str() << '\t' << (int32_t)(*int_param) << '\t'
<< int_param->info_str() << '\n';
} else {
stream << int_param->name_str() << '\t' << (int32_t)(*int_param) << '\n';
}
}
for (auto bool_param : vec->bool_params) {
stream << bool_param->name_str() << '\t' << bool(*bool_param) << '\t'
<< bool_param->info_str() << '\n';
if (print_info) {
stream << bool_param->name_str() << '\t' << bool(*bool_param) << '\t'
<< bool_param->info_str() << '\n';
} else {
stream << bool_param->name_str() << '\t' << bool(*bool_param) << '\n';
}
}
for (auto string_param : vec->string_params) {
stream << string_param->name_str() << '\t' << string_param->c_str() << '\t'
<< string_param->info_str() << '\n';
if (print_info) {
stream << string_param->name_str() << '\t' << string_param->c_str() << '\t'
<< string_param->info_str() << '\n';
} else {
stream << string_param->name_str() << '\t' << string_param->c_str() << '\n';
}
}
for (auto double_param : vec->double_params) {
stream << double_param->name_str() << '\t' << (double)(*double_param) << '\t'
<< double_param->info_str() << '\n';
if (print_info) {
stream << double_param->name_str() << '\t' << (double)(*double_param) << '\t'
<< double_param->info_str() << '\n';
} else {
stream << double_param->name_str() << '\t' << (double)(*double_param) << '\n';
}
}
}
fprintf(fp, "%s", stream.str().c_str());
Expand Down