ros_message.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright 2016-2017 Davide Faconti
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 * *******************************************************************/
34 
35 
36 #include <boost/algorithm/string.hpp>
37 #include <boost/utility/string_ref.hpp>
38 #include <boost/utility/string_ref.hpp>
40 #include <boost/regex.hpp>
41 #include <boost/algorithm/string/regex.hpp>
42 
43 namespace RosIntrospection{
44 
45 ROSMessage::ROSMessage(const std::string &msg_def)
46 {
47  std::istringstream messageDescriptor(msg_def);
48  boost::match_results<std::string::const_iterator> what;
49 
50  for (std::string line; std::getline(messageDescriptor, line, '\n') ; )
51  {
52  std::string::const_iterator begin = line.begin(), end = line.end();
53 
54  // Skip empty line or one that is a comment
55  if (boost::regex_search( begin, end, what,
56  boost::regex("(^\\s*$|^\\s*#)")))
57  {
58  continue;
59  }
60 
61  if( line.compare(0, 5, "MSG: ") == 0)
62  {
63  line.erase(0,5);
64  _type = ROSType(line);
65  }
66  else{
67  auto new_field = ROSField(line);
68  _fields.push_back(new_field);
69  }
70  }
71 }
72 
73 void ROSMessage::updateMissingPkgNames(const std::vector<const ROSType*> &all_types)
74 {
75  for (ROSField& field: _fields)
76  {
77  // if package name is missing, try to find msgName in the list of known_type
78  if( field.type().pkgName().size() == 0 )
79  {
80  for (const ROSType* known_type: all_types)
81  {
82  if( field.type().msgName().compare( known_type->msgName() ) == 0 )
83  {
84  field._type.setPkgName( known_type->pkgName() );
85  break;
86  }
87  }
88  }
89  }
90 }
91 
92 } // end namespace
93 
94 
const absl::string_view & pkgName() const
ex.: geometry_msgs/Pose -> "geometry_msgs"
Definition: ros_type.hpp:122
char * begin
char * end
constexpr size_type size() const noexcept
ROSMessage(const std::string &msg_def)
Definition: ros_message.cpp:45
const absl::string_view & msgName() const
ex.: geometry_msgs/Pose -> "Pose"
Definition: ros_type.hpp:117
const ROSField & field(size_t index) const
Get field by index.
Definition: ros_message.hpp:54
const ROSType & type() const
Definition: ros_field.hpp:59
std::vector< ROSField > _fields
Definition: ros_message.hpp:71
void setPkgName(absl::string_view new_pkg)
Definition: ros_type.cpp:93
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
Definition: ros_field.hpp:52
void updateMissingPkgNames(const std::vector< const ROSType * > &all_types)
Definition: ros_message.cpp:73
int compare(string_view x) const noexcept


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Thu May 16 2019 02:39:09