comparison dw.hpp @ 2872:e62fc9b3b09c

C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions. This allows compilation on Visual C 2005 and hopefully ancient versions of GCC.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 19 Dec 2022 00:07:06 +0000
parents 4b7c4cd7a11d
children 0bbfb19022e7
comparison
equal deleted inserted replaced
2871:4b7c4cd7a11d 2872:e62fc9b3b09c
4 */ 4 */
5 5
6 #ifndef _HPP_DW 6 #ifndef _HPP_DW
7 #define _HPP_DW 7 #define _HPP_DW
8 #include <dw.h> 8 #include <dw.h>
9
10 // Attempt to support compilers without nullptr type literal
11 #if __cplusplus >= 201103L
12 #define DW_NULL nullptr
13 #else
14 #define DW_NULL NULL
15 #endif
9 16
10 namespace DW 17 namespace DW
11 { 18 {
12 19
13 // Base handle class which allows opaque access to 20 // Base handle class which allows opaque access to
48 void PackEnd(Widget *item, int width, int height, int hsize, int vsize, int pad) { 55 void PackEnd(Widget *item, int width, int height, int hsize, int vsize, int pad) {
49 dw_box_pack_end(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); } 56 dw_box_pack_end(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); }
50 void PackAtIndex(Widget *item, int index, int width, int height, int hsize, int vsize, int pad) { 57 void PackAtIndex(Widget *item, int index, int width, int height, int hsize, int vsize, int pad) {
51 dw_box_pack_at_index(hwnd, item ? item->GetHWND() : DW_NOHWND, index, width, height, hsize, vsize, pad); } 58 dw_box_pack_at_index(hwnd, item ? item->GetHWND() : DW_NOHWND, index, width, height, hsize, vsize, pad); }
52 Widget *UnpackAtIndex(int index) { HWND widget = dw_box_unpack_at_index(hwnd, index); 59 Widget *UnpackAtIndex(int index) { HWND widget = dw_box_unpack_at_index(hwnd, index);
53 void *classptr = widget ? dw_window_get_data(widget, "_dw_classptr") : nullptr; 60 void *classptr = widget ? dw_window_get_data(widget, "_dw_classptr") : DW_NULL;
54 return reinterpret_cast<Widget *>(classptr); 61 return reinterpret_cast<Widget *>(classptr);
55 } 62 }
56 }; 63 };
57 64
58 // TODO: Find a way to implement this cross platform... 65 // TODO: Find a way to implement this cross platform...
123 App(App &other) = delete; 130 App(App &other) = delete;
124 // Singletons should not be assignable. 131 // Singletons should not be assignable.
125 void operator=(const App &) = delete; 132 void operator=(const App &) = delete;
126 #endif 133 #endif
127 // Initialization functions for creating App 134 // Initialization functions for creating App
128 static App *Init() { if(!_app) { _app = new App; dw_init(TRUE, 0, NULL); } return _app; } 135 static App *Init() { if(!_app) { _app = new App; dw_init(TRUE, 0, DW_NULL); } return _app; }
129 static App *Init(const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); } return _app; } 136 static App *Init(const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, DW_NULL); dw_init(TRUE, 0, DW_NULL); } return _app; }
130 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; } 137 static App *Init(const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, 0, DW_NULL); } return _app; }
131 static App *Init(int argc, char *argv[]) { if(!_app) { _app = new App(); dw_init(TRUE, argc, argv); } return _app; } 138 static App *Init(int argc, char *argv[]) { if(!_app) { _app = new App(); dw_init(TRUE, argc, argv); } return _app; }
132 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; } 139 static App *Init(int argc, char *argv[], const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, DW_NULL); dw_init(TRUE, argc, argv); } return _app; }
133 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; } 140 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; }
134 141
135 void Main() { dw_main(); } 142 void Main() { dw_main(); }
136 void MainIteration() { dw_main_iteration(); } 143 void MainIteration() { dw_main_iteration(); }
137 void MainQuit() { dw_main_quit(); } 144 void MainQuit() { dw_main_quit(); }
138 void Exit(int exitcode) { dw_exit(exitcode); } 145 void Exit(int exitcode) { dw_exit(exitcode); }
139 }; 146 };
140 147
141 // Static singleton reference declared outside of the class 148 // Static singleton reference declared outside of the class
142 App* App::_app = nullptr; 149 App* App::_app = DW_NULL;
143 150
144 #if 0 151 #if 0
145 // Class that allows drawing, either to screen or picture (pixmap) 152 // Class that allows drawing, either to screen or picture (pixmap)
146 class Drawable 153 class Drawable
147 { 154 {