Skip to content

Option: fixed missing childs of options with the same unit #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions src/AvTranscoder/Option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void loadOptions(OptionMap& outOptions, void* av_class, int req_flags)
if(!av_class)
return;

// Use multimap because it is possible to have several parent options with the same unit
std::multimap<std::string, std::string> optionUnitToParentName;
std::vector<Option> childOptions;

Expand All @@ -255,39 +256,49 @@ void loadOptions(OptionMap& outOptions, void* av_class, int req_flags)
else
{
outOptions.insert(std::make_pair(option.getName(), option));
optionUnitToParentName.insert(std::make_pair(option.getUnit(), option.getName()));
if(! option.getUnit().empty())
{
optionUnitToParentName.insert(std::make_pair(option.getUnit(), option.getName()));
}
}
}

// iterate on child options
for(std::vector<Option>::iterator itOption = childOptions.begin(); itOption != childOptions.end(); ++itOption)
for(std::vector<Option>::iterator itChild = childOptions.begin(); itChild != childOptions.end(); ++itChild)
{
bool parentFound = false;
for(std::multimap<std::string, std::string>::iterator itUnit = optionUnitToParentName.begin();
itUnit != optionUnitToParentName.end(); ++itUnit)
for(std::multimap<std::string, std::string>::iterator itUnitToParents = optionUnitToParentName.begin();
itUnitToParents != optionUnitToParentName.end(); ++itUnitToParents)
{
if(itUnit->first == itOption->getUnit())
const std::string parentUnit = itUnitToParents->first;
if(parentUnit == itChild->getUnit())
{
std::string nameParentOption = itUnit->second;
Option& parentOption = outOptions.at(nameParentOption);

parentOption.appendChild(*itOption);

// child of a Choice
if(parentOption.getType() == eOptionBaseTypeChoice)
// Get all the parent options with the same unit
std::pair<std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> parentOptions = optionUnitToParentName.equal_range(parentUnit);
for(std::multimap<std::string, std::string>::iterator itParent = parentOptions.first; itParent != parentOptions.second; ++itParent)
{
if(itOption->getDefaultInt() == parentOption.getDefaultInt())
parentOption.setDefaultChildIndex(parentOption.getChilds().size() - 1);
const std::string parentName = itParent->second;
Option& parentOption = outOptions.at(parentName);
parentOption.appendChild(*itChild);

// child of a Choice
if(parentOption.getType() == eOptionBaseTypeChoice)
{
if(itChild->getDefaultInt() == parentOption.getDefaultInt())
parentOption.setDefaultChildIndex(parentOption.getChilds().size() - 1);
}

parentFound = true;
}

parentFound = true;
break;
if(parentFound)
break;
}
}

if(!parentFound)
{
LOG_WARN("Can't find a choice option for " << itOption->getName())
LOG_WARN("Can't find a choice option for " << itChild->getName())
}
}
}
Expand Down