24 #include <string_view>
34 std::istringstream messageDescriptor(msg_def);
35 std::match_results<std::string::const_iterator> what;
37 for (std::string line; std::getline(messageDescriptor, line,
'\n');)
39 std::string::const_iterator begin = line.begin(), end = line.end();
42 if (std::regex_search(begin, end, what, std::regex(
"(^\\s*$|^\\s*#)")))
49 if (line.compare(0, 5,
"MSG: ") == 0)
64 std::istringstream ss_msg(multi_def);
66 std::vector<std::string> parts;
69 for (std::string line; std::getline(ss_msg, line,
'\n');)
71 if (line.find(
"========") == 0)
91 std::vector<ROSType> known_type;
92 std::vector<ROSMessage::Ptr> parsed_msgs;
98 for (
int i = parts.size() - 1; i >= 0; i--)
100 auto msg = std::make_shared<ROSMessage>(parts[i]);
105 if (
msg->type() == no_type && root_type != no_type)
107 msg->setType(root_type);
109 else if (
msg->type() == no_type && root_type == no_type)
111 std::cout << multi_def << std::endl;
112 throw std::runtime_error(
"Message type unspecified");
117 parsed_msgs.push_back(
msg);
118 known_type.push_back(
msg->type());
122 for (
auto&
msg : parsed_msgs)
127 if (
field.type().pkgName().empty())
129 std::vector<ROSType> guessed_type;
131 for (
const ROSType& known_type : known_type)
133 if (
field.type().msgName() == known_type.msgName())
135 guessed_type.push_back(known_type);
139 if (!guessed_type.empty())
141 bool better_match =
false;
145 for (
const ROSType& guessed_type : guessed_type)
147 if (guessed_type.pkgName() == root_type.
pkgName())
149 field.changeType(guessed_type);
159 field.changeType(guessed_type[0]);
166 std::reverse(parsed_msgs.begin(), parsed_msgs.end());
171 const std::vector<ROSMessage::Ptr>& parsed_msgs)
173 auto schema = std::make_shared<MessageSchema>();
174 schema->topic_name = topic_name;
175 schema->root_msg = parsed_msgs.front();
177 for (
const auto&
msg : parsed_msgs)
179 schema->msg_library.insert({
msg->type(),
msg });
187 const size_t NUM_FIELDS =
msg->fields().size();
188 field_node->children().reserve(NUM_FIELDS);
192 if (
field.isConstant())
197 field_node->addChild(&
field);
198 FieldTreeNode* new_string_node = &(field_node->children().back());
201 if (
field.type().isBuiltin() ==
false)
203 auto new_msg =
field.getMessagePtr(schema->msg_library);
206 throw std::runtime_error(
"Missing ROSType in library");
209 recursiveTreeCreator(new_msg, new_string_node);
215 auto root_field =
new ROSField(schema->root_msg->type(), topic_name);
216 schema->field_tree.root()->setValue(root_field);
218 recursiveTreeCreator(schema->root_msg, schema->field_tree.root());