Ignition Common

API Reference

3.6.1
TemplatePluginPtr< PluginType > Class Template Referencefinal

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the PluginLoader 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...
 
 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 it. 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 ()=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 if this PluginPtr is holding a plugin instance. 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= (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...
 
TemplatePluginPtroperator= (std::nullptr_t)
 nullptr assignment operator. Same as calling Clear() More...
 
bool operator== (const TemplatePluginPtr &_other) const
 Comparison operator. Returns true if this Plugin is holding the same plugin instance as _other, otherwise returns false. 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::common::TemplatePluginPtr< PluginType >

This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the PluginLoader 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 it.

Parameters
[in]_otherPointer to plugin 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]_otherAnother PluginPtr object. It may have a different kind of specialization.

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 if this PluginPtr is holding a plugin instance.

Returns
False if this PluginPtr contains a plugin instance. If it instead contains 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.
Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is != _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.
Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is < _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.
Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is <= _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]_otherAnother PluginPtr object. It may have a different kind of specialization.
Returns
A reference to this object.

◆ operator=() [3/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]_otherAnother PluginPtr object.
Returns
A reference to this object.

◆ operator=() [4/4]

nullptr assignment operator. Same as calling Clear()

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

◆ operator==()

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

Comparison operator. Returns true if this Plugin is holding the same plugin instance as _other, otherwise returns false.

Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is == _other.

◆ 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.
Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is > _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.
Parameters
[in]_otherAnother PluginPtr object.
Returns
True if the value of this pointer is >= _other.

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