NAP
appeventhandler.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "app.h"
9 
10 // External Includes
11 #include <rtti/typeinfo.h>
12 
13 namespace nap
14 {
19  class NAPAPI AppEventHandler
20  {
21  RTTI_ENABLE()
22  public:
28 
29  // Default Destructor
30  virtual ~AppEventHandler() = default;
31 
36  AppEventHandler& operator=(const AppEventHandler&) = delete;
37 
41  AppEventHandler(AppEventHandler&&) = delete;
42  AppEventHandler& operator=(AppEventHandler&&) = delete;
43 
48  virtual void start() { }
49 
56  virtual void process() { }
57 
61  virtual void shutdown() { }
62 
66  template<typename T>
67  T& getApp();
68 
69  protected:
70  BaseApp& mApp; // The app associated with this app event handler
71  };
72 
73 
75  // Template definitions
77 
78  template<typename T>
80  {
81  assert(mApp.get_type().is_derived_from(RTTI_OF(T)));
82  return static_cast<T&>(mApp);
83  }
84 }
nap::AppEventHandler::getApp
T & getApp()
Definition: appeventhandler.h:79
nap::AppEventHandler::start
virtual void start()
Definition: appeventhandler.h:48
nap::AppEventHandler::process
virtual void process()
Definition: appeventhandler.h:56
nap::AppEventHandler::mApp
BaseApp & mApp
Definition: appeventhandler.h:70
nap::AppEventHandler
Definition: appeventhandler.h:19
nap
Definition: templateapp.h:17
nap::AppEventHandler::shutdown
virtual void shutdown()
Definition: appeventhandler.h:61
nap::BaseApp
Definition: app.h:22