ros_message.hpp
Go to the documentation of this file.
1 /***** MIT License ****
2  *
3  * Copyright (c) 2016-2022 Davide Faconti
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef ROS_INTROSPECTION_ROSMESSAGE_H
25 #define ROS_INTROSPECTION_ROSMESSAGE_H
26 
27 #include <unordered_map>
30 
31 namespace RosMsgParser
32 {
33 
35 {
36 public:
37  using Ptr = std::shared_ptr<ROSMessage>;
38 
41  ROSMessage(const std::string& msg_def);
42 
43  const ROSField& field(size_t i) const
44  {
45  return _fields[i];
46  }
47 
48  const std::vector<ROSField>& fields() const
49  {
50  return _fields;
51  }
52 
53  std::vector<ROSField>& fields()
54  {
55  return _fields;
56  }
57 
58  const ROSType& type() const
59  {
60  return _type;
61  }
62 
63  void setType(const ROSType& new_type)
64  {
65  _type = new_type;
66  }
67 
68 private:
70  std::vector<ROSField> _fields;
71 };
72 
75 
77 {
78  using Ptr = std::shared_ptr<MessageSchema>;
79 
80  std::string topic_name;
84 };
85 
86 //------------------------------------------------
87 
88 inline std::ostream& operator<<(std::ostream& os, const ROSMessage& msg)
89 {
90  os << msg.type();
91  return os;
92 }
93 
94 inline std::ostream& operator<<(std::ostream& os, const ROSMessage* msg)
95 {
96  os << msg->type();
97  return os;
98 }
99 
100 std::vector<ROSMessage::Ptr> ParseMessageDefinitions(const std::string& multi_def,
101  const ROSType& type);
102 
103 MessageSchema::Ptr BuildMessageSchema(const std::string& topic_name,
104  const std::vector<ROSMessage::Ptr>& parsed_msgs);
105 
106 } // namespace RosMsgParser
107 
108 #endif
RosMsgParser::ROSMessage::Ptr
std::shared_ptr< ROSMessage > Ptr
Definition: ros_message.hpp:37
RosMsgParser::ROSMessage::_fields
std::vector< ROSField > _fields
Definition: ros_message.hpp:70
RosMsgParser::ROSType
ROSType.
Definition: ros_type.hpp:39
RosMsgParser::ROSMessage::fields
const std::vector< ROSField > & fields() const
Definition: ros_message.hpp:48
RosMsgParser::MessageSchema::Ptr
std::shared_ptr< MessageSchema > Ptr
Definition: ros_message.hpp:78
RosMsgParser::MessageSchema::msg_library
RosMessageLibrary msg_library
Definition: ros_message.hpp:83
mqtt_test_proto.msg
msg
Definition: mqtt_test_proto.py:43
RosMsgParser::MessageSchema::topic_name
std::string topic_name
Definition: ros_message.hpp:80
RosMsgParser::ROSMessage::field
const ROSField & field(size_t i) const
Definition: ros_message.hpp:43
RosMsgParser::ROSMessage::fields
std::vector< ROSField > & fields()
Definition: ros_message.hpp:53
RosMsgParser::RosMessageLibrary
std::unordered_map< ROSType, std::shared_ptr< ROSMessage > > RosMessageLibrary
Definition: ros_field.hpp:38
RosMsgParser
Definition: builtin_types.hpp:34
RosMsgParser::MessageSchema::field_tree
FieldTree field_tree
Definition: ros_message.hpp:81
RosMsgParser::ROSMessage::ROSMessage
ROSMessage(const std::string &msg_def)
Definition: ros_message.cpp:32
RosMsgParser::ROSMessage
Definition: ros_message.hpp:34
tree.hpp
RosMsgParser::ROSMessage::_type
ROSType _type
Definition: ros_message.hpp:69
RosMsgParser::FieldTree
details::Tree< const ROSField * > FieldTree
Definition: ros_message.hpp:74
RosMsgParser::MessageSchema::root_msg
ROSMessage::Ptr root_msg
Definition: ros_message.hpp:82
RosMsgParser::ROSMessage::setType
void setType(const ROSType &new_type)
Definition: ros_message.hpp:63
RosMsgParser::BuildMessageSchema
MessageSchema::Ptr BuildMessageSchema(const std::string &topic_name, const std::vector< ROSMessage::Ptr > &parsed_msgs)
Definition: ros_message.cpp:170
RosMsgParser::MessageSchema
Definition: ros_message.hpp:76
RosMsgParser::operator<<
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
Definition: builtin_types.hpp:138
RosMsgParser::ROSMessage::type
const ROSType & type() const
Definition: ros_message.hpp:58
ros_field.hpp
RosMsgParser::details::Tree< const ROSField * >
RosMsgParser::details::TreeNode
Element of the tree. it has a single parent and N >= 0 children.
Definition: tree.hpp:119
RosMsgParser::FieldTreeNode
details::TreeNode< const ROSField * > FieldTreeNode
Definition: ros_message.hpp:73
RosMsgParser::ROSField
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair.
Definition: ros_field.hpp:46
RosMsgParser::ParseMessageDefinitions
std::vector< ROSMessage::Ptr > ParseMessageDefinitions(const std::string &multi_def, const ROSType &type)
Definition: ros_message.cpp:87


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46