message_definition_cache.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <set>
4 #include <string>
5 #include <unordered_map>
6 #include <unordered_set>
7 #include <utility>
8 
9 namespace foxglove {
10 
11 // Taken from
12 // https://github.com/ros2/rosidl/blob/a57baea5/rosidl_parser/rosidl_parser/definition.py
13 constexpr char SERVICE_REQUEST_MESSAGE_SUFFIX[] = "_Request";
14 constexpr char SERVICE_RESPONSE_MESSAGE_SUFFIX[] = "_Response";
15 constexpr char ACTION_GOAL_SERVICE_SUFFIX[] = "_SendGoal";
16 constexpr char ACTION_RESULT_SERVICE_SUFFIX[] = "_GetResult";
17 constexpr char ACTION_FEEDBACK_MESSAGE_SUFFIX[] = "_FeedbackMessage";
18 
20  IDL,
21  MSG,
22 };
23 
24 struct MessageSpec {
25  MessageSpec(MessageDefinitionFormat format, std::string text, const std::string& package_context);
26  const std::set<std::string> dependencies;
27  const std::string text;
29 };
30 
33  std::string package_resource_name;
34 
35  bool operator==(const DefinitionIdentifier& di) const {
36  return (format == di.format) && (package_resource_name == di.package_resource_name);
37  }
38 };
39 
40 class DefinitionNotFoundError : public std::exception {
41 private:
42  std::string name_;
43 
44 public:
45  explicit DefinitionNotFoundError(std::string name)
46  : name_(std::move(name)) {}
47 
48  const char* what() const noexcept override {
49  return name_.c_str();
50  }
51 };
52 
54 public:
63  std::pair<MessageDefinitionFormat, std::string> get_full_text(
64  const std::string& package_resource_name);
65 
66 private:
68  std::size_t operator()(const DefinitionIdentifier& di) const {
69  std::size_t h1 = std::hash<MessageDefinitionFormat>()(di.format);
70  std::size_t h2 = std::hash<std::string>()(di.package_resource_name);
71  return h1 ^ h2;
72  }
73  };
78  const MessageSpec& load_message_spec(const DefinitionIdentifier& definition_identifier);
79 
80  std::unordered_map<DefinitionIdentifier, MessageSpec, DefinitionIdentifierHash>
82 };
83 
84 std::set<std::string> parse_dependencies(MessageDefinitionFormat format, const std::string& text,
85  const std::string& package_context);
86 
87 } // namespace foxglove
constexpr char ACTION_GOAL_SERVICE_SUFFIX[]
std::set< std::string > parse_dependencies(MessageDefinitionFormat format, const std::string &text, const std::string &package_context)
constexpr char SERVICE_RESPONSE_MESSAGE_SUFFIX[]
constexpr char ACTION_RESULT_SERVICE_SUFFIX[]
std::size_t operator()(const DefinitionIdentifier &di) const
MessageDefinitionFormat format
std::unordered_map< DefinitionIdentifier, MessageSpec, DefinitionIdentifierHash > msg_specs_by_definition_identifier_
bool operator==(const DefinitionIdentifier &di) const
const std::set< std::string > dependencies
constexpr char ACTION_FEEDBACK_MESSAGE_SUFFIX[]
const char * what() const noexcept override
constexpr char SERVICE_REQUEST_MESSAGE_SUFFIX[]
Definition: format.py:1


foxglove_bridge
Author(s): Foxglove
autogenerated on Mon Jul 3 2023 02:12:22