Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "ros_type_introspection/ros_type.hpp"
00037 #include "ros_type_introspection/helper_functions.hpp"
00038 #include <absl/strings/substitute.h>
00039
00040 namespace RosIntrospection{
00041
00042 ROSType::ROSType(absl::string_view name):
00043 _base_name(name)
00044 {
00045 int pos = -1;
00046 for (size_t i=0; i<name.size(); i++)
00047 {
00048 if(name[i] == '/'){
00049 pos = i;
00050 break;
00051 }
00052 }
00053
00054 if( pos == -1)
00055 {
00056 _msg_name = _base_name;
00057 }
00058 else{
00059 _pkg_name = absl::string_view( _base_name.data(), pos);
00060 pos++;
00061 _msg_name = absl::string_view( _base_name.data() + pos, _base_name.size() - pos);
00062 }
00063
00064 _id = toBuiltinType( _msg_name );
00065 _hash = std::hash<std::string>{}( _base_name );
00066 }
00067
00068 ROSType& ROSType::operator= (const ROSType &other)
00069 {
00070 int pos = other._pkg_name.size();
00071 _base_name = other._base_name;
00072 _pkg_name = absl::string_view( _base_name.data(), pos);
00073 if( pos > 0) pos++;
00074 _msg_name = absl::string_view( _base_name.data() + pos, _base_name.size() - pos);
00075 _id = other._id;
00076 _hash = other._hash;
00077 return *this;
00078 }
00079
00080 ROSType& ROSType::operator= (ROSType &&other)
00081 {
00082 int pos = other._pkg_name.size();
00083 _base_name = std::move( other._base_name );
00084 _pkg_name = absl::string_view( _base_name.data(), pos);
00085 if( pos > 0) pos++;
00086 _msg_name = absl::string_view( _base_name.data() + pos, _base_name.size() - pos);
00087 _id = other._id;
00088 _hash = other._hash;
00089 return *this;
00090 }
00091
00092
00093 void ROSType::setPkgName(absl::string_view new_pkg)
00094 {
00095 assert(_pkg_name.size() == 0);
00096
00097 int pos = new_pkg.size();
00098 _base_name = absl::Substitute("$0/$1", new_pkg, _base_name);
00099
00100 _pkg_name = absl::string_view( _base_name.data(), pos++);
00101 _msg_name = absl::string_view( _base_name.data() + pos, _base_name.size() - pos);
00102
00103 _hash = std::hash<std::string>{}( _base_name );
00104 }
00105
00106
00107 }