ROSE  0.11.145.0
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> { ... };

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

SharedPointer<MyBaseClass> update() const {
...
return sharedFromThis();
}

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 381 of file SharedPointer.h.

#include <util/Sawyer/SharedPointer.h>

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

Public Member Functions

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

Member Function Documentation

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 390 of file SharedPointer.h.

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 395 of file SharedPointer.h.


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