Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Fix ROSMessage::updateMissingPkgNames() for ambiguous message names #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 21 additions & 12 deletions src/ros_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* SOFTWARE.
*/

#include <algorithm>

#include <boost/algorithm/string.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/utility/string_ref.hpp>
Expand Down Expand Up @@ -64,23 +66,30 @@ ROSMessage::ROSMessage(const std::string &msg_def)

void ROSMessage::updateMissingPkgNames(const std::vector<const ROSType*> &all_types)
{
// From http://wiki.ros.org/msg#Fields
// When embedding other Message descriptions, the type name may be relative
// (e.g. "Point32") if it is in the same package; otherwise it must be the
// full Message type (e.g. "std_msgs/String"). The only exception to this
// rule is Header.
for (ROSField& field: _fields)
{
// if package name is missing, try to find msgName in the list of known_type
if( field.type().pkgName().size() == 0 )
// if package name is missing, try to find pkgName/msgName in the list of all_types
if( field.type().pkgName().size() != 0 ) continue;
const auto found = std::find_if(
all_types.begin(), all_types.end(),
[&](const ROSType* known_type) {
return ( (this->type().pkgName().compare( known_type->pkgName() ) == 0) &&
(field.type().msgName().compare( known_type->msgName() ) == 0) );
});
if (found != all_types.end())
{
field._type.setPkgName( (*found)->pkgName() );
}
else if ( field.type().msgName() == "Header" )
{
for (const ROSType* known_type: all_types)
{
if( field.type().msgName().compare( known_type->msgName() ) == 0 )
{
field._type.setPkgName( known_type->pkgName() );
break;
}
}
field._type.setPkgName( "std_msgs" );
}
}
}

} // end namespace


2 changes: 1 addition & 1 deletion src/ros_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void Parser::registerMessage(const std::string& definition)
next_msg = getMessageByType(field.type());
if (next_msg == nullptr)
{
throw std::runtime_error("This type was not registered ");
throw std::runtime_error("Type " + field.type().baseName() + " was not registered");
}
msg_node->addChild(next_msg);
MessageTreeNode* new_msg_node = &(msg_node->children().back());
Expand Down