YARP
Yet Another Robot Platform
yarp::os::SharedLibraryClass< T > Class Template Reference

Container for an object created using a factory provided by a shared library. More...

#include <yarp/os/SharedLibraryClass.h>

Detailed Description

template<class T>
class yarp::os::SharedLibraryClass< T >

Container for an object created using a factory provided by a shared library.

Used to ensure the object is destroyed by a method also provided by the shared library. Mixing creation and destruction methods could be very bad.

Definition at line 18 of file SharedLibraryClass.h.

Public Member Functions

 SharedLibraryClass ()
 Constructor for empty instance. More...
 
 SharedLibraryClass (SharedLibraryClassFactory< T > &factory)
 Constructor for valid instance of a class from a shared library. More...
 
bool open (SharedLibraryClassFactory< T > &factory)
 Construct an instance using the specified factory. More...
 
virtual bool close ()
 Destroy an instance if one has been created. More...
 
virtual ~SharedLibraryClass ()
 Destructor. More...
 
T & getContent ()
 Gives access to the created instance. More...
 
const T & getContent () const
 Gives access to the created instance (const version). More...
 
bool isValid () const
 Check whether a valid instance has been created. More...
 
T & operator* ()
 Shorthand for SharedLibraryClass::getContent. More...
 
const T & operator* () const
 Shorthand for SharedLibraryClass::getContent (const version) More...
 
T * operator-> ()
 A pointer version of SharedLibraryClass::getContent. More...
 
const T * operator-> () const
 A pointer version of SharedLibraryClass::getContent (const version) More...
 

Private Attributes

T * content
 
SharedLibraryClassFactory< T > * pfactory
 

Constructor & Destructor Documentation

◆ SharedLibraryClass() [1/2]

template<class T>
yarp::os::SharedLibraryClass< T >::SharedLibraryClass ( )
inline

Constructor for empty instance.

Definition at line 38 of file SharedLibraryClass.h.

◆ SharedLibraryClass() [2/2]

template<class T>
yarp::os::SharedLibraryClass< T >::SharedLibraryClass ( SharedLibraryClassFactory< T > &  factory)
inline

Constructor for valid instance of a class from a shared library.

Parameters
factorythe factory to use to construct (and eventually destroy) the instance.

Definition at line 49 of file SharedLibraryClass.h.

◆ ~SharedLibraryClass()

template<class T>
virtual yarp::os::SharedLibraryClass< T >::~SharedLibraryClass ( )
inlinevirtual

Destructor.

Definition at line 96 of file SharedLibraryClass.h.

Member Function Documentation

◆ close()

template<class T>
virtual bool yarp::os::SharedLibraryClass< T >::close ( void  )
inlinevirtual

Destroy an instance if one has been created.

Returns
true on success

Definition at line 77 of file SharedLibraryClass.h.

◆ getContent() [1/2]

template<class T>
T& yarp::os::SharedLibraryClass< T >::getContent ( )
inline

Gives access to the created instance.

No check made to ensure an instance is in fact present. Call SharedLibraryClass::isValid first if unsure.

Returns
the created instance

Definition at line 108 of file SharedLibraryClass.h.

◆ getContent() [2/2]

template<class T>
const T& yarp::os::SharedLibraryClass< T >::getContent ( ) const
inline

Gives access to the created instance (const version).

No check made to ensure an instance is in fact present. Call SharedLibraryClass::isValid first if unsure.

Returns
the created instance

Definition at line 120 of file SharedLibraryClass.h.

◆ isValid()

template<class T>
bool yarp::os::SharedLibraryClass< T >::isValid ( ) const
inline

Check whether a valid instance has been created.

Returns
true iff a valid instance has been created

Definition at line 129 of file SharedLibraryClass.h.

◆ open()

template<class T>
bool yarp::os::SharedLibraryClass< T >::open ( SharedLibraryClassFactory< T > &  factory)
inline

Construct an instance using the specified factory.

If an instance has already been made, it is destroyed.

Parameters
factorythe factory to use to construct (and eventually destroy) the instance.
Returns
true on success

Definition at line 63 of file SharedLibraryClass.h.

◆ operator*() [1/2]

template<class T>
T& yarp::os::SharedLibraryClass< T >::operator* ( )
inline

Shorthand for SharedLibraryClass::getContent.

Returns
the created instance

Definition at line 138 of file SharedLibraryClass.h.

◆ operator*() [2/2]

template<class T>
const T& yarp::os::SharedLibraryClass< T >::operator* ( ) const
inline

Shorthand for SharedLibraryClass::getContent (const version)

Returns
the created instance

Definition at line 147 of file SharedLibraryClass.h.

◆ operator->() [1/2]

template<class T>
T* yarp::os::SharedLibraryClass< T >::operator-> ( )
inline

A pointer version of SharedLibraryClass::getContent.

Returns
a pointer to the created instance, or nullptr if there is none

Definition at line 157 of file SharedLibraryClass.h.

◆ operator->() [2/2]

template<class T>
const T* yarp::os::SharedLibraryClass< T >::operator-> ( ) const
inline

A pointer version of SharedLibraryClass::getContent (const version)

Returns
a pointer to the created instance, or nullptr if there is none

Definition at line 167 of file SharedLibraryClass.h.

Member Data Documentation

◆ content

template<class T>
T* yarp::os::SharedLibraryClass< T >::content
private

Definition at line 31 of file SharedLibraryClass.h.

◆ pfactory

template<class T>
SharedLibraryClassFactory<T>* yarp::os::SharedLibraryClass< T >::pfactory
private

Definition at line 32 of file SharedLibraryClass.h.


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