DCCL v3
Classes | Static Public Member Functions | Friends | List of all members
dccl::DynamicProtobufManager Class Reference

Helper class for creating google::protobuf::Message objects that are not statically compiled into the application. More...

#include <dccl/dynamic_protobuf_manager.h>

Static Public Member Functions

static const google::protobuf::Descriptor * find_descriptor (const std::string &protobuf_type_name)
 Finds the Google Protobuf Descriptor (essentially a meta-class for a given Message) from a given Message name. More...
 
template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer new_protobuf_message (const std::string &protobuf_type_name)
 Create a new (empty) Google Protobuf message of a given type by name. More...
 
template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer new_protobuf_message (const google::protobuf::Descriptor *desc)
 Create a new (empty) Google Protobuf message of a given type by Descriptor. More...
 
static boost::shared_ptr< google::protobuf::Messagenew_protobuf_message (const google::protobuf::Descriptor *desc)
 Create a new (empty) Google Protobuf message of a given type by Descriptor. More...
 
static boost::shared_ptr< google::protobuf::Messagenew_protobuf_message (const std::string &protobuf_type_name)
 Create a new (empty) Google Protobuf message of a given type by name. More...
 
static void add_database (boost::shared_ptr< google::protobuf::DescriptorDatabase > database)
 Add a Google Protobuf DescriptorDatabase to the set of databases searched for Message Descriptors.
 
static void enable_compilation ()
 Enable on the fly compilation of .proto files on the local disk. Must be called before load_from_proto_file() is called.
 
static const google::protobuf::FileDescriptor * load_from_proto_file (const std::string &protofile_absolute_path)
 Load a message from a .proto file on the disk. enable_compilation() must be called first. More...
 
static void add_include_path (const std::string &path)
 Add a path for searching for import messages when loading .proto files using load_from_proto_file() More...
 
static void * load_from_shared_lib (const std::string &shared_lib_path)
 Load compiled .proto files from a UNIX shared library (i.e. *.so or *.dylib) More...
 
static void protobuf_shutdown ()
 
static const google::protobuf::FileDescriptor * add_protobuf_file (const google::protobuf::FileDescriptorProto &proto)
 Add a protobuf file defined in a google::protobuf::FileDescriptorProto.
 
static google::protobuf::DynamicMessageFactory & msg_factory ()
 
static google::protobuf::DescriptorPool & user_descriptor_pool ()
 
static google::protobuf::SimpleDescriptorDatabase & simple_database ()
 
static void reset ()
 

Friends

template<typename T >
void boost::checked_delete (T *)
 

Detailed Description

Helper class for creating google::protobuf::Message objects that are not statically compiled into the application.

Definition at line 43 of file dynamic_protobuf_manager.h.

Member Function Documentation

◆ add_include_path()

static void dccl::DynamicProtobufManager::add_include_path ( const std::string &  path)
inlinestatic

Add a path for searching for import messages when loading .proto files using load_from_proto_file()

Exceptions
ExceptionIf enable_compilation() has not been called before using this function.

Definition at line 143 of file dynamic_protobuf_manager.h.

◆ find_descriptor()

static const google::protobuf::Descriptor* dccl::DynamicProtobufManager::find_descriptor ( const std::string &  protobuf_type_name)
inlinestatic

Finds the Google Protobuf Descriptor (essentially a meta-class for a given Message) from a given Message name.

Parameters
protobuf_type_nameThe fully qualified name of the Google Protobuf Message including package name. E.g. in the .proto file:
package dccl.protobuf
message A { }
would result in protobuf_type_name == "dccl.protobuf.A"

Definition at line 54 of file dynamic_protobuf_manager.h.

◆ load_from_proto_file()

const google::protobuf::FileDescriptor * dccl::DynamicProtobufManager::load_from_proto_file ( const std::string &  protofile_absolute_path)
static

Load a message from a .proto file on the disk. enable_compilation() must be called first.

Parameters
protofile_absolute_pathIt is critical that the argument be the absolute, canonical path to the file. (No relative paths and no "." or "..") This could be achieved, e.g., by using Boost filesystem as follows...
boost::filesystem::path abs_path = boost::filesystem::complete(rel_path);
abs_path.normalize();
Exceptions
ExceptionIf enable_compilation() has not been called before using this function
ExceptionIf any error exists in locating or parsing this .proto file.

It is critical that the argument be the absolute, canonical path to the file. This could be achieved, e.g., by using Boost filesystem as follows... boost::filesystem::path abs_path = boost::filesystem::complete(rel_path); abs_path.normalize();

Definition at line 60 of file dynamic_protobuf_manager.cpp.

◆ load_from_shared_lib()

static void* dccl::DynamicProtobufManager::load_from_shared_lib ( const std::string &  shared_lib_path)
inlinestatic

Load compiled .proto files from a UNIX shared library (i.e. *.so or *.dylib)

Parameters
shared_lib_pathPath to shared library. May be relative if known by ld.so

Definition at line 154 of file dynamic_protobuf_manager.h.

◆ new_protobuf_message() [1/4]

template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer dccl::DynamicProtobufManager::new_protobuf_message ( const google::protobuf::Descriptor *  desc)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by Descriptor.

Parameters
descThe Google Protobuf Descriptor of the message to create.
Template Parameters
GoogleProtobufMessagePointerA pointer or anything that acts like a pointer (has operator*()) to a google::protobuf::Message
Returns
A pointer to the newly created object. Deleting the memory is up to the caller of this function, so smart pointers (e.g. boost::shared_ptr<google::protobuf::Message>) are recommended.

Definition at line 92 of file dynamic_protobuf_manager.h.

◆ new_protobuf_message() [2/4]

static boost::shared_ptr<google::protobuf::Message> dccl::DynamicProtobufManager::new_protobuf_message ( const google::protobuf::Descriptor *  desc)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by Descriptor.

Parameters
descThe Google Protobuf Descriptor of the message to create.
Returns
A boost::shared_ptr to the newly created object.

Definition at line 100 of file dynamic_protobuf_manager.h.

◆ new_protobuf_message() [3/4]

template<typename GoogleProtobufMessagePointer >
static GoogleProtobufMessagePointer dccl::DynamicProtobufManager::new_protobuf_message ( const std::string &  protobuf_type_name)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by name.

Parameters
protobuf_type_nameThe fully qualified name of the Google Protobuf Message including package name. E.g. in the .proto file:
package dccl.protobuf
message A { }
would result in protobuf_type_name == "dccl.protobuf.A"
Template Parameters
GoogleProtobufMessagePointerA pointer or anything that acts like a pointer (has operator*()) to a google::protobuf::Message
Returns
A pointer to the newly created object. Deleting the memory is up to the caller of this function, so smart pointers (e.g. boost::shared_ptr<google::protobuf::Message>) are recommended.

Definition at line 76 of file dynamic_protobuf_manager.h.

◆ new_protobuf_message() [4/4]

static boost::shared_ptr<google::protobuf::Message> dccl::DynamicProtobufManager::new_protobuf_message ( const std::string &  protobuf_type_name)
inlinestatic

Create a new (empty) Google Protobuf message of a given type by name.

Parameters
protobuf_type_nameThe full name (including package) of the Google Protobuf message to create (e.g. "package.MyMessage").
Returns
A boost::shared_ptr to the newly created object.

Definition at line 108 of file dynamic_protobuf_manager.h.


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