MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / findMessage

Method findMessage

app/src/DataModel/Importers/ProtoImporter.cpp:1722–1748  ·  view source on GitHub ↗

* @brief Looks up a message by qualified name, dotted partial name, or unqualified name. */

Source from the content-addressed store, hash-verified

1720 * @brief Looks up a message by qualified name, dotted partial name, or unqualified name.
1721 */
1722const DataModel::ProtoMessage* DataModel::ProtoImporter::findMessage(const QString& typeRef) const
1723{
1724 if (typeRef.isEmpty())
1725 return nullptr;
1726
1727 QString needle = typeRef;
1728 while (needle.startsWith(QLatin1Char('.')))
1729 needle.remove(0, 1);
1730
1731 std::function<const ProtoMessage*(const ProtoMessage&)> walk =
1732 [&](const ProtoMessage& m) -> const ProtoMessage* {
1733 if (m.qualifiedName == needle || m.name == needle)
1734 return &m;
1735
1736 for (const auto& sub : m.nested)
1737 if (const auto* r = walk(sub))
1738 return r;
1739
1740 return nullptr;
1741 };
1742
1743 for (const auto& m : m_messages)
1744 if (const auto* r = walk(m))
1745 return r;
1746
1747 return nullptr;
1748}
1749
1750/**
1751 * @brief Returns a pointer to the n-th top-level message, or nullptr if out of range.

Callers

nothing calls this directly

Calls 3

walkFunction · 0.85
isEmptyMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected