ros_type.cpp
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 #include <assert.h>
26 
27 namespace RosMsgParser
28 {
29 
30 ROSType::ROSType(const std::string& name) : _base_name(name)
31 {
32  int pos = -1;
33  for (size_t i = 0; i < name.size(); i++)
34  {
35  if (name[i] == '/')
36  {
37  pos = i;
38  break;
39  }
40  }
41 
42  if (pos == -1)
43  {
45  }
46  else
47  {
48  _pkg_name = std::string_view(_base_name.data(), pos);
49  pos++;
50  _msg_name = std::string_view(_base_name.data() + pos, _base_name.size() - pos);
51  }
52 
54  _hash = std::hash<std::string>{}(_base_name);
55 }
56 
58 {
59  int pos = other._pkg_name.size();
60  _base_name = other._base_name;
61  _pkg_name = std::string_view(_base_name.data(), pos);
62  if (pos > 0)
63  pos++;
64  _msg_name = std::string_view(_base_name.data() + pos, _base_name.size() - pos);
65  _id = other._id;
66  _hash = other._hash;
67  return *this;
68 }
69 
71 {
72  int pos = other._pkg_name.size();
73  _base_name = std::move(other._base_name);
74  _pkg_name = std::string_view(_base_name.data(), pos);
75  if (pos > 0)
76  pos++;
77  _msg_name = std::string_view(_base_name.data() + pos, _base_name.size() - pos);
78  _id = other._id;
79  _hash = other._hash;
80  return *this;
81 }
82 
84 {
85  assert(_pkg_name.size() == 0);
86 
87  size_t pos = new_pkg.size();
88  _base_name = std::string(new_pkg) + "/" + _base_name;
89 
90  _pkg_name = std::string_view(_base_name.data(), pos++);
91  _msg_name = std::string_view(_base_name.data() + pos, _base_name.size() - pos);
92 
93  _hash = std::hash<std::string>{}(_base_name);
94 }
95 
96 } // namespace RosMsgParser
RosMsgParser::ROSType
ROSType.
Definition: ros_type.hpp:39
RosMsgParser::ROSType::operator=
ROSType & operator=(const ROSType &other)
Definition: ros_type.cpp:57
RosMsgParser::ROSType::_hash
size_t _hash
Definition: ros_type.hpp:108
RosMsgParser::ROSType::ROSType
ROSType()
Definition: ros_type.hpp:42
ros_type.hpp
RosMsgParser::toBuiltinType
BuiltinType toBuiltinType(const std::string_view &s)
Definition: ros_type.hpp:151
RosMsgParser
Definition: builtin_types.hpp:34
RosMsgParser::ROSType::setPkgName
void setPkgName(std::string_view new_pkg)
Definition: ros_type.cpp:83
RosMsgParser::ROSType::_base_name
std::string _base_name
Definition: ros_type.hpp:105
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:394
string_view
basic_string_view< char > string_view
Definition: core.h:518
assert
#define assert(condition)
Definition: lz4.c:271
RosMsgParser::ROSType::_id
BuiltinType _id
Definition: ros_type.hpp:104
assert.h
RosMsgParser::ROSType::_msg_name
std::string_view _msg_name
Definition: ros_type.hpp:106
RosMsgParser::ROSType::_pkg_name
std::string_view _pkg_name
Definition: ros_type.hpp:107


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