Skip to content

--Configurations : Expand and unify vector/array-backed value handling#2395

Merged
jturner65 merged 3 commits intomainfrom
Configs_ExpandVectorHandling
May 13, 2024
Merged

--Configurations : Expand and unify vector/array-backed value handling#2395
jturner65 merged 3 commits intomainfrom
Configs_ExpandVectorHandling

Conversation

@jturner65
Copy link
Copy Markdown
Contributor

Motivation and Context

As an extension of this PR, which provided vector/array-backed support to subconfigurations, and in preparation for #2382 , which brings substantial expansion to the Configuration subsystem capabilities, this PR expands and unifies the handling of vector/array-based configuration fields.

Now, a json construct that is expected to be either an array or an array-like key-value store (where the keys are string representations of the indices of the subsquent array) will be handled by the same code, and a paradigm of consistency is introduced to provide vector set/get access to configuration-based vector-like constructs. A float specialization is also added for the Configuration set/getSubconfigValsOfTypeInVector so that the stored doubles can be provided as floats to the float-expecting consumer, and the existing attributes that had custom handling for arrays of data now use the same generalized functionality.

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@jturner65 jturner65 requested a review from aclegg3 May 13, 2024 17:15
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label May 13, 2024
Comment on lines +638 to +665
std::vector<float> Configuration::getSubconfigValsOfTypeInVector(
const std::string& subCfgName) const {
const ConfigValType desiredType = configValTypeFor<double>();
const auto subCfg = getSubconfigView(subCfgName);
const auto& subCfgTags = subCfg->getKeysByType(desiredType, true);
std::vector<float> res;
res.reserve(subCfgTags.size());
for (const auto& tag : subCfgTags) {
res.emplace_back(static_cast<float>(subCfg->get<double>(tag)));
}
return res;
} // getSubconfigValsOfTypeInVector float specialization

template <>
void Configuration::setSubconfigValsOfTypeInVector(
const std::string& subCfgName,
const std::vector<float>& values) {
auto subCfg = editSubconfig<Configuration>(subCfgName);
// remove existing values in subconfig of specified type
subCfg->removeAllOfType<double>();
// add new values, building string key from index in values array of each
// value.
for (std::size_t i = 0; i < values.size(); ++i) {
const std::string& key = Cr::Utility::formatString("{:.03d}", i);
subCfg->set(key, values[i]);
}
} // setSubconfigValsOfTypeInVector float specialization

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These float specializations enable direct consumption of the vectors of values without the consumer having to massage their data, since we store floating point values internally in Configurations as doubles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for posterity)

@jturner65 jturner65 merged commit b8d5ef8 into main May 13, 2024
@jturner65 jturner65 deleted the Configs_ExpandVectorHandling branch May 13, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants