Jamba C++ API
5.1.1
|
The purpose of this class is to implement a view listener that is "self-contained": More...
#include <SelfContainedViewListener.h>
Inherits ViewListenerAdapter, and enable_shared_from_this< SelfContainedViewListener >.
Inherited by GlobalKeyboardHook.
Public Member Functions | |
virtual std::shared_ptr< SelfContainedViewListener > | registerView (CView *iView) |
Registers this class as a view listener. More... | |
SelfContainedViewListener ()=default | |
The constructor which unfortunately has to be declared public for the purpose of a creating a shared instance. More... | |
virtual void | unregister () |
You can call this method at anytime to unregister this class as the listener to the view that was previously registered in SelfContainedViewListener::create() . More... | |
Static Public Member Functions | |
template<typename T , typename ... Args> | |
static std::shared_ptr< T > | create (CView *iView, Args &&...iArgs) |
This is the main method that should be used to create an instance of this class. More... | |
Protected Member Functions | |
void | viewWillDelete (CView *iView) override |
Called by the view itself when it is going to be deleted. More... | |
Protected Attributes | |
std::shared_ptr< SelfContainedViewListener > | fThis {} |
CView * | fView {} |
The purpose of this class is to implement a view listener that is "self-contained":
The typical code usage would be
Implementation note: internally this class keeps a std::shared_ptr
to ifself for as long as this
is registered with the view itself, ensuring that this class is not going to be deleted until the view goes away (or it is unregistered). If an outside piece of code also has a reference to this class which is scenario 2, then the class itself won't be deleted until this other reference goes away.
|
default |
The constructor which unfortunately has to be declared public
for the purpose of a creating a shared instance.
Do not instantiate directly.
|
inlinestatic |
This is the main method that should be used to create an instance of this class.
It will automatically register this
class as a view listener to iView
.
T | the actual type (must be a subtype of SelfContainedViewListener ) |
Args | optional arguments templates for the T constructor |
iView | the view on which this class will be registered as a listener (must not be nullptr ) |
iArgs | optional arguments for the T constructor |
|
inlinevirtual |
Registers this class as a view listener.
Note that this call requires to be called from a shared pointer. It is called by SelfContainedViewListener::create()
.
Reimplemented in GlobalKeyboardHook.
|
inlinevirtual |
You can call this method at anytime to unregister this
class as the listener to the view that was previously registered in SelfContainedViewListener::create()
.
It is not necessary to call it explicitly as it will be automatically unregistered when the view gets deleted.
Reimplemented in GlobalKeyboardHook.
|
inlineoverrideprotected |
Called by the view itself when it is going to be deleted.
It automatically unregisters itself and deletes the shared_ptr
so that the class can be properly deleted (when all other instances of the shared_ptr
are gone)
|
protected |
|
protected |