@@ -229,6 +229,7 @@ void loadOptions(OptionMap& outOptions, void* av_class, int req_flags)
229
229
if (!av_class)
230
230
return ;
231
231
232
+ // Use multimap because it is possible to have several parent options with the same unit
232
233
std::multimap<std::string, std::string> optionUnitToParentName;
233
234
std::vector<Option> childOptions;
234
235
@@ -255,39 +256,49 @@ void loadOptions(OptionMap& outOptions, void* av_class, int req_flags)
255
256
else
256
257
{
257
258
outOptions.insert (std::make_pair (option.getName (), option));
258
- optionUnitToParentName.insert (std::make_pair (option.getUnit (), option.getName ()));
259
+ if (! option.getUnit ().empty ())
260
+ {
261
+ optionUnitToParentName.insert (std::make_pair (option.getUnit (), option.getName ()));
262
+ }
259
263
}
260
264
}
261
265
262
266
// iterate on child options
263
- for (std::vector<Option>::iterator itOption = childOptions.begin (); itOption != childOptions.end (); ++itOption )
267
+ for (std::vector<Option>::iterator itChild = childOptions.begin (); itChild != childOptions.end (); ++itChild )
264
268
{
265
269
bool parentFound = false ;
266
- for (std::multimap<std::string, std::string>::iterator itUnit = optionUnitToParentName.begin ();
267
- itUnit != optionUnitToParentName.end (); ++itUnit )
270
+ for (std::multimap<std::string, std::string>::iterator itUnitToParents = optionUnitToParentName.begin ();
271
+ itUnitToParents != optionUnitToParentName.end (); ++itUnitToParents )
268
272
{
269
- if (itUnit->first == itOption->getUnit ())
273
+ const std::string parentUnit = itUnitToParents->first ;
274
+ if (parentUnit == itChild->getUnit ())
270
275
{
271
- std::string nameParentOption = itUnit->second ;
272
- Option& parentOption = outOptions.at (nameParentOption);
273
-
274
- parentOption.appendChild (*itOption);
275
-
276
- // child of a Choice
277
- if (parentOption.getType () == eOptionBaseTypeChoice)
276
+ // Get all the parent options with the same unit
277
+ std::pair<std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> parentOptions = optionUnitToParentName.equal_range (parentUnit);
278
+ for (std::multimap<std::string, std::string>::iterator itParent = parentOptions.first ; itParent != parentOptions.second ; ++itParent)
278
279
{
279
- if (itOption->getDefaultInt () == parentOption.getDefaultInt ())
280
- parentOption.setDefaultChildIndex (parentOption.getChilds ().size () - 1 );
280
+ const std::string parentName = itParent->second ;
281
+ Option& parentOption = outOptions.at (parentName);
282
+ parentOption.appendChild (*itChild);
283
+
284
+ // child of a Choice
285
+ if (parentOption.getType () == eOptionBaseTypeChoice)
286
+ {
287
+ if (itChild->getDefaultInt () == parentOption.getDefaultInt ())
288
+ parentOption.setDefaultChildIndex (parentOption.getChilds ().size () - 1 );
289
+ }
290
+
291
+ parentFound = true ;
281
292
}
282
293
283
- parentFound = true ;
284
- break ;
294
+ if ( parentFound)
295
+ break ;
285
296
}
286
297
}
287
298
288
299
if (!parentFound)
289
300
{
290
- LOG_WARN (" Can't find a choice option for " << itOption ->getName ())
301
+ LOG_WARN (" Can't find a choice option for " << itChild ->getName ())
291
302
}
292
303
}
293
304
}
0 commit comments