Gazebo Plugin

API Reference

1.4.0
TemplatePluginPtr< PluginType > Class Template Referencefinal

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the ignition::plugin::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. More...
 
 TemplatePluginPtr (const TemplatePluginPtr &_other)
 Copy constructor. This PluginPtr will now point at the same plugin instance as _other, and they will share ownership. More...
 
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). More...
 
 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. More...
 
 ~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. More...
 
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. More...
 
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. More...
 
bool IsEmpty () const
 Check whether this is pointing at a valid plugin. More...
 
 operator bool () const
 Implicitly convert this PluginPtr to a boolean. More...
 
bool operator!= (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 
PluginType & operator* () const
 Get a reference to the wrapper for the plugin instance that is being managed by this PluginPtr. More...
 
PluginType * operator-> () const
 Access the wrapper for the plugin instance and call one of its member functions. More...
 
bool operator< (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 
bool operator<= (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 
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. More...
 
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. More...
 
TemplatePluginPtroperator= (std::nullptr_t _null)
 nullptr assignment operator. Same as calling Clear() More...
 
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. More...
 
bool operator== (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 
bool operator> (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 
bool operator>= (const TemplatePluginPtr &_other) const
 Comparison operator. More...
 

Detailed Description

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

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the ignition::plugin::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()

~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]

TemplatePluginPtr ( const TemplatePluginPtr< PluginType > &  _other)

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]

TemplatePluginPtr ( TemplatePluginPtr< PluginType > &&  _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.

Parameters
[in]_otherPlugin being moved.

◆ TemplatePluginPtr() [4/4]

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).

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

Member Function Documentation

◆ Clear()

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()

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()

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()

operator bool ( ) const

Implicitly convert this PluginPtr to a boolean.

Returns
The opposite value of IsEmpty().

◆ operator!=()

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*()

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->()

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<()

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<=()

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]

TemplatePluginPtr& operator= ( const TemplatePluginPtr< PluginType > &  _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.

Parameters
[in]_otherPointer to plugin being copied.

◆ operator=() [2/4]

TemplatePluginPtr& operator= ( 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.

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

◆ operator=() [3/4]

TemplatePluginPtr& operator= ( std::nullptr_t  _null)

nullptr assignment operator. Same as calling Clear()

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

◆ operator=() [4/4]

TemplatePluginPtr& operator= ( TemplatePluginPtr< PluginType > &&  _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.

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

◆ operator==()

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>()

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>=()

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: