Skip to content

ofParameterGroup contains(string name) if parameter changed name. #6576

@eduardfrigola

Description

@eduardfrigola

Hi everyone.
Playing with ofParameterGroups I found an issue with ofParameterGroup::contains(...)

bool ofParameterGroup::contains(const string& name) const{
return obj->parametersIndex.find(escape(name))!=obj->parametersIndex.end();
}
it also applies in all places where std::map<std::string,std::size_t> parametersIndex; is used.

The issue pops up when you change the name of a parameter that is already inside the parameterGroup. The name changes of the parameter changes, but the name in parametersIndex does, not and so we cannot find our parameter inside the parameterGroup. Because the parameterIndex map is only created when adding parameters, and only modified when removing, the only workaround for this is to remove the element from the group, changing the name, and adding it again. With that changing the order of the elements in the group.

As ofParameter has a public method of ::setName(), this case should be considered right?

As there is no event fired by the ofParameter when the name is changed, I think the best solution is to get rid of parametersIndex and search the parameters vector directly so we get the updated name every time we make the request.

Eduard

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions