Gazebo Msgs

API Reference

10.3.0
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. More...
 
using FactoryFnCollection = std::map< std::string, FactoryFn >
 A map of message types as strings to factory functions. More...
 
using Message = google::protobuf::Message
 Base message type. More...
 
using MessagePtr = std::unique_ptr< Message >
 Unique pointer to base message type. More...
 

Public Member Functions

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

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]

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.

Referenced by 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]

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: