Gazebo Common

API Reference

3.17.0
SpecializedPlugin< SpecInterface > Class Template Reference

This class allows Plugin instances to have high-speed access to interfaces that can be anticipated at compile time. The plugin does not have to actually offer the specialized interface in order to get this performance improvement. This template is variadic, so it can support arbitrarily many interfaces. More...

#include <SpecializedPlugin.hh>

Public Member Functions

template<class Interface >
bool HasInterface () const
 Returns true if this Plugin has the specified type of interface. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName). More...
 
template<class Interface >
bool HasInterface () const
 
bool HasInterface (const std::string &_interfaceName) const
 Returns true if this Plugin has the specified type of interface, otherwise returns false. More...
 
template<class Interface >
Interface * QueryInterface ()
 Get an interface of the specified type. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName). More...
 
template<class Interface >
Interface * QueryInterface ()
 
template<class Interface >
const Interface * QueryInterface () const
 const-qualified version of QueryInterface<Interface>() More...
 
template<class Interface >
const Interface * QueryInterface () const
 
template<class Interface >
Interface * QueryInterface (const std::string &_interfaceName)
 Get an interface with the given name, casted to the specified class type. 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 >
const Interface * QueryInterface (const std::string &_interfaceName) const
 const-qualified version of QueryInterface<Interface>(std::string) More...
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr ()
 Get the requested interface as a std::shared_ptr. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterfaceSharedPtr<Interface>(const std::string&). More...
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr ()
 
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...
 
template<class Interface >
std::shared_ptr< const Interface > QueryInterfaceSharedPtr () const
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr (const std::string &_interfaceName)
 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 std::string &_interfaceName) const
 Same as QueryInterfaceSharedPtr<Interface>(std::string), but it returns a std::shared_ptr to a const-qualified Interface. More...
 
- Public Member Functions inherited from Plugin
virtual ~Plugin ()
 Virtual destructor. More...
 
template<class Interface >
bool HasInterface () const
 Returns true if this Plugin has the specified type of interface. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName). More...
 
bool HasInterface (const std::string &_interfaceName) const
 Returns true if this Plugin has the specified type of interface, otherwise returns false. More...
 
template<class Interface >
Interface * QueryInterface ()
 Get an interface of the specified type. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName). More...
 
template<class Interface >
const Interface * QueryInterface () const
 const-qualified version of QueryInterface<Interface>() More...
 
template<class Interface >
Interface * QueryInterface (const std::string &_interfaceName)
 Get an interface with the given name, casted to the specified class type. 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 >
const Interface * QueryInterface (const std::string &_interfaceName) const
 const-qualified version of QueryInterface<Interface>(std::string) More...
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr ()
 Get the requested interface as a std::shared_ptr. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterfaceSharedPtr<Interface>(const std::string&). 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...
 
template<class Interface >
std::shared_ptr< Interface > QueryInterfaceSharedPtr (const std::string &_interfaceName)
 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 std::string &_interfaceName) const
 Same as QueryInterfaceSharedPtr<Interface>(std::string), but it returns a std::shared_ptr to a const-qualified Interface. More...
 

Additional Inherited Members

- Public Types inherited from Plugin
using InterfaceMap = std::map< std::string, void * >
 The InterfaceMap type needs to get used in several places, like PluginPrivate 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...
 

Detailed Description

template<class SpecInterface>
class ignition::common::SpecializedPlugin< SpecInterface >

This class allows Plugin instances to have high-speed access to interfaces that can be anticipated at compile time. The plugin does not have to actually offer the specialized interface in order to get this performance improvement. This template is variadic, so it can support arbitrarily many interfaces.

Usage example:

using MySpecialPluginPtr = SpecializedPluginPtr<
MyInterface1, FooInterface, MyInterface2, BarInterface>;
MySpecialPluginPtr plugin = loader->Instantiate(pluginName);

Then, calling the function

plugin->QueryInterface<FooInterface>();

will have extremely high-speed associated with it. It will provide direct access to the the FooInterface* of plugin. If plugin does not actually offer FooInterface, then it will return a nullptr, still at extremely high speed.

Only interfaces that have been "specialized" can be passed as arguments to the SpecializedPlugin template. To specialize an interface, simply put the macro IGN_COMMON_SPECIALIZE_INTERFACE(~) from ignition/common/PluginMacros.hh into a public location of its class definition.

Member Function Documentation

◆ HasInterface() [1/3]

bool HasInterface ( class Interface  )

Returns true if this Plugin has the specified type of interface. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName).

◆ HasInterface() [2/3]

bool HasInterface ( ) const

◆ HasInterface() [3/3]

bool HasInterface

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

Parameters
[in]_interfaceNameThe name of the desired interface, as a string.

◆ QueryInterface() [1/6]

Interface* QueryInterface ( class Interface  )

Get an interface of the specified type. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterface<Interface>(_interfaceName).

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.

◆ QueryInterface() [2/6]

Interface* QueryInterface ( )

◆ QueryInterface() [3/6]

const Interface* QueryInterface ( class Interface  )

const-qualified version of QueryInterface<Interface>()

◆ QueryInterface() [4/6]

const Interface* QueryInterface ( ) const

◆ QueryInterface() [5/6]

Interface* QueryInterface ( class Interface  )

Get an interface with the given name, casted to the specified class type. The template argument Interface must exactly match the underlying type associated with _interfaceName, or else the behavior of this function is undefined.

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.

Parameters
[in]_interfaceNameThe name of the desired interface, as a string.
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() [6/6]

const Interface* QueryInterface ( class Interface  )

const-qualified version of QueryInterface<Interface>(std::string)

◆ QueryInterfaceSharedPtr() [1/6]

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

Get the requested interface as a std::shared_ptr. Note that this function only works when the Interface type is specialized using the macro IGN_COMMON_SPECIALIZE_INTERFACE. For more general interfaces which do not meet this condition, use QueryInterfaceSharedPtr<Interface>(const std::string&).

◆ QueryInterfaceSharedPtr() [2/6]

std::shared_ptr<Interface> QueryInterfaceSharedPtr ( )

◆ QueryInterfaceSharedPtr() [3/6]

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

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

◆ QueryInterfaceSharedPtr() [4/6]

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

◆ QueryInterfaceSharedPtr() [5/6]

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

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.

Parameters
[in]_interfaceNameThe name of the desired interface, as a string.
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() [6/6]

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

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


The documentation for this class was generated from the following file:
TemplatePluginPtr< SpecializedPlugin< SpecInterfaces... > > SpecializedPluginPtr
This alias allows PluginPtr instances to have high-speed access to interfaces that can be anticipated...
Definition: gz/common/SpecializedPluginPtr.hh:71