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  // Trim start of line
62  line.erase(line.begin(), std::find_if(line.begin(), line.end(),
63  std::not1(std::ptr_fun<int, int>(std::isspace))));
64 
65  if( line.compare(0, 5, "MSG: ") == 0)
66  {
67  line.erase(0,5);
68  _type = ROSType(line);
69  }
70  else{
71  auto new_field = ROSField(line);
72  _fields.push_back(new_field);
73  }
74  }
75 }
76 
77 void ROSMessage::updateMissingPkgNames(const std::vector<const ROSType*> &all_types)
78 {
79  for (ROSField& field: _fields)
80  {
81  // if package name is missing, try to find msgName in the list of known_type
82  if( field.type().pkgName().size() == 0 )
83  {
84  for (const ROSType* known_type: all_types)
85  {
86  if( field.type().msgName().compare( known_type->msgName() ) == 0 )
87  {
88  field._type.setPkgName( known_type->pkgName() );
89  break;
90  }
91  }
92  }
93  }
94 }
95 
96 } // end namespace
97 
98 
const boost::string_ref & pkgName() const
ex.: geometry_msgs/Pose -> "geometry_msgs"
Definition: ros_type.hpp:122
ROSMessage(const std::string &msg_def)
Definition: ros_message.cpp:45
void setPkgName(boost::string_ref new_pkg)
Definition: ros_type.cpp:92
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
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:77
const boost::string_ref & msgName() const
ex.: geometry_msgs/Pose -> "Pose"
Definition: ros_type.hpp:117


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Sun Sep 6 2020 03:19:54