--Configurations : Expand and unify vector/array-backed value handling#2395
Merged
--Configurations : Expand and unify vector/array-backed value handling#2395
Conversation
aclegg3
approved these changes
May 13, 2024
jturner65
commented
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 | ||
|
|
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Checklist