自动生成ROS(机器人操作系统)message C++ 头文件包含如下类型定义:
typedef ::std_msgs::Header_<std::allocator<void> > Header;
什么是std::allocator<void>
意思是这里?为什么是模板类型void
?这是什么意思?什么时候使用?
这是文档std::allocator<>
:
- https://www.cplusplus.com/reference/memory/allocator/
- https://en.cppreference.com/w/cpp/memory/allocator
这是要查看的自动生成文件的示例:http://docs.ros.org/en/electric/api/std_msgs/html/msg__gen_2cpp_2include_2std__msgs_2Header_8h_source.html.
上面的第一行是第 116 行。
这是自动生成的 ROS 消息的开始Header_
class:
template <class ContainerAllocator>
struct Header_ {
这是自动生成的更多上下文Header.h,与各种typedef
s 在底部:
template <class ContainerAllocator>
struct Header_ {
typedef Header_<ContainerAllocator> Type;
Header_()
: seq(0)
, stamp()
, frame_id()
{
}
Header_(const ContainerAllocator& _alloc)
: seq(0)
, stamp()
, frame_id(_alloc)
{
}
typedef uint32_t _seq_type;
uint32_t seq;
typedef ros::Time _stamp_type;
ros::Time stamp;
typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _frame_id_type;
std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > frame_id;
private:
static const char* __s_getDataType_() { return "std_msgs/Header"; }
public:
ROS_DEPRECATED static const std::string __s_getDataType() { return __s_getDataType_(); }
ROS_DEPRECATED const std::string __getDataType() const { return __s_getDataType_(); }
private:
static const char* __s_getMD5Sum_() { return "2176decaecbce78abc3b96ef049fabed"; }
public:
ROS_DEPRECATED static const std::string __s_getMD5Sum() { return __s_getMD5Sum_(); }
ROS_DEPRECATED const std::string __getMD5Sum() const { return __s_getMD5Sum_(); }
private:
static const char* __s_getMessageDefinition_() { return "# Standard metadata for higher-level stamped data types.\n\
# This is generally used to communicate timestamped data \n\
# in a particular coordinate frame.\n\
# \n\
# sequence ID: consecutively increasing ID \n\
uint32 seq\n\
#Two-integer timestamp that is expressed as:\n\
# * stamp.secs: seconds (stamp_secs) since epoch\n\
# * stamp.nsecs: nanoseconds since stamp_secs\n\
# time-handling sugar is provided by the client library\n\
time stamp\n\
#Frame this data is associated with\n\
# 0: no frame\n\
# 1: global frame\n\
string frame_id\n\
\n\
"; }
public:
ROS_DEPRECATED static const std::string __s_getMessageDefinition() { return __s_getMessageDefinition_(); }
ROS_DEPRECATED const std::string __getMessageDefinition() const { return __s_getMessageDefinition_(); }
ROS_DEPRECATED virtual uint8_t *serialize(uint8_t *write_ptr, uint32_t seq) const
{
ros::serialization::OStream stream(write_ptr, 1000000000);
ros::serialization::serialize(stream, seq);
ros::serialization::serialize(stream, stamp);
ros::serialization::serialize(stream, frame_id);
return stream.getData();
}
ROS_DEPRECATED virtual uint8_t *deserialize(uint8_t *read_ptr)
{
ros::serialization::IStream stream(read_ptr, 1000000000);
ros::serialization::deserialize(stream, seq);
ros::serialization::deserialize(stream, stamp);
ros::serialization::deserialize(stream, frame_id);
return stream.getData();
}
ROS_DEPRECATED virtual uint32_t serializationLength() const
{
uint32_t size = 0;
size += ros::serialization::serializationLength(seq);
size += ros::serialization::serializationLength(stamp);
size += ros::serialization::serializationLength(frame_id);
return size;
}
typedef boost::shared_ptr< ::std_msgs::Header_<ContainerAllocator> > Ptr;
typedef boost::shared_ptr< ::std_msgs::Header_<ContainerAllocator> const> ConstPtr;
boost::shared_ptr<std::map<std::string, std::string> > __connection_header;
}; // struct Header
typedef ::std_msgs::Header_<std::allocator<void> > Header;
typedef boost::shared_ptr< ::std_msgs::Header> HeaderPtr;
typedef boost::shared_ptr< ::std_msgs::Header const> HeaderConstPtr;
Related
我相信这些不是重复的:
-
什么是分配器- 不是重复的,因为我问的是具体情况
T
is void
,不是 a 的一般情况std::allocator<>
.
-
弃用 std::allocator- 不是重复的,因为我不知道为什么它在 C++20 中被弃用或更改,我问的是
std::allocator<void>
case 是一般情况,它的作用以及何时/为何使用它。
- https://answers.ros.org/question/212857/what-is-constptr/