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
using FactoryFn = std::function<MessagePtr(void)> |
Function that returns unique pointer to base message type.
◆ FactoryFnCollection
using FactoryFnCollection = std::map<std::string, FactoryFn> |
A map of message types as strings to factory functions.
◆ Message
using Message = google::protobuf::Message |
Base message type.
◆ MessagePtr
using MessagePtr = std::unique_ptr<Message> |
Unique pointer to base message type.
Constructor & Destructor Documentation
◆ MessageFactory()
MessageFactory | ( | ) |
Constructor.
◆ ~MessageFactory()
~MessageFactory | ( | ) |
Destructor.
Member Function Documentation
◆ LoadDescriptors()
void LoadDescriptors | ( | const std::string & | _paths | ) |
Load a collection of descriptor .desc files.
- Parameters
-
[in] _paths A set of directories containing .desc decriptor files. Each directory should be separated by ":".
◆ New() [1/4]
|
inline |
Create a new instance of a message.
- Parameters
-
[in] _msgType Type 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] _msgType Type of message to create.
- Returns
- Pointer to a google protobuf message. Null if the message type could not be handled.
◆ New() [3/4]
|
inline |
Create a new instance of a message.
- Parameters
-
[in] _msgType Type of message to create. [in] _args Message 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] _msgType Type of message to create. [in] _args Message 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] _msgType Type of message to register. [in] _factoryFn Function that generates the message.
◆ Types()
void Types | ( | std::vector< std::string > & | _types | ) |
Get all the message types.
- Parameters
-
[out] _types Vector of strings of the message types.
The documentation for this class was generated from the following file: