Skip to content

Commit 3a214c6

Browse files
committed
Allow array property append operator for a non-existing property
1 parent 730f5d2 commit 3a214c6

File tree

1 file changed

+102
-95
lines changed

1 file changed

+102
-95
lines changed

source/bxdatatools/src/properties.cc

Lines changed: 102 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4497,20 +4497,27 @@ namespace datatools {
44974497
_section_start_line_number_,
44984498
_current_line_number_,
44994499
"Property override/append is not allowed for array with key '" << prop_key << "'!");
4500-
DT_PROP_CFG_READ_THROW_IF(! props_.has_key(prop_key),
4501-
std::logic_error,
4502-
_current_filename_,
4503-
_section_name_,
4504-
_section_start_line_number_,
4505-
_current_line_number_,
4506-
"Key '" << prop_key << "' is not used and no append action can be done on it!");
4507-
DT_PROP_CFG_READ_THROW_IF(! props_.is_vector(prop_key),
4508-
std::logic_error,
4509-
_current_filename_,
4510-
_section_name_,
4511-
_section_start_line_number_,
4512-
_current_line_number_,
4513-
"Key '" << prop_key << "' is not a vector property and no append action can be done on it!");
4500+
if (! props_.has_key(prop_key)) {
4501+
// Revert to non "append mode" for array
4502+
array_append = false;
4503+
/*
4504+
DT_PROP_CFG_READ_THROW_IF(true,
4505+
std::logic_error,
4506+
_current_filename_,
4507+
_section_name_,
4508+
_section_start_line_number_,
4509+
_current_line_number_,
4510+
"Key '" << prop_key << "' is not used and no append action can be done on it!");
4511+
*/
4512+
} else {
4513+
DT_PROP_CFG_READ_THROW_IF(! props_.is_vector(prop_key),
4514+
std::logic_error,
4515+
_current_filename_,
4516+
_section_name_,
4517+
_section_start_line_number_,
4518+
_current_line_number_,
4519+
"Key '" << prop_key << "' is not a vector property and no append action can be done on it!");
4520+
}
45144521
} else {
45154522
if (props_.has_key(prop_key)) {
45164523
if (!allow_key_override) {
@@ -4532,7 +4539,7 @@ namespace datatools {
45324539
if (clean_key) {
45334540
props_.clean(prop_key);
45344541
}
4535-
}
4542+
}
45364543
}
45374544
// std::cerr << "***** DEVEL ***" << "About to store property '" << prop_key << "' ************" << std::endl;
45384545

@@ -4649,91 +4656,91 @@ namespace datatools {
46494656
} else {
46504657
// std::cerr << "***** DEVEL ***" << "Append mode vector property '" << prop_key << "' ************" << std::endl;
46514658
if (type == properties::data::TYPE_BOOLEAN_SYMBOL) {
4652-
DT_PROP_CFG_READ_THROW_IF(not props_.is_boolean(prop_key) and not props_.is_vector(prop_key),
4653-
std::logic_error,
4654-
_current_filename_,
4655-
_section_name_,
4656-
_section_start_line_number_,
4657-
_current_line_number_,
4658-
"Original property with key '" << prop_key << "' is not a boolean vector property!");
4659-
4660-
data::vbool v_booleans_appended;
4661-
props_.fetch(prop_key, v_booleans_appended);
4662-
for (auto val : v_booleans) {
4663-
v_booleans_appended.push_back(val);
4664-
}
4665-
props_.update(prop_key, v_booleans_appended);
4666-
}
4659+
DT_PROP_CFG_READ_THROW_IF(not props_.is_boolean(prop_key) and not props_.is_vector(prop_key),
4660+
std::logic_error,
4661+
_current_filename_,
4662+
_section_name_,
4663+
_section_start_line_number_,
4664+
_current_line_number_,
4665+
"Original property with key '" << prop_key << "' is not a boolean vector property!");
4666+
4667+
data::vbool v_booleans_appended;
4668+
props_.fetch(prop_key, v_booleans_appended);
4669+
for (auto val : v_booleans) {
4670+
v_booleans_appended.push_back(val);
4671+
}
4672+
props_.update(prop_key, v_booleans_appended);
4673+
}
46674674
if (type == properties::data::TYPE_INTEGER_SYMBOL) {
4668-
DT_PROP_CFG_READ_THROW_IF(not props_.is_integer(prop_key) and not props_.is_vector(prop_key),
4669-
std::logic_error,
4670-
_current_filename_,
4671-
_section_name_,
4672-
_section_start_line_number_,
4673-
_current_line_number_,
4674-
"Original property with key '" << prop_key << "' is not an integer vector property!");
4675-
4676-
data::vint v_integers_appended;
4677-
props_.fetch(prop_key, v_integers_appended);
4678-
for (auto val : v_integers) {
4679-
v_integers_appended.push_back(val);
4680-
}
4681-
props_.update(prop_key, v_integers_appended);
4675+
DT_PROP_CFG_READ_THROW_IF(not props_.is_integer(prop_key) and not props_.is_vector(prop_key),
4676+
std::logic_error,
4677+
_current_filename_,
4678+
_section_name_,
4679+
_section_start_line_number_,
4680+
_current_line_number_,
4681+
"Original property with key '" << prop_key << "' is not an integer vector property!");
4682+
4683+
data::vint v_integers_appended;
4684+
props_.fetch(prop_key, v_integers_appended);
4685+
for (auto val : v_integers) {
4686+
v_integers_appended.push_back(val);
4687+
}
4688+
props_.update(prop_key, v_integers_appended);
46824689
}
46834690
if (type == properties::data::TYPE_REAL_SYMBOL) {
4684-
DT_PROP_CFG_READ_THROW_IF(not props_.is_real(prop_key) and not props_.is_vector(prop_key),
4685-
std::logic_error,
4686-
_current_filename_,
4687-
_section_name_,
4688-
_section_start_line_number_,
4689-
_current_line_number_,
4690-
"Original property with key '" << prop_key << "' is not a real vector property!");
4691-
data::vdouble v_reals_appended;
4692-
props_.fetch(prop_key, v_reals_appended);
4693-
for (auto val : v_reals) {
4694-
v_reals_appended.push_back(val);
4695-
}
4696-
if (with_explicit_unit) {
4697-
DT_PROP_CFG_READ_THROW_IF(not props_.has_explicit_unit(prop_key),
4698-
std::logic_error,
4699-
_current_filename_,
4700-
_section_name_,
4701-
_section_start_line_number_,
4702-
_current_line_number_,
4703-
"Original real vector key '" << prop_key << "' has no explicit unit!");
4704-
DT_PROP_CFG_READ_THROW_IF(props_.has_unit_symbol(prop_key)
4705-
and props_.get_unit_symbol(prop_key) != unit_symbol,
4706-
std::logic_error,
4707-
_current_filename_,
4708-
_section_name_,
4709-
_section_start_line_number_,
4710-
_current_line_number_,
4711-
"Original real vector key '" << prop_key << "' has unmatching explicit unit '" << props_.get_unit_symbol(prop_key) << "' with respect to appended values with unit '" << unit_symbol << "'!");
4712-
}
4713-
props_.update(prop_key, v_reals_appended);
4691+
DT_PROP_CFG_READ_THROW_IF(not props_.is_real(prop_key) and not props_.is_vector(prop_key),
4692+
std::logic_error,
4693+
_current_filename_,
4694+
_section_name_,
4695+
_section_start_line_number_,
4696+
_current_line_number_,
4697+
"Original property with key '" << prop_key << "' is not a real vector property!");
4698+
data::vdouble v_reals_appended;
4699+
props_.fetch(prop_key, v_reals_appended);
4700+
for (auto val : v_reals) {
4701+
v_reals_appended.push_back(val);
4702+
}
4703+
if (with_explicit_unit) {
4704+
DT_PROP_CFG_READ_THROW_IF(not props_.has_explicit_unit(prop_key),
4705+
std::logic_error,
4706+
_current_filename_,
4707+
_section_name_,
4708+
_section_start_line_number_,
4709+
_current_line_number_,
4710+
"Original real vector key '" << prop_key << "' has no explicit unit!");
4711+
DT_PROP_CFG_READ_THROW_IF(props_.has_unit_symbol(prop_key)
4712+
and props_.get_unit_symbol(prop_key) != unit_symbol,
4713+
std::logic_error,
4714+
_current_filename_,
4715+
_section_name_,
4716+
_section_start_line_number_,
4717+
_current_line_number_,
4718+
"Original real vector key '" << prop_key << "' has unmatching explicit unit '" << props_.get_unit_symbol(prop_key) << "' with respect to appended values with unit '" << unit_symbol << "'!");
4719+
}
4720+
props_.update(prop_key, v_reals_appended);
47144721
}
47154722
if (type == properties::data::TYPE_STRING_SYMBOL) {
4716-
DT_PROP_CFG_READ_THROW_IF(not props_.is_string(prop_key) and not props_.is_vector(prop_key),
4717-
std::logic_error,
4718-
_current_filename_,
4719-
_section_name_,
4720-
_section_start_line_number_,
4721-
_current_line_number_,
4722-
"Original property with key '" << prop_key << "' is not a string vector property!");
4723-
DT_PROP_CFG_READ_THROW_IF(with_explicit_path != props_.is_explicit_path(prop_key),
4724-
std::logic_error,
4725-
_current_filename_,
4726-
_section_name_,
4727-
_section_start_line_number_,
4728-
_current_line_number_,
4729-
"Original string vector key '" << prop_key << "' has unmatching explicit path with respect to appended vector!");
4730-
data::vstring v_strings_appended;
4731-
props_.fetch(prop_key, v_strings_appended);
4732-
for (auto val : v_strings) {
4733-
v_strings_appended.push_back(val);
4734-
}
4735-
props_.update(prop_key, v_strings_appended);
4736-
}
4723+
DT_PROP_CFG_READ_THROW_IF(not props_.is_string(prop_key) and not props_.is_vector(prop_key),
4724+
std::logic_error,
4725+
_current_filename_,
4726+
_section_name_,
4727+
_section_start_line_number_,
4728+
_current_line_number_,
4729+
"Original property with key '" << prop_key << "' is not a string vector property!");
4730+
DT_PROP_CFG_READ_THROW_IF(with_explicit_path != props_.is_explicit_path(prop_key),
4731+
std::logic_error,
4732+
_current_filename_,
4733+
_section_name_,
4734+
_section_start_line_number_,
4735+
_current_line_number_,
4736+
"Original string vector key '" << prop_key << "' has unmatching explicit path with respect to appended vector!");
4737+
data::vstring v_strings_appended;
4738+
props_.fetch(prop_key, v_strings_appended);
4739+
for (auto val : v_strings) {
4740+
v_strings_appended.push_back(val);
4741+
}
4742+
props_.update(prop_key, v_strings_appended);
4743+
}
47374744
}
47384745
}
47394746
prop_description.clear();

0 commit comments

Comments
 (0)