Apollo 10.0
自动驾驶开放平台
apollo::external_command::MessageReader类 参考

#include <message_reader.h>

apollo::external_command::MessageReader 的协作图:

Public 成员函数

template<typename T >
void RegisterMessage (const std::string &channel_name)
 Register the message reader with the given channel name.
 
template<typename T >
const T * GetMessage (const std::string &channel_name) const
 Get the message with the channel name.
 

详细描述

在文件 message_reader.h34 行定义.

成员函数说明

◆ GetMessage()

template<typename T >
const T * apollo::external_command::MessageReader::GetMessage ( const std::string &  channel_name) const

Get the message with the channel name.

参数
channel_nameChannel name of the message.
返回
Message with the channel name; return null if no message with the given type and channel name is registered.

在文件 message_reader.h68 行定义.

68 {
69 if (reader_map_.find(channel_name) == reader_map_.end()) {
70 return nullptr;
71 }
72 auto* base_reader = reader_map_.at(channel_name).get();
73 auto* message_reader = dynamic_cast<cyber::Reader<T>*>(base_reader);
74 if (nullptr == message_reader) {
75 return nullptr;
76 }
77 message_reader->Observe();
78 if (message_reader->Empty()) {
79 AERROR << "Failed to get message of " << channel_name;
80 return nullptr;
81 }
82 const auto* message = message_reader->GetLatestObserved().get();
83 return message;
84}
#define AERROR
Definition log.h:44

◆ RegisterMessage()

template<typename T >
void apollo::external_command::MessageReader::RegisterMessage ( const std::string &  channel_name)

Register the message reader with the given channel name.

参数
channel_nameChannel name of the message.

在文件 message_reader.h59 行定义.

59 {
60 // Only register reader when it is not registered before.
61 if (reader_map_.find(channel_name) == reader_map_.end()) {
62 auto reader = node_->CreateReader<T>(channel_name);
63 reader_map_[channel_name] = reader;
64 }
65}

该类的文档由以下文件生成: