@@ -207,18 +207,35 @@ bool operator==(const ConfigValue& a, const ConfigValue& b) {
207
207
if (a._typeAndFlags != b._typeAndFlags ) {
208
208
return false ;
209
209
}
210
+ const auto dataType = a.getType ();
210
211
// Pointer-backed data types need to have _data dereffed
211
- if (isConfigValTypePointerBased (a.getType ())) {
212
- return pointerBasedConfigTypeHandlerFor (a.getType ())
213
- .comparator (a._data , b._data );
212
+ if (isConfigValTypePointerBased (dataType)) {
213
+ return pointerBasedConfigTypeHandlerFor (dataType).comparator (a._data ,
214
+ b._data );
215
+ }
216
+
217
+ // By here we know the type is a trivial type and that the types for both
218
+ // values are equal
219
+ if (a.reqsFuzzyCompare ()) {
220
+ // Type is specified to require fuzzy comparison
221
+ switch (dataType) {
222
+ case ConfigValType::Double: {
223
+ return Mn::Math::equal (a.get <double >(), b.get <double >());
224
+ }
225
+ default : {
226
+ CORRADE_ASSERT_UNREACHABLE (
227
+ " Unknown/unsupported Type in ConfigValue::operator==()" , " " );
228
+ }
229
+ }
214
230
}
215
231
216
- // Trivial type : a._data holds the actual value
217
- // _data array will always hold only legal data, since a ConfigValue should
218
- // never change type.
232
+ // Trivial non-fuzzy-comparison-requiring type : a._data holds the actual
233
+ // value _data array will always hold only legal data, since a ConfigValue
234
+ // should never change type.
219
235
return std::equal (std::begin (a._data ), std::end (a._data ),
220
236
std::begin (b._data ));
221
- }
237
+
238
+ } // ConfigValue::operator==
222
239
223
240
bool operator !=(const ConfigValue& a, const ConfigValue& b) {
224
241
return !(a == b);
@@ -236,7 +253,7 @@ std::string ConfigValue::getAsString() const {
236
253
return std::to_string (get<int >());
237
254
}
238
255
case ConfigValType::Double: {
239
- return std::to_string ( get<double >());
256
+ return Cr::Utility::formatString ( " {} " , get<double >());
240
257
}
241
258
case ConfigValType::String: {
242
259
return get<std::string>();
@@ -295,7 +312,8 @@ std::string ConfigValue::getAsString() const {
295
312
296
313
io::JsonGenericValue ConfigValue::writeToJsonObject (
297
314
io::JsonAllocator& allocator) const {
298
- // unknown is checked before this function is called, so does not need support
315
+ // unknown is checked before this function is called, so does not need
316
+ // support
299
317
switch (getType ()) {
300
318
case ConfigValType::Boolean : {
301
319
return io::toJsonValue (get<bool >(), allocator);
@@ -487,17 +505,17 @@ int Configuration::loadOneConfigFromJson(int numConfigSettings,
487
505
} else {
488
506
// The array does not match any currently supported magnum
489
507
// objects, so place in indexed subconfig of values.
490
- // decrement count by 1 - the recursive subgroup load will count all the
491
- // values.
508
+ // decrement count by 1 - the recursive subgroup load will count all
509
+ // the values.
492
510
--numConfigSettings;
493
511
// create a new subgroup
494
512
std::shared_ptr<core::config::Configuration> subGroupPtr =
495
513
editSubconfig<core::config::Configuration>(key);
496
514
// load array into subconfig
497
515
numConfigSettings += subGroupPtr->loadFromJsonArray (jsonObj);
498
516
}
499
- // value in array is a number of specified length, else it is a string, an
500
- // object or a nested array
517
+ // value in array is a number of specified length, else it is a string,
518
+ // an object or a nested array
501
519
} else {
502
520
// decrement count by 1 - the recursive subgroup load will count all the
503
521
// values.
@@ -584,8 +602,8 @@ void Configuration::writeValuesToJson(io::JsonGenericValue& jsonObj,
584
602
<< " `, so nothing will be written to JSON for this key." ;
585
603
586
604
} else if (valIter->second .shouldWriteToFile ()) {
587
- // Create Generic value for key, using allocator, to make sure its a copy
588
- // and lives long enough
605
+ // Create Generic value for key, using allocator, to make sure its a
606
+ // copy and lives long enough
589
607
writeValueToJsonInternal (valIter->second , valIter->first .c_str (), jsonObj,
590
608
allocator);
591
609
} else {
@@ -602,8 +620,8 @@ void Configuration::writeSubconfigsToJson(io::JsonGenericValue& jsonObj,
602
620
++cfgIter) {
603
621
// only save if subconfig tree has value entries
604
622
if (cfgIter->second ->getConfigTreeNumValues () > 0 ) {
605
- // Create Generic value for key, using allocator, to make sure its a copy
606
- // and lives long enough
623
+ // Create Generic value for key, using allocator, to make sure its a
624
+ // copy and lives long enough
607
625
io::JsonGenericValue name{cfgIter->first .c_str (), allocator};
608
626
io::JsonGenericValue subObj =
609
627
cfgIter->second ->writeToJsonObject (allocator);
@@ -663,9 +681,9 @@ void Configuration::setSubconfigValsOfTypeInVector(
663
681
/* *
664
682
* @brief Retrieves a shared pointer to a copy of the subConfig @ref
665
683
* esp::core::config::Configuration that has the passed @p name . This will
666
- * create a pointer to a new sub-configuration if none exists already with that
667
- * name, but will not add this configuration to this Configuration's internal
668
- * storage.
684
+ * create a pointer to a new sub-configuration if none exists already with
685
+ * that name, but will not add this configuration to this Configuration's
686
+ * internal storage.
669
687
*
670
688
* @param name The name of the configuration to retrieve.
671
689
* @return A pointer to a copy of the configuration having the requested
@@ -866,7 +884,7 @@ Mn::Debug& operator<<(Mn::Debug& debug, const Configuration& cfg) {
866
884
867
885
bool operator ==(const Configuration& a, const Configuration& b) {
868
886
if ((a.getNumSubconfigs () != b.getNumSubconfigs ()) ||
869
- (a.getNumValues () != b.getNumValues ())) {
887
+ (a.getNumVisibleValues () != b.getNumVisibleValues ())) {
870
888
return false ;
871
889
}
872
890
for (const auto & entry : a.configMap_ ) {
0 commit comments