Skip to content
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

Return only unique message types in MessageFactory::Types function #472

Merged
merged 2 commits into from
Oct 29, 2024
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
24 changes: 16 additions & 8 deletions core/src/MessageFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#include <unordered_set>

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4146 4251)
Expand Down Expand Up @@ -60,16 +62,16 @@ MessageFactory::MessagePtr MessageFactory::New(
{
type = kGzMsgsPrefix + _msgType.substr(8);
}
// Convert ".gz_msgs." prefix
else if (_msgType.find(".gz_msgs.") == 0)
{
type = kGzMsgsPrefix + _msgType.substr(9);
}
// Convert ".gz.msgs." prefix
else if (_msgType.find(".gz.msgs.") == 0)
{
type = kGzMsgsPrefix + _msgType.substr(9);
}
// Convert ".gz_msgs." prefix
else if (_msgType.find(".gz_msgs.") == 0)
{
type = kGzMsgsPrefix + _msgType.substr(9);
}
else
{
type = _msgType;
Expand Down Expand Up @@ -130,15 +132,21 @@ void MessageFactory::Types(std::vector<std::string> &_types)
{
_types.clear();

// Add the types loaded from descriptor files
std::vector<std::string> dynTypes;
this->dynamicFactory->Types(dynTypes);

// Use set to remove duplicates
std::unordered_set<std::string> typesSet(dynTypes.begin(), dynTypes.end());

// Return the list of all known message types.
std::map<std::string, FactoryFn>::const_iterator iter;
for (iter = msgMap.begin(); iter != msgMap.end(); ++iter)
{
_types.push_back(iter->first);
typesSet.insert(iter->first);
}

// Add the types loaded from descriptor files
this->dynamicFactory->Types(_types);
std::copy(typesSet.begin(), typesSet.end(), std::back_inserter(_types));
}

/////////////////////////////////////////////////
Expand Down
Loading