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.
|
| 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.
|
|
| void | viewWillDelete (CView *iView) override |
| | Called by the view itself when it is going to be deleted.
|
The purpose of this class is to implement a view listener that is "self-contained":
- this class MUST live at least as long as it is registered with the view
- this class offers an easy way to unregister early (if the client code desires to do so) while making sure that the instance is still valid.
The typical code usage would be
{
public:
}
CView *verifyView(CView *iView, ...)
{
if(iView ....)
{
}
}
std::shared_ptr<MyViewListener> fListener{};
CView *verifyView(CView *iView, ...)
{
if(iView ....)
{
}
}
void someCustomCode()
{
if(fListener)
fListener->unregister();
}
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.
Definition SelfContainedViewListener.h:100
SelfContainedViewListener()=default
The constructor which unfortunately has to be declared public for the purpose of a creating a shared ...
Implementation note: internally this class keeps a std::shared_ptr to itself 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.
- Note
- Although this class is not marked internal and you can use it in your own code, it is used by the framework and you should rarely need to to use it.
◆ SelfContainedViewListener()
| SelfContainedViewListener |
( |
| ) |
|
|
default |
The constructor which unfortunately has to be declared public for the purpose of a creating a shared instance.
Do not instantiate directly.
◆ create()
template<typename T, typename ... Args>
| std::shared_ptr< T > create |
( |
CView * | iView, |
|
|
Args &&... | iArgs ) |
|
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.
- Template Parameters
-
- Parameters
-
| iView | the view on which this class will be registered as a listener (must not be nullptr) |
| iArgs | optional arguments for the T constructor |
- Returns
- the shared pointer which may be kept around (scenario 2) but is NOT required
◆ registerView()
◆ unregister()
| virtual void unregister |
( |
| ) |
|
|
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.
◆ viewWillDelete()
| void viewWillDelete |
( |
CView * | iView | ) |
|
|
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)
◆ fThis
◆ fView
The documentation for this class was generated from the following file: