Gazebo Msgs

API Reference

11.0.1
MessageFactory Class Reference

A factory that generates protobuf message based on a string type. This class will also try to load all Protobuf descriptors in paths provided in LoadDescriptors as well as the GZ_DESCRIPTOR_PATH environment variable. More...

#include <MessageFactory.hh>

Public Types

using FactoryFn = std::function< MessagePtr(void)>
 Function that returns unique pointer to base message type.
 
using FactoryFnCollection = std::map< std::string, FactoryFn >
 A map of message types as strings to factory functions.
 
using Message = google::protobuf::Message
 Base message type.
 
using MessagePtr = std::unique_ptr< Message >
 Unique pointer to base message type.
 

Public Member Functions

 MessageFactory ()
 Constructor.
 
 ~MessageFactory ()
 Destructor.
 
void LoadDescriptors (const std::string &_paths)
 Load a collection of descriptor .desc files.
 
template<typename T >
std::unique_ptr< T > New (const std::string &_msgType)
 Create a new instance of a message.
 
MessagePtr New (const std::string &_msgType)
 Create a new instance of a message.
 
template<typename T >
std::unique_ptr< T > New (const std::string &_msgType, const std::string &_args)
 Create a new instance of a message.
 
MessagePtr New (const std::string &_msgType, const std::string &_args)
 Create a new instance of a message.
 
void Register (const std::string &_msgType, FactoryFn _factoryFn)
 Register a message.
 
void Types (std::vector< std::string > &_types)
 Get all the message types.
 

Detailed Description

A factory that generates protobuf message based on a string type. This class will also try to load all Protobuf descriptors in paths provided in LoadDescriptors as well as the GZ_DESCRIPTOR_PATH environment variable.

Member Typedef Documentation

◆ FactoryFn

Function that returns unique pointer to base message type.

◆ FactoryFnCollection

A map of message types as strings to factory functions.

◆ Message

using Message = google::protobuf::Message

Base message type.

◆ MessagePtr

Unique pointer to base message type.

Constructor & Destructor Documentation

◆ MessageFactory()

Constructor.

◆ ~MessageFactory()

Destructor.

Member Function Documentation

◆ LoadDescriptors()

void LoadDescriptors ( const std::string _paths)

Load a collection of descriptor .desc files.

Parameters
[in]_pathsA set of directories containing .desc decriptor files. Each directory should be separated by ":".

◆ New() [1/4]

template<typename T >
std::unique_ptr< T > New ( const std::string _msgType)
inline

Create a new instance of a message.

Parameters
[in]_msgTypeType of message to create.
Returns
Pointer to a google protobuf message. Null if the message type could not be handled.

References MessageFactory::New().

Referenced by Factory::New(), MessageFactory::New(), Factory::New(), and MessageFactory::New().

◆ New() [2/4]

MessagePtr New ( const std::string _msgType)

Create a new instance of a message.

Parameters
[in]_msgTypeType of message to create.
Returns
Pointer to a google protobuf message. Null if the message type could not be handled.

◆ New() [3/4]

template<typename T >
std::unique_ptr< T > New ( const std::string _msgType,
const std::string _args 
)
inline

Create a new instance of a message.

Parameters
[in]_msgTypeType of message to create.
[in]_argsMessage arguments. This will populate the message.
Returns
Pointer to a google protobuf message. Null if the message type could not be handled.

References MessageFactory::New().

◆ New() [4/4]

MessagePtr New ( const std::string _msgType,
const std::string _args 
)

Create a new instance of a message.

Parameters
[in]_msgTypeType of message to create.
[in]_argsMessage arguments. This will populate the message.
Returns
Pointer to a google protobuf message. Null if the message type could not be handled.

◆ Register()

void Register ( const std::string _msgType,
FactoryFn  _factoryFn 
)

Register a message.

Parameters
[in]_msgTypeType of message to register.
[in]_factoryFnFunction that generates the message.

◆ Types()

void Types ( std::vector< std::string > &  _types)

Get all the message types.

Parameters
[out]_typesVector of strings of the message types.

The documentation for this class was generated from the following file: