ROSE 0.11.145.147
List of all members
Sawyer::SharedFromThis< T > Class Template Reference

Description

template<class T>
class Sawyer::SharedFromThis< T >

Creates SharedPointer from this.

This class provides a sharedFromThis method that returns a SharedPointer pointing to an object of type T. The template parameter T is usually the name of the class derived from SharedFromThis. For instance, the following example declares MyBaseClass to be a shared object (able to be pointed to by a SharedPointer), and declares that it is possible to create a SharedPointer from a raw object pointer.

class MyBaseClass: public SharedObject, public SharedFromThis<MyBaseClass> { ... };
Creates SharedPointer from this.
Base class for reference counted objects.

Some method in MyBaseClass might want to return such a pointer:

...
return sharedFromThis();
}
SharedPointer< T > sharedFromThis()
Create a shared pointer from this.
Reference-counting intrusive smart pointer.

Subclasses in a class hierarchy need not all have the same version of sharedFromThis. If the user's base class is the only one to directly derive from SharedFromThis, then any subclass calling sharedFromThis will return a pointer to the user's base class. On the other hand, the various subclasses can directly inherit from SharedFromThis also in order to return pointers to objects of their type:

class MyDerivedA: public MyBaseClass {
// sharedFromThis() returns pointers to MyBaseClass
};
class MyDerivedB: public MyBaseClass, public SharedFromThis<MyDerivedB> {
// sharedFromThis() is overridden to return pointers to MyDerivedB
}

Definition at line 398 of file SharedPointer.h.

#include <Sawyer/SharedPointer.h>

Inheritance diagram for Sawyer::SharedFromThis< T >:
Inheritance graph
[legend]

Public Member Functions

SharedPointer< T > sharedFromThis ()
 Create a shared pointer from this.
 
SharedPointer< const T > sharedFromThis () const
 Create a shared pointer from this.
 

Constructor & Destructor Documentation

◆ ~SharedFromThis()

template<class T >
virtual Sawyer::SharedFromThis< T >::~SharedFromThis ( )
inlinevirtual

Definition at line 400 of file SharedPointer.h.

Member Function Documentation

◆ sharedFromThis() [1/2]

template<class T >
SharedPointer< T > Sawyer::SharedFromThis< T >::sharedFromThis ( )
inline

Create a shared pointer from this.

Returns a shared pointer that points to this object. The type T must be derived from SharedObject.

Definition at line 407 of file SharedPointer.h.

◆ sharedFromThis() [2/2]

template<class T >
SharedPointer< const T > Sawyer::SharedFromThis< T >::sharedFromThis ( ) const
inline

Create a shared pointer from this.

Returns a shared pointer that points to this object. The type T must be derived from SharedObject.

Definition at line 412 of file SharedPointer.h.


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