Gazebo Plugin

API Reference

2.0.3

#include <Plugin.hh>

Public Types

using InterfaceMap = std::map< std::string, void * >
 The InterfaceMap type needs to get used in several places, like Plugin::Implementation and SpecializedPlugin<T>. We make the typedef public so that those other classes can use it without needing to be friends of Plugin. End-users should not have any need for this typedef. More...
 

Public Member Functions

virtual ~Plugin ()
 Virtual destructor. More...
 
template<class Interface >
bool HasInterface () const
 Checks if this Plugin has the specified type of interface. More...
 
bool HasInterface (const std::string &_interfaceName, const bool _demangled=true) const
 Checks if this Plugin has the specified type of interface. More...
 
const std::stringName () const
 Gets the name of this Plugin. More...
 
template<class Interface >
Interface * QueryInterface ()
 Get an interface of the specified type, if it is provided by this plugin. More...
 
template<class Interface >
const Interface * QueryInterface () const
 const-qualified version of QueryInterface<Interface>() More...
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr ()
 Get the requested interface as a std::shared_ptr. The template argument Interface must exactly match the underlying type associated with _interfaceName, or else the behavior of this function is undefined. More...
 
template<class Interface >
std::shared_ptr< const Interface > QueryInterfaceSharedPtr () const
 Same as QueryInterfaceSharedPtr<Interface>(), but it returns a std::shared_ptr to a const-qualified Interface. More...
 

Protected Member Functions

 Plugin ()
 Default constructor. This is kept protected to discourage users from instantiating them directly. They should instead only be retrieved as a PluginPtr from the plugin Loader. More...
 

Member Typedef Documentation

◆ InterfaceMap

The InterfaceMap type needs to get used in several places, like Plugin::Implementation and SpecializedPlugin<T>. We make the typedef public so that those other classes can use it without needing to be friends of Plugin. End-users should not have any need for this typedef.

Constructor & Destructor Documentation

◆ Plugin()

Plugin ( )
protected

Default constructor. This is kept protected to discourage users from instantiating them directly. They should instead only be retrieved as a PluginPtr from the plugin Loader.

◆ ~Plugin()

virtual ~Plugin ( )
virtual

Virtual destructor.

Member Function Documentation

◆ HasInterface() [1/2]

bool HasInterface ( ) const

Checks if this Plugin has the specified type of interface.

Returns
Returns true if this Plugin has the specified type of interface, and false otherwise.

◆ HasInterface() [2/2]

bool HasInterface ( const std::string _interfaceName,
const bool  _demangled = true 
) const

Checks if this Plugin has the specified type of interface.

By default, we expect you to pass in a demangled version of the interface name. If you want to use a mangled version of the name, set the demangled argument to false.

Parameters
[in]_interfaceNameThe name of the desired interface, as a std::string. Note that this expects the name to be mangled.
[in]_demangledIf _interfaceName is demangled, set this to true. If you are instead using the raw mangled name that gets provided by typeid(T).name(), then set _demangled to false.
Returns
Returns true if this Plugin has the specified type of interface, and false otherwise.

◆ Name()

const std::string* Name ( ) const

Gets the name of this Plugin.

Returns
A pointer to the name of this Plugin, or nullptr if this Plugin is not instantiated.

◆ QueryInterface() [1/2]

Interface* QueryInterface ( )

Get an interface of the specified type, if it is provided by this plugin.

Note that the interface pointer you receive is owned by the Plugin object. You MUST NOT ever try to deallocate it yourself. Moreover, the pointer will be invalidated once all Plugin objects that refer to the same Plugin instance are destructed. Use the QueryInterfaceSharedPtr function in order to get a reference-counting pointer to an interface of this Plugin object. The pointer will remain valid as long as the std::shared_ptr provided by QueryInterfaceSharedPtr is alive.

Returns
A raw pointer to the specified interface. If the requested _interfaceName is not provided by this Plugin, this returns a nullptr. This pointer is invalidated when the reference count of the plugin instance drops to zero.

◆ QueryInterface() [2/2]

const Interface* QueryInterface ( ) const

const-qualified version of QueryInterface<Interface>()

◆ QueryInterfaceSharedPtr() [1/2]

std::shared_ptr<Interface> QueryInterfaceSharedPtr ( )

Get the requested interface as a std::shared_ptr. The template argument Interface must exactly match the underlying type associated with _interfaceName, or else the behavior of this function is undefined.

This std::shared_ptr and the interface+plugin that it refers to will remain valid, even if all Plugin objects which refer to the plugin instance are destructed.

You MUST NOT attempt to pass a QueryInterface pointer into a std::shared_ptr yourself; that will result in double-delete memory errors. You must always call QueryInterfaceSharedPtr for a reference- counting pointer to an interface.

Returns
A reference-counting pointer to the specified interface. This will keep the interface valid and the plugin instance alive, even if all Plugin objects that refer to this plugin instance are destructed.

◆ QueryInterfaceSharedPtr() [2/2]

std::shared_ptr<const Interface> QueryInterfaceSharedPtr ( ) const

Same as QueryInterfaceSharedPtr<Interface>(), but it returns a std::shared_ptr to a const-qualified Interface.


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