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 { return _fields[i]; }
44 
45  const std::vector<ROSField>& fields() const { return _fields; }
46 
47  std::vector<ROSField>& fields() { return _fields; }
48 
49  const ROSType& type() const { return _type; }
50 
51  void setType(const ROSType& new_type ) { _type = new_type; }
52 
53 private:
54 
56  std::vector<ROSField> _fields;
57 };
58 
61 
63 {
64  using Ptr = std::shared_ptr<MessageSchema>;
65 
66  std::string topic_name;
67  FieldTree field_tree;
70 };
71 
72 //------------------------------------------------
73 
74 inline std::ostream& operator<<(std::ostream &os, const ROSMessage& msg )
75 {
76  os << msg.type();
77  return os;
78 }
79 
80 inline std::ostream& operator<<(std::ostream &os, const ROSMessage* msg )
81 {
82  os << msg->type();
83  return os;
84 }
85 
86 std::vector<ROSMessage::Ptr> ParseMessageDefinitions(const std::string& multi_def,
87  const ROSType &type);
88 
89 MessageSchema::Ptr BuildMessageSchema(const std::string& topic_name,
90  const std::vector<ROSMessage::Ptr>& parsed_msgs);
91 
92 }
93 
94 #endif
const ROSField & field(size_t i) const
Definition: ros_message.hpp:43
std::vector< ROSField > & fields()
Definition: ros_message.hpp:47
const ROSType & type() const
Definition: ros_message.hpp:49
std::shared_ptr< ROSMessage > Ptr
Definition: ros_message.hpp:37
const std::vector< ROSField > & fields() const
Definition: ros_message.hpp:45
void setType(const ROSType &new_type)
Definition: ros_message.hpp:51
type
Definition: core.h:1059
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
Definition: ros_field.hpp:45
RosMessageLibrary msg_library
Definition: ros_message.hpp:69
MessageSchema::Ptr BuildMessageSchema(const std::string &topic_name, const std::vector< ROSMessage::Ptr > &parsed_msgs)
std::vector< ROSField > _fields
Definition: ros_message.hpp:56
details::Tree< const ROSField * > FieldTree
Definition: ros_message.hpp:60
details::TreeNode< const ROSField * > FieldTreeNode
Definition: ros_message.hpp:59
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
std::shared_ptr< MessageSchema > Ptr
Definition: ros_message.hpp:64
std::unordered_map< ROSType, std::shared_ptr< ROSMessage > > RosMessageLibrary
Definition: ros_field.hpp:37
ROSMessage(const std::string &msg_def)
Definition: ros_message.cpp:31
std::vector< ROSMessage::Ptr > ParseMessageDefinitions(const std::string &multi_def, const ROSType &type)
Definition: ros_message.cpp:85
Element of the tree. it has a single parent and N >= 0 children.
Definition: tree.hpp:53


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39