Clang-format Config.?pp

So difficult to work with ATM
This commit is contained in:
Cory Cross
2025-11-04 09:50:47 -08:00
parent 9a591516b8
commit 771e4c0ad2
2 changed files with 2614 additions and 2303 deletions

View File

@@ -231,9 +231,7 @@ std::string escape_ampersand(const std::string& str)
return std::string(out.data(), outptr - out.data());
}
void ConfigOptionDeleter::operator()(ConfigOption* p) {
delete p;
}
void ConfigOptionDeleter::operator()(ConfigOption* p) { delete p; }
std::vector<std::string> ConfigOptionDef::cli_args(const std::string& key) const
{
@@ -280,7 +278,8 @@ ConfigOption* ConfigOptionDef::create_empty_option() const
case coFloatsOrPercents: return new ConfigOptionFloatsOrPercents();
case coPoint: return new ConfigOptionPoint();
case coPoints: return new ConfigOptionPoints();
case coPoint3: return new ConfigOptionPoint3();
case coPoint3:
return new ConfigOptionPoint3();
// case coPoint3s: return new ConfigOptionPoint3s();
case coBool: return new ConfigOptionBool();
case coBools: return new ConfigOptionBools();
@@ -411,8 +410,8 @@ std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, s
// right: option description
std::string descr = def.tooltip;
bool show_defaults_this = show_defaults || def.opt_key == "config_compatibility";
if (show_defaults_this && def.default_value && def.type != coBool
&& (def.type != coString || !def.default_value->serialize().empty())) {
if (show_defaults_this && def.default_value && def.type != coBool &&
(def.type != coString || !def.default_value->serialize().empty())) {
descr += " (";
if (!def.sidetext.empty()) {
descr += def.sidetext + ", ";
@@ -535,7 +534,10 @@ void ConfigBase::set(const std::string &opt_key, int value, bool create)
switch (opt->type()) {
case coInt: static_cast<ConfigOptionInt*>(opt)->value = value; break;
case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
case coFloatOrPercent:
static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value;
static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false;
break;
case coString: static_cast<ConfigOptionString*>(opt)->value = std::to_string(value); break;
default: throw BadOptionTypeException("Configbase::set() - conversion from int not possible");
}
@@ -546,13 +548,19 @@ void ConfigBase::set(const std::string &opt_key, double value, bool create)
ConfigOption* opt = this->option_throw(opt_key, create);
switch (opt->type()) {
case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
case coFloatOrPercent:
static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value;
static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false;
break;
case coString: static_cast<ConfigOptionString*>(opt)->value = float_to_string_decimal_point(value); break;
default: throw BadOptionTypeException("Configbase::set() - conversion from float not possible");
}
}
bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src, const std::string &value_src, ConfigSubstitutionContext& substitutions_ctxt, bool append)
bool ConfigBase::set_deserialize_nothrow(const t_config_option_key& opt_key_src,
const std::string& value_src,
ConfigSubstitutionContext& substitutions_ctxt,
bool append)
{
t_config_option_key opt_key = opt_key_src;
std::string value = value_src;
@@ -570,7 +578,10 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src,
return this->set_deserialize_raw(opt_key, value, substitutions_ctxt, append);
}
void ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, ConfigSubstitutionContext& substitutions_ctxt, bool append)
void ConfigBase::set_deserialize(const t_config_option_key& opt_key_src,
const std::string& value_src,
ConfigSubstitutionContext& substitutions_ctxt,
bool append)
{
if (!this->set_deserialize_nothrow(opt_key_src, value_src, substitutions_ctxt, append))
throw BadOptionValueException(format("Invalid value provided for parameter %1%: %2%", opt_key_src, value_src));
@@ -582,7 +593,10 @@ void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items
this->set_deserialize(item.opt_key, item.opt_value, substitutions_ctxt, item.append);
}
bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, const std::string &value, ConfigSubstitutionContext& substitutions_ctxt, bool append)
bool ConfigBase::set_deserialize_raw(const t_config_option_key& opt_key_src,
const std::string& value,
ConfigSubstitutionContext& substitutions_ctxt,
bool append)
{
t_config_option_key opt_key = opt_key_src;
// Try to deserialize the option by its name.
@@ -642,9 +656,11 @@ bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, con
if (!success && substitutions_ctxt.rule != ForwardCompatibilitySubstitutionRule::Disable &&
// Only allow substitutions of an enum value by another enum value or a boolean value with an enum value.
// That means, we expect enum values being added in the future and possibly booleans being converted to enums.
(optdef->type == coEnum || optdef->type == coEnums || optdef->type == coBool) /*&& ConfigHelpers::looks_like_enum_value(value)*/) {
(optdef->type == coEnum || optdef->type == coEnums ||
optdef->type == coBool) /*&& ConfigHelpers::looks_like_enum_value(value)*/) {
// Deserialize failed, try to substitute with a default value.
//assert(substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::Enable || substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::EnableSilent);
// assert(substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::Enable || substitutions_ctxt.rule ==
// ForwardCompatibilitySubstitutionRule::EnableSilent);
if (optdef->type == coBool)
static_cast<ConfigOptionBool*>(opt)->value = ConfigHelpers::enum_looks_like_true_value(value);
else
@@ -708,17 +724,16 @@ double ConfigBase::get_abs_value(const t_config_option_key &opt_key) const
throw NoDefinitionException(opt_key);
const ConfigOptionDef* opt_def = def->get(opt_key);
assert(opt_def != nullptr);
if (opt_def->ratio_over == "")
return cast_opt->get_abs_value(1);
// Compute absolute value over the absolute value of the base option.
// FIXME there are some ratio_over chains, which end with empty ratio_with.
// For example, XXX_extrusion_width parameters are not handled by get_abs_value correctly.
return opt_def->ratio_over.empty() ? 0. :
return opt_def->ratio_over.empty() ?
0. :
static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->get_abs_value(this->get_abs_value(opt_def->ratio_over));
throw ConfigurationError("ConfigBase::get_abs_value(): Not a valid option type for get_abs_value()");
}
@@ -754,7 +769,8 @@ void ConfigBase::setenv_() const
}
// BBS
ConfigSubstitutions ConfigBase::load_string_map(std::map<std::string, std::string>& key_values, ForwardCompatibilitySubstitutionRule compatibility_rule)
ConfigSubstitutions ConfigBase::load_string_map(std::map<std::string, std::string>& key_values,
ForwardCompatibilitySubstitutionRule compatibility_rule)
{
CNumericLocalesSetter locales_setter;
@@ -764,8 +780,7 @@ ConfigSubstitutions ConfigBase::load_string_map(std::map<std::string, std::strin
try {
t_config_option_key opt_key = it->first;
this->set_deserialize(opt_key, it->second, substitutions_ctxt);
}
catch (UnknownOptionException& /* e */) {
} catch (UnknownOptionException& /* e */) {
// ignore
}
}
@@ -781,8 +796,7 @@ ConfigSubstitutions ConfigBase::load(const std::string &file, ForwardCompatibili
else if (is_json_file(file)) {
std::string reason;
return this->load_from_json(file, compatibility_rule, key_values, reason);
}
else {
} else {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "unsupported format for config file" << file;
return ConfigSubstitutions();
// return this->load_from_ini(file, compatibility_rule);
@@ -790,7 +804,10 @@ ConfigSubstitutions ConfigBase::load(const std::string &file, ForwardCompatibili
}
// BBS: add json support
ConfigSubstitutions ConfigBase::load_from_json(const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule, std::map<std::string, std::string>& key_values, std::string& reason)
ConfigSubstitutions ConfigBase::load_from_json(const std::string& file,
ForwardCompatibilitySubstitutionRule compatibility_rule,
std::map<std::string, std::string>& key_values,
std::string& reason)
{
int ret = 0;
ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
@@ -799,7 +816,11 @@ ConfigSubstitutions ConfigBase::load_from_json(const std::string &file, ForwardC
return std::move(substitutions_ctxt.substitutions);
}
int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContext& substitution_context, bool load_inherits_to_config, std::map<std::string, std::string>& key_values, std::string& reason)
int ConfigBase::load_from_json(const std::string& file,
ConfigSubstitutionContext& substitution_context,
bool load_inherits_to_config,
std::map<std::string, std::string>& key_values,
std::string& reason)
{
json j;
std::list<std::string> different_settings_append;
@@ -810,7 +831,9 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
CNumericLocalesSetter locales_setter;
std::function<bool(const json::const_iterator&, const char,const char,const bool,std::string&)> parse_str_arr = [&parse_str_arr](const json::const_iterator& it, const char single_sep,const char array_sep,const bool escape_string_style,std::string& value_str)->bool {
std::function<bool(const json::const_iterator&, const char, const char, const bool, std::string&)> parse_str_arr =
[&parse_str_arr](const json::const_iterator& it, const char single_sep, const char array_sep, const bool escape_string_style,
std::string& value_str) -> bool {
// must have consistent type name
std::string consistent_type;
for (auto iter = it.value().begin(); iter != it.value().end(); ++iter) {
@@ -832,8 +855,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
bool success = parse_str_arr(iter, single_sep, array_sep, escape_string_style, value_str);
if (!success)
return false;
}
else if (iter.value().is_string()) {
} else if (iter.value().is_string()) {
if (!first)
value_str += single_sep;
else
@@ -845,8 +867,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
value_str += escape_string_cstyle(iter.value());
value_str += "\"";
}
}
else {
} else {
// should not happen
return false;
}
@@ -868,37 +889,27 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
for (auto it = j.begin(); it != j.end(); it++) {
if (boost::iequals(it.key(), BBL_JSON_KEY_VERSION)) {
key_values.emplace(BBL_JSON_KEY_VERSION, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_IS_CUSTOM)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_IS_CUSTOM)) {
// skip it
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) {
key_values.emplace(BBL_JSON_KEY_NAME, it.value());
if (it.value() == "project_settings")
is_project_settings = true;
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) {
key_values.emplace(BBL_JSON_KEY_URL, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_TYPE)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_TYPE)) {
key_values.emplace(BBL_JSON_KEY_TYPE, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_SETTING_ID)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_SETTING_ID)) {
key_values.emplace(BBL_JSON_KEY_SETTING_ID, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_FILAMENT_ID)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_FILAMENT_ID)) {
key_values.emplace(BBL_JSON_KEY_FILAMENT_ID, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_FROM)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_FROM)) {
key_values.emplace(BBL_JSON_KEY_FROM, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_DESCRIPTION)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_DESCRIPTION)) {
key_values.emplace(BBL_JSON_KEY_DESCRIPTION, it.value());
}
else if (boost::iequals(it.key(), BBL_JSON_KEY_INSTANTIATION)) {
} else if (boost::iequals(it.key(), BBL_JSON_KEY_INSTANTIATION)) {
key_values.emplace(BBL_JSON_KEY_INSTANTIATION, it.value());
}
else if (!load_inherits_to_config && boost::iequals(it.key(), BBL_JSON_KEY_INHERITS)) {
} else if (!load_inherits_to_config && boost::iequals(it.key(), BBL_JSON_KEY_INHERITS)) {
key_values.emplace(BBL_JSON_KEY_INHERITS, it.value());
} else if (boost::iequals(it.key(), ORCA_JSON_KEY_RENAMED_FROM)) {
key_values.emplace(ORCA_JSON_KEY_RENAMED_FROM, it.value());
@@ -919,7 +930,8 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
}
} else if (opt_key == "wall_infill_order") {
// BBS: check wall_infill order to decide if it be different and append to diff_setting_append
if (it.value() == "outer wall/inner wall/infill" || it.value() == "infill/outer wall/inner wall" || it.value() == "inner-outer-inner wall/infill") {
if (it.value() == "outer wall/inner wall/infill" || it.value() == "infill/outer wall/inner wall" ||
it.value() == "inner-outer-inner wall/infill") {
get_wall_sequence = "wall_seq_diff_to_system";
}
@@ -928,8 +940,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
is_infill_first = "true";
}
}
}
else if (it.value().is_array()) {
} else if (it.value().is_array()) {
t_config_option_key opt_key_src = opt_key;
this->handle_legacy(opt_key, value_str);
if (opt_key.empty()) {
@@ -958,17 +969,13 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
char array_sep = '#'; // currenty not used
bool escape_string_type = false;
if (optdef) {
switch (optdef->type)
{
switch (optdef->type) {
case coStrings:
escape_string_type = true;
single_sep = ';';
break;
case coPointsGroups:
single_sep = '#';
break;
default:
break;
case coPointsGroups: single_sep = '#'; break;
default: break;
}
}
@@ -980,8 +987,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
}
if (valid)
this->set_deserialize(opt_key, value_str, substitution_context);
}
else {
} else {
// should not happen
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file << " error, invalid json type for " << it.key();
}
@@ -999,7 +1005,8 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
}
if (is_project_settings) {
std::vector<std::string>& different_settings = this->option<ConfigOptionStrings>("different_settings_to_system", true)->values;
std::vector<std::string>& different_settings = this->option<ConfigOptionStrings>("different_settings_to_system", true)
->values;
size_t size = different_settings.size();
if (size == 0) {
size = this->option<ConfigOptionStrings>("filament_settings_id")->values.size() + 2;
@@ -1008,12 +1015,10 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
std::vector<bool> is_first(size, false);
std::vector<std::vector<std::string>> original_diffs(size);
for (int index = 0; index < size; index++)
{
for (int index = 0; index < size; index++) {
if (different_settings[index].empty()) {
is_first[index] = true;
}
else {
} else {
// remove unneeded key
if (get_wall_sequence.empty()) {
std::string wall_sqe_string = "wall_sequence";
@@ -1025,7 +1030,6 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
erase_len++;
different_settings[index].erase(pos, erase_len);
}
}
if (different_settings[index].empty()) {
@@ -1037,8 +1041,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
}
}
for (auto diff_key : different_settings_append)
{
for (auto diff_key : different_settings_append) {
// get the index in the group
int index = 0;
bool need_insert = true;
@@ -1075,18 +1078,15 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
// Perform composite conversions, for example merging multiple keys into one key.
this->handle_legacy_composite();
return 0;
}
catch (const std::ifstream::failure &err) {
} catch (const std::ifstream::failure& err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file << " got a ifstream error, reason = " << err.what();
reason = std::string("ifstreamError: ") + err.what();
// throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file, e.what()));
}
catch(nlohmann::detail::parse_error &err) {
} catch (nlohmann::detail::parse_error& err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file << " got a nlohmann::detail::parse_error, reason = " << err.what();
reason = std::string("JsonParseError: ") + err.what();
// throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file, err.what()));
}
catch(std::exception &err) {
} catch (std::exception& err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file << " got a generic exception, reason = " << err.what();
reason = std::string("std::exception: ") + err.what();
}
@@ -1130,15 +1130,18 @@ ConfigSubstitutions ConfigBase::load_from_ini_string_commented(std::string &&dat
++i;
}
// Skip all leading spaces;
for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++ i) ;
for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++i)
;
// Skip the semicolon (comment indicator).
if (i < data.size() && data[i] == ';')
++i;
// Skip all leading spaces after semicolon.
for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++ i) ;
for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++i)
;
if (strncmp(data.data() + i, "generated by ", 13) == 0) {
// Skip the "; generated by ..." line.
for (; i < data.size() && data[i] != '\n'; ++ i);
for (; i < data.size() && data[i] != '\n'; ++i)
;
}
} else if (data[i] == '\r' && i + 1 < data.size() && data[i + 1] == '\n') {
// Skip CR.
@@ -1175,13 +1178,15 @@ static bool is_end_of_line(char c) { return c == '\r' || c == '\n' || c
static bool is_end_of_gcode_line(char c) { return c == ';' || is_end_of_line(c); }
static bool is_end_of_word(char c) { return is_whitespace(c) || is_end_of_gcode_line(c); }
static const char* skip_word(const char* c) {
static const char* skip_word(const char* c)
{
for (; !is_end_of_word(*c); ++c)
; // silence -Wempty-body
return c;
}
static const char* skip_whitespaces(const char* c) {
static const char* skip_whitespaces(const char* c)
{
for (; is_whitespace(*c); ++c)
; // silence -Wempty-body
return c;
@@ -1210,11 +1215,13 @@ size_t ConfigBase::load_from_gcode_string_legacy(ConfigBase& config, const char*
size_t num_key_value_pairs = 0;
for (;;) {
// Extract next line.
for (--end; end > data_start && (*end == '\r' || *end == '\n'); --end);
for (--end; end > data_start && (*end == '\r' || *end == '\n'); --end)
;
if (end == data_start)
break;
const char* start = end++;
for (; start > data_start && *start != '\r' && *start != '\n'; --start);
for (; start > data_start && *start != '\r' && *start != '\n'; --start)
;
if (start == data_start)
break;
// Extracted a line from start to end. Extract the key = value pair.
@@ -1225,7 +1232,8 @@ size_t ConfigBase::load_from_gcode_string_legacy(ConfigBase& config, const char*
// A key must start with a letter.
break;
const char* sep = key;
for (; sep != end && *sep != '='; ++ sep) ;
for (; sep != end && *sep != '='; ++sep)
;
if (sep == end || sep[-1] != ' ' || sep[1] != ' ')
break;
const char* value = sep + 2;
@@ -1245,8 +1253,7 @@ size_t ConfigBase::load_from_gcode_string_legacy(ConfigBase& config, const char*
try {
config.set_deserialize(std::string(key, key_end), std::string(value, end), substitutions);
++num_key_value_pairs;
}
catch (UnknownOptionException & /* e */) {
} catch (UnknownOptionException& /* e */) {
// ignore
}
end = start;
@@ -1275,7 +1282,8 @@ public:
m_block.assign(m_block_size, 0);
}
bool getline(std::string &out) {
bool getline(std::string& out)
{
out.clear();
for (;;) {
if (m_block_len == 0) {
@@ -1369,8 +1377,7 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
size_t key_value_pairs = 0;
if (has_delimiters)
{
if (has_delimiters) {
// BBS
// PrusaSlicer starting with 2.4.0-alpha0 delimits the config section stored into G-code with
// ; CONFIG_BLOCK_START
@@ -1385,7 +1392,8 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
break;
}
if (!begin_found) {
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Configuration block closing tag \"; CONFIG_BLOCK_START\" not found when reading %1%", file);
// BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Configuration block closing tag \"; CONFIG_BLOCK_START\" not found when
// reading %1%", file);
throw Slic3r::RuntimeError(format("Config tag \"; CONFIG_BLOCK_START\" not found"));
}
std::string key, value;
@@ -1410,12 +1418,11 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
}
}
if (!end_found) {
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Configuration block opening tag \"; CONFIG_BLOCK_END\" not found when reading %1%", file);
// BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Configuration block opening tag \"; CONFIG_BLOCK_END\" not found when
// reading %1%", file);
throw Slic3r::RuntimeError(format("Config tag \"; CONFIG_BLOCK_END\" not found"));
}
}
else
{
} else {
auto header_end_pos = ifs.tellg();
// Slicer older than 2.4.0-alpha0 do not emit any delimiter.
// Try a heuristics reading the G-code from back.
@@ -1430,7 +1437,8 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo
}
if (key_value_pairs < 80) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs);
BOOST_LOG_TRIVIAL(error) << __FUNCTION__
<< format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs);
throw Slic3r::RuntimeError(format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs));
}
@@ -1452,8 +1460,7 @@ void ConfigBase::save_to_json(const std::string &file, const std::string &name,
j[BBL_JSON_KEY_FROM] = from;
// record all the key-values
for (const std::string &opt_key : this->keys())
{
for (const std::string& opt_key : this->keys()) {
const ConfigOption* opt = this->option(opt_key);
if (opt->is_scalar()) {
if (opt->type() == coString && (opt_key != "bed_custom_texture" && opt_key != "bed_custom_model"))
@@ -1461,8 +1468,7 @@ void ConfigBase::save_to_json(const std::string &file, const std::string &name,
j[opt_key] = (dynamic_cast<const ConfigOptionString*>(opt))->value;
else
j[opt_key] = opt->serialize();
}
else {
} else {
const ConfigOptionVectorBase* vec = static_cast<const ConfigOptionVectorBase*>(opt);
// if (!vec->empty())
std::vector<std::string> string_values = vec->vserialize();
@@ -1703,7 +1709,8 @@ t_config_option_keys DynamicConfig::keys() const
return keys;
}
DynamicConfig::DynamicConfigDifference DynamicConfig::diff_report(const DynamicConfig& rhs) const {
DynamicConfig::DynamicConfigDifference DynamicConfig::diff_report(const DynamicConfig& rhs) const
{
DynamicConfig::DynamicConfigDifference result;
std::set<t_config_option_key> all_keys;
@@ -1724,27 +1731,19 @@ DynamicConfig::DynamicConfigDifference DynamicConfig::diff_report(const DynamicC
if (left_has && right_has) {
if (*left_it->second != *right_it->second) {
result.differences[key] = {
left_it->second->serialize(),
right_it->second->serialize()
};
result.differences[key] = {left_it->second->serialize(), right_it->second->serialize()};
}
} else if (left_has) {
result.differences[key] = {
left_it->second->serialize(),
std::nullopt
};
result.differences[key] = {left_it->second->serialize(), std::nullopt};
} else if (right_has) {
result.differences[key] = {
std::nullopt,
right_it->second->serialize()
};
result.differences[key] = {std::nullopt, right_it->second->serialize()};
}
}
return result;
}
std::ostream& operator<<(std::ostream& os, const DynamicConfig::DynamicConfigDifference& diff) {
std::ostream& operator<<(std::ostream& os, const DynamicConfig::DynamicConfigDifference& diff)
{
if (!diff.is_different()) {
os << "Configurations are identical.\n";
return os;
@@ -1774,7 +1773,8 @@ std::ostream& operator<<(std::ostream& os, const DynamicConfig::DynamicConfigDif
os << " -> Right Value: " << detail.right_value.value() << "\n";
}
}
os << "Summary: " << missing_right << " missing on right, " << missing_left << " missing on left, and " << differ << " have differing values\n";
os << "Summary: " << missing_right << " missing on right, " << missing_left << " missing on left, and " << differ
<< " have differing values\n";
return os;
}
@@ -1806,7 +1806,10 @@ t_config_option_keys StaticConfig::keys() const
// Returns true on early exit by fn().
// BBS: add skipped key logic
template<typename Fn>
static inline bool dynamic_config_iterate(const DynamicConfig &lhs, const DynamicConfig &rhs, Fn fn, const std::set<std::string>* skipped_keys = nullptr)
static inline bool dynamic_config_iterate(const DynamicConfig& lhs,
const DynamicConfig& rhs,
Fn fn,
const std::set<std::string>* skipped_keys = nullptr)
{
std::map<t_config_option_key, std::unique_ptr<ConfigOption>>::const_iterator i = lhs.cbegin();
std::map<t_config_option_key, std::unique_ptr<ConfigOption>>::const_iterator j = rhs.cbegin();
@@ -1817,11 +1820,9 @@ static inline bool dynamic_config_iterate(const DynamicConfig &lhs, const Dynami
++j;
else {
assert(i->first == j->first);
if (skipped_keys && (skipped_keys->count(i->first) != 0))
{
if (skipped_keys && (skipped_keys->count(i->first) != 0)) {
// do nothing
}
else if (fn(i->first, i->second.get(), j->second.get()))
} else if (fn(i->first, i->second.get(), j->second.get()))
// Early exit by fn.
return true;
++i;
@@ -1835,8 +1836,8 @@ static inline bool dynamic_config_iterate(const DynamicConfig &lhs, const Dynami
// BBS: add skipped keys logic
bool DynamicConfig::equals(const DynamicConfig& other, const std::set<std::string>* skipped_keys) const
{
return ! dynamic_config_iterate(*this, other,
[](const t_config_option_key & /* key */, const ConfigOption *l, const ConfigOption *r) { return *l != *r; },
return !dynamic_config_iterate(
*this, other, [](const t_config_option_key& /* key */, const ConfigOption* l, const ConfigOption* r) { return *l != *r; },
skipped_keys);
}
@@ -1844,8 +1845,7 @@ bool DynamicConfig::equals(const DynamicConfig &other, const std::set<std::strin
t_config_option_keys DynamicConfig::diff(const DynamicConfig& other) const
{
t_config_option_keys diff;
dynamic_config_iterate(*this, other,
[&diff](const t_config_option_key &key, const ConfigOption *l, const ConfigOption *r) {
dynamic_config_iterate(*this, other, [&diff](const t_config_option_key& key, const ConfigOption* l, const ConfigOption* r) {
if (*l != *r)
diff.emplace_back(key);
// Continue iterating.
@@ -1858,8 +1858,7 @@ t_config_option_keys DynamicConfig::diff(const DynamicConfig &other) const
t_config_option_keys DynamicConfig::equal(const DynamicConfig& other) const
{
t_config_option_keys equal;
dynamic_config_iterate(*this, other,
[&equal](const t_config_option_key &key, const ConfigOption *l, const ConfigOption *r) {
dynamic_config_iterate(*this, other, [&equal](const t_config_option_key& key, const ConfigOption* l, const ConfigOption* r) {
if (*l == *r)
equal.emplace_back(key);
// Continue iterating.
@@ -1868,7 +1867,7 @@ t_config_option_keys DynamicConfig::equal(const DynamicConfig &other) const
return equal;
}
}
} // namespace Slic3r
#include <cereal/types/polymorphic.hpp>
CEREAL_REGISTER_TYPE(Slic3r::ConfigOption)

File diff suppressed because it is too large Load Diff