Gazebo Plugin

API Reference

3.0.0
TemplatePluginPtr< PluginType > Class Template Referencefinal

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the Loader class or by copy-construction or assignment from another PluginPtr instance. More...

#include <PluginPtr.hh>

Public Member Functions

 TemplatePluginPtr ()
 Default constructor. Creates a PluginPtr object that does not point to any plugin instance. IsEmpty() will return true until a plugin instance is provided.
 
 TemplatePluginPtr (const TemplatePluginPtr &_other)
 Copy constructor. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership.
 
template<typename OtherPluginType >
 TemplatePluginPtr (const TemplatePluginPtr< OtherPluginType > &_other)
 Casting constructor. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. This essentially allows casting between PluginPtrs that are holding different types of plugin wrappers (for example, you can cast a generic PluginPtr to any SpecializedPluginPtr type, or you can cast between different types of specializations).
 
 TemplatePluginPtr (TemplatePluginPtr &&_other)
 Move constructor. This PluginPtr will take ownership of the plugin instance held by _other. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing which is being moved.
 
 ~TemplatePluginPtr ()=default
 Destructor. Deletes this PluginPtr's reference to the plugin instance. Once all PluginPtrs that refer to a plugin instance are deleted, the plugin will also be deleted.
 
void Clear ()
 Clears the Plugin instance from this PluginPtr. IsEmpty() will return true after this is used, and none of the interfaces will be available any longer.
 
std::size_t Hash () const
 Produces a hash for the plugin instance that this PluginPtr is holding. This function allows PluginPtr instances to be used as values in a std::unordered_set<PluginPtr> or keys in a std::unordered_map<PluginPtr, T>. Using this function directly should not normally be necessary.
 
bool IsEmpty () const
 Check whether this is pointing at a valid plugin.
 
 operator bool () const
 Implicitly convert this PluginPtr to a boolean.
 
bool operator!= (const TemplatePluginPtr &_other) const
 Comparison operator.
 
PluginTypeoperator* () const
 Get a reference to the wrapper for the plugin instance that is being managed by this PluginPtr.
 
PluginTypeoperator-> () const
 Access the wrapper for the plugin instance and call one of its member functions.
 
bool operator< (const TemplatePluginPtr &_other) const
 Comparison operator.
 
bool operator<= (const TemplatePluginPtr &_other) const
 Comparison operator.
 
TemplatePluginPtroperator= (const TemplatePluginPtr &_other)
 Copy assignment operator. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing it.
 
template<typename OtherPluginType >
TemplatePluginPtroperator= (const TemplatePluginPtr< OtherPluginType > &_other)
 Casting operator. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. This essentially allows casting between PluginPtrs that are holding different types of plugin wrappers.
 
TemplatePluginPtroperator= (std::nullptr_t _null)
 nullptr assignment operator. Same as calling Clear()
 
TemplatePluginPtroperator= (TemplatePluginPtr &&_other)
 Move assignment operator. This PluginPtr will take ownership of the plugin instance held by _other. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing it.
 
bool operator== (const TemplatePluginPtr &_other) const
 Comparison operator.
 
bool operator> (const TemplatePluginPtr &_other) const
 Comparison operator.
 
bool operator>= (const TemplatePluginPtr &_other) const
 Comparison operator.
 

Detailed Description

template<typename PluginType>
class gz::plugin::TemplatePluginPtr< PluginType >

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the Loader class or by copy-construction or assignment from another PluginPtr instance.

This class behaves similarly to a std::shared_ptr where multiple PluginPtr objects can share a single plugin instance, and the plugin instance will not be deleted until all PluginPtr objects that refer to it are either destroyed, cleared, or begin referring to a different plugin instance.

A PluginPtr object can be "cast" to a SpecializedPluginPtr object by simply using the copy/move constructor or assignment operator of a SpecializedPluginPtr object. Note that this "cast" does have a small amount of overhead associated with it, but it may result in huge savings after initialization is finished if you frequently access the interfaces that the SpecializedPluginPtr is specialized for.

Constructor & Destructor Documentation

◆ ~TemplatePluginPtr()

template<typename PluginType >
~TemplatePluginPtr ( )
default

Destructor. Deletes this PluginPtr's reference to the plugin instance. Once all PluginPtrs that refer to a plugin instance are deleted, the plugin will also be deleted.

◆ TemplatePluginPtr() [1/4]

Default constructor. Creates a PluginPtr object that does not point to any plugin instance. IsEmpty() will return true until a plugin instance is provided.

◆ TemplatePluginPtr() [2/4]

Copy constructor. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership.

Parameters
[in]_otherPointer to plugin being copied.

◆ TemplatePluginPtr() [3/4]

Move constructor. This PluginPtr will take ownership of the plugin instance held by _other. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing which is being moved.

Parameters
[in]_otherPlugin being moved.

◆ TemplatePluginPtr() [4/4]

Casting constructor. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. This essentially allows casting between PluginPtrs that are holding different types of plugin wrappers (for example, you can cast a generic PluginPtr to any SpecializedPluginPtr type, or you can cast between different types of specializations).

Parameters
[in]_otherPointer to plugin being casted, which is of a different type.

Member Function Documentation

◆ Clear()

template<typename PluginType >
void Clear ( )

Clears the Plugin instance from this PluginPtr. IsEmpty() will return true after this is used, and none of the interfaces will be available any longer.

◆ Hash()

template<typename PluginType >
std::size_t Hash ( ) const

Produces a hash for the plugin instance that this PluginPtr is holding. This function allows PluginPtr instances to be used as values in a std::unordered_set<PluginPtr> or keys in a std::unordered_map<PluginPtr, T>. Using this function directly should not normally be necessary.

Returns
A hash of the underlying pointer object.

◆ IsEmpty()

template<typename PluginType >
bool IsEmpty ( ) const

Check whether this is pointing at a valid plugin.

Returns
False if this PluginPtr is pointing at a valid plugin instance. If it is instead pointing at a nullptr, this returns true.

◆ operator bool()

template<typename PluginType >
operator bool ( ) const

Implicitly convert this PluginPtr to a boolean.

Returns
The opposite value of IsEmpty().

◆ operator!=()

template<typename PluginType >
bool operator!= ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if the pointer instance held by this PluginPtr is different from the pointer instance held by _other.

◆ operator*()

template<typename PluginType >
PluginType & operator* ( ) const

Get a reference to the wrapper for the plugin instance that is being managed by this PluginPtr.

Returns
A reference to the underlying Plugin object.

◆ operator->()

template<typename PluginType >
PluginType * operator-> ( ) const

Access the wrapper for the plugin instance and call one of its member functions.

Returns
The ability to call a member function on the underlying Plugin object.

◆ operator<()

template<typename PluginType >
bool operator< ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if the pointer value of the plugin instance held by this PluginPtr is less than the pointer value of the instance held by _other.

◆ operator<=()

template<typename PluginType >
bool operator<= ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if the value of the pointer instance held by this PluginPtr is less than or equal to the value of the pointer instance held by _other.

◆ operator=() [1/4]

Copy assignment operator. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing it.

Parameters
[in]_otherPointer to plugin being copied.

◆ operator=() [2/4]

Casting operator. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. This essentially allows casting between PluginPtrs that are holding different types of plugin wrappers.

Parameters
[in]_otherPointer to plugin being casted, which is of a different type.
Returns
A reference to this object.

◆ operator=() [3/4]

nullptr assignment operator. Same as calling Clear()

Parameters
[in]_nullnullptr object.
Returns
A reference to this object.

◆ operator=() [4/4]

Move assignment operator. This PluginPtr will take ownership of the plugin instance held by _other. If this PluginPtr was holding an instance to another plugin, that instance will be deleted if no other PluginPtr is referencing it.

Parameters
[in]_otherPlugin being moved.
Returns
A reference to this object.

◆ operator==()

template<typename PluginType >
bool operator== ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if this Plugin is holding the same plugin instance as _other, otherwise returns false.

◆ operator>()

template<typename PluginType >
bool operator> ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if the pointer value of the plugin instance held by this PluginPtr is greater than the pointer value of the instance held by _other.

◆ operator>=()

template<typename PluginType >
bool operator>= ( const TemplatePluginPtr< PluginType > &  _other) const

Comparison operator.

Parameters
[in]_otherPlugin to compare to.
Returns
True if the value of the pointer instance held by this PluginPtr is greater than or equal to the value of the pointer instance held by _other.

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