comparison dw.hpp @ 2866:6ea67d0809eb

Convert DW::App class into a singleton so subsequent DW::App::Init() calls will return a handle to our instance once it is already initialized.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 17 Dec 2022 11:51:22 +0000
parents fd32dce7fecd
children ada74f4d3f39
comparison
equal deleted inserted replaced
2865:fd32dce7fecd 2866:6ea67d0809eb
59 virtual int OnConfigure(int width, int height) = 0; 59 virtual int OnConfigure(int width, int height) = 0;
60 }; 60 };
61 61
62 class App 62 class App
63 { 63 {
64 protected:
65 App() { }
66 static App *_app;
64 public: 67 public:
65 App() { dw_init(TRUE, 0, NULL); } 68 // Singletons should not be cloneable.
66 App(const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); } 69 App(App &other) = delete;
67 App(const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, 0, NULL); } 70 // Singletons should not be assignable.
68 App(int argc, char *argv[]) { dw_init(TRUE, argc, argv); } 71 void operator=(const App &) = delete;
69 App(int argc, char *argv[], const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, argc, argv); } 72 // Initialization functions for creating App
70 App(int argc, char *argv[], const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, argc, argv); } 73 static App *Init() { if(!_app) { _app = new App; dw_init(TRUE, 0, NULL); } return _app; }
74 static App *Init(const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); } return _app; }
75 static App *Init(const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, 0, NULL); } return _app; }
76 static App *Init(int argc, char *argv[]) { if(!_app) { _app = new App(); dw_init(TRUE, argc, argv); } return _app; }
77 static App *Init(int argc, char *argv[], const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, NULL); dw_init(TRUE, argc, argv); } return _app; }
78 static App *Init(int argc, char *argv[], const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, argc, argv); } return _app; }
71 79
72 void Main() { dw_main(); } 80 void Main() { dw_main(); }
73 void MainIteration() { dw_main_iteration(); } 81 void MainIteration() { dw_main_iteration(); }
74 void MainQuit() { dw_main_quit(); } 82 void MainQuit() { dw_main_quit(); }
75 void Exit(int exitcode) { dw_exit(exitcode); } 83 void Exit(int exitcode) { dw_exit(exitcode); }
76 }; 84 };
85
86 // Static singleton reference declared outside of the class
87 App* App::_app = nullptr;
77 88
78 #if 0 89 #if 0
79 // Class that allows drawing, either to screen or picture (pixmap) 90 // Class that allows drawing, either to screen or picture (pixmap)
80 class Drawable 91 class Drawable
81 { 92 {