source: thomson/elec/CrO2/software/iupplusplus.h@ f9263dd

main
Last change on this file since f9263dd was f9263dd, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Final version (?) of iup++, which handles callbacks with arguments. Needs C++11.

git-svn-id: svn://localhost/thomson@14 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/* CrO2 datassette emulator
2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
3 *
4 * Distributed under the terms of the MIT licence.
5 */
6
7#include <iup.h>
8
9template<class Handler, typename... Args> class Callback
10{
11 typedef int(Handler::*T)(Args... args);
12
13 public:
14 static int destroy(Ihandle* that)
15 {
16 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
17 delete call;
18 return IUP_DEFAULT;
19 }
20
21 static void create(Ihandle* handle, const char* name, Handler* self, T what)
22 {
23 Callback* cb = new Callback(self, what);
24 IupSetAttribute(handle, "LCALLBACK", (char*)cb);
25 IupSetCallback(handle, name, (Icallback)Callback::call);
26 IupSetCallback(handle, "LDESTROY_CB", Callback::destroy);
27 }
28
29 static int call(Ihandle* that, Args... args)
30 {
31 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
32 return ((call->self)->*(call->what))(args...);
33 }
34
35 private:
36 Callback(Handler* self, T what)
37 {
38 this->self = self;
39 this->what = what;
40 }
41
42 Callback(); // do not use
43
44 Handler* self;
45 T what;
46};
47
Note: See TracBrowser for help on using the repository browser.