24 #include <string_view> 33 std::istringstream messageDescriptor(msg_def);
34 std::match_results<std::string::const_iterator> what;
36 for (std::string line; std::getline(messageDescriptor, line,
'\n') ; )
38 std::string::const_iterator begin = line.begin(), end = line.end();
41 if (std::regex_search( begin, end, what,
42 std::regex(
"(^\\s*$|^\\s*#)")))
49 if( line.compare(0, 5,
"MSG: ") == 0)
63 std::istringstream ss_msg(multi_def);
65 std::vector<std::string> parts;
68 for (std::string line; std::getline(ss_msg, line,
'\n') ; )
70 if( line.find(
"========") == 0)
86 const std::string& multi_def,
90 std::vector<ROSType> known_type;
91 std::vector<ROSMessage::Ptr> parsed_msgs;
97 for(
int i = parts.size()-1; i>=0; i--)
99 auto msg = std::make_shared<ROSMessage>(parts[i]);
104 if(
msg->type() == no_type && root_type != no_type )
106 msg->setType( root_type );
108 else if (
msg->type() == no_type && root_type == no_type)
110 std::cout << multi_def << std::endl;
111 throw std::runtime_error(
"Message type unspecified");
116 parsed_msgs.push_back(
msg );
117 known_type.push_back(
msg->type() );
121 for (
auto&
msg: parsed_msgs)
128 for (
const ROSType& known_type : known_type)
145 const std::vector<ROSMessage::Ptr>& parsed_msgs)
147 auto schema = std::make_shared<MessageSchema>();
148 schema->topic_name = topic_name;
149 schema->root_msg = parsed_msgs.front();
151 for(
const auto&
msg: parsed_msgs )
153 schema->msg_library.insert( {
msg->type(),
msg} );
157 std::function<void(ROSMessage::Ptr, FieldTreeNode*)> recursiveTreeCreator;
162 const size_t NUM_FIELDS = msg->fields().size();
163 field_node->children().reserve(NUM_FIELDS);
172 field_node->addChild(&
field);
173 FieldTreeNode* new_string_node = &(field_node->children().back());
181 throw std::runtime_error(
"Missing ROSType in library");
184 recursiveTreeCreator(new_msg, new_string_node);
191 auto root_field =
new ROSField( schema->root_msg->type(), topic_name);
192 schema->field_tree.root()->setValue( root_field );
194 recursiveTreeCreator(schema->root_msg, schema->field_tree.root());
const ROSField & field(size_t i) const
const std::string_view & pkgName() const
ex.: geometry_msgs/Pose -> "geometry_msgs"
const std::string_view & msgName() const
ex.: geometry_msgs/Pose -> "Pose"
std::shared_ptr< ROSMessage > Ptr
std::shared_ptr< ROSMessage > getMessagePtr(const RosMessageLibrary &library) const
static void reverse(lua_State *L, StkId from, StkId to)
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
MessageSchema::Ptr BuildMessageSchema(const std::string &topic_name, const std::vector< ROSMessage::Ptr > &parsed_msgs)
std::vector< ROSField > _fields
void TrimStringLeft(std::string &s)
std::vector< std::string > SplitMultipleMessageDefinitions(const std::string &multi_def)
std::shared_ptr< MessageSchema > Ptr
bool isConstant() const
True if field is a constant in message definition.
bool isBuiltin() const
True if the type is ROS builtin.
const T & move(const T &v)
ROSMessage(const std::string &msg_def)
std::vector< ROSMessage::Ptr > ParseMessageDefinitions(const std::string &multi_def, const ROSType &type)
const ROSType & type() const
Element of the tree. it has a single parent and N >= 0 children.
void changeType(const ROSType &type)