mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 17:50:04 +01:00
[Escher] Add a magic number to app as poor man's RTTI
Change-Id: If7e907f1187b6b6bda33f89aee4a5dfbd922ed6d
This commit is contained in:
committed by
Romain Goyet
parent
c1c59ae72f
commit
4b88baebec
@@ -15,10 +15,12 @@
|
||||
|
||||
class App : public Responder {
|
||||
public:
|
||||
constexpr static uint8_t Magic = 0xA8;
|
||||
App();
|
||||
void setWindow(Window * window);
|
||||
void focus(Responder * responder);
|
||||
void processEvent(Ion::Events::Event event);
|
||||
uint8_t m_magic; // Poor man's RTTI
|
||||
protected:
|
||||
virtual ViewController * rootViewController() = 0;
|
||||
private:
|
||||
|
||||
@@ -5,6 +5,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
App::App() :
|
||||
m_magic(Magic),
|
||||
Responder(nullptr),
|
||||
m_focusedResponder(nullptr)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <escher/responder.h>
|
||||
#include <escher/app.h>
|
||||
#include <assert.h>
|
||||
|
||||
Responder::Responder(Responder * parentResponder) :
|
||||
m_parentResponder(parentResponder)
|
||||
@@ -29,5 +31,7 @@ App * Responder::app() {
|
||||
/* If we used RTTI we could use a dynamic_cast, which would be a lot more
|
||||
* safe, as such:
|
||||
* return dynamic_cast<App *>(rootResponder); */
|
||||
return (App *)rootResponder;
|
||||
App * result = (App *)rootResponder;
|
||||
assert(result->m_magic == App::Magic); // Poor man's RTTI
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user