1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #ifndef _STATRICK_H_ |
---|
6 | #define _STATRICK_H_ |
---|
7 | |
---|
8 | /** |
---|
9 | @file |
---|
10 | CALLING METHODS WITH "STATIC TRICK" (="STATRICK") |
---|
11 | |
---|
12 | each trick-callable method has the static counterpart defined by the STATRICKDEF macro |
---|
13 | |
---|
14 | \code |
---|
15 | static void Class::method_statrick(Class* instance,otherparams) |
---|
16 | { instance->method(otherparams); } |
---|
17 | |
---|
18 | ------ class.h ----------- |
---|
19 | class Class |
---|
20 | { |
---|
21 | #define STATRICKCLASS Class |
---|
22 | STATRICKDEF(method_x) |
---|
23 | STATRICKDEF1(method_y,argtype1) |
---|
24 | STATRICKDEF2(method_z,argtype1,argtype2) |
---|
25 | STATRICKIMPL(method_a) |
---|
26 | { |
---|
27 | ...implementation... |
---|
28 | } |
---|
29 | STATRICKIMPL1(method_b,argtype1) |
---|
30 | { |
---|
31 | ...implementation... |
---|
32 | } |
---|
33 | STATRICKIMPL2(method_c,argtype1,argtype2) |
---|
34 | { |
---|
35 | ...implementation... |
---|
36 | } |
---|
37 | #undef STATRICKCLASS |
---|
38 | } |
---|
39 | ------ class.cpp --------- |
---|
40 | Class::method_x() |
---|
41 | { |
---|
42 | ...implementation |
---|
43 | } |
---|
44 | Class::method_y(type1 arg1) |
---|
45 | { |
---|
46 | ...implementation |
---|
47 | } |
---|
48 | Class::method_z(type1 arg1,type2 arg2) |
---|
49 | { |
---|
50 | ...implementation |
---|
51 | } |
---|
52 | -------------------------- |
---|
53 | \endcode |
---|
54 | |
---|
55 | usage: |
---|
56 | |
---|
57 | \code |
---|
58 | void* methodptr=STATRICKPTR(Class::method); |
---|
59 | STATRICKCALL(method,anyobject); |
---|
60 | \endcode |
---|
61 | |
---|
62 | */ |
---|
63 | |
---|
64 | #define STATRICKNAME(name) (name ## _statrick) |
---|
65 | #define STATRICKCALL(method,anyobject) (*method(anyobject)) |
---|
66 | #define STATRICKCALL1(method,anyobject,a) (*method(anyobject,a)) |
---|
67 | #define STATRICKCALL2(method,anyobject,a,b) (*method(anyobject,a,b)) |
---|
68 | |
---|
69 | #define STATRICKSTUB(cls,method) \ |
---|
70 | static void method ## _statrick (cls * instance) \ |
---|
71 | { instance -> method (); } |
---|
72 | |
---|
73 | #define STATRICKSTUB1(cls,method,type1) \ |
---|
74 | static void method ## _statrick (cls * instance, type1 arg1) \ |
---|
75 | { instance -> method (arg1); } |
---|
76 | |
---|
77 | #define STATRICKSTUB2(cls,method,type1,type2) \ |
---|
78 | static void method ## _statrick (cls * instance, type1 arg1, type2 arg2) \ |
---|
79 | { instance -> method (arg1,arg2); } |
---|
80 | |
---|
81 | #define STATRICKRSTUB(cls,ret,method) \ |
---|
82 | static ret method ## _statrick (cls * instance) \ |
---|
83 | { return instance -> method (); } |
---|
84 | |
---|
85 | #define STATRICKRSTUB1(cls,ret,method,type1) \ |
---|
86 | static ret method ## _statrick (cls * instance, type1 arg1) \ |
---|
87 | { return instance -> method (arg1); } |
---|
88 | |
---|
89 | #define STATRICKRSTUB2(cls,ret,method,type1,type2) \ |
---|
90 | static ret method ## _statrick (cls * instance, type1 arg1, type2 arg2) \ |
---|
91 | { return instance -> method (arg1,arg2); } |
---|
92 | |
---|
93 | #define STATRICKDEF(method) \ |
---|
94 | STATRICKSTUB(STATRICKCLASS,method) \ |
---|
95 | void method () |
---|
96 | |
---|
97 | #define STATRICKRDEF(ret,method) \ |
---|
98 | STATRICKRSTUB(STATRICKCLASS,ret,method) \ |
---|
99 | ret method () |
---|
100 | |
---|
101 | #define STATRICKDEF1(method,type1) \ |
---|
102 | STATRICKSTUB1(STATRICKCLASS,method,type1) \ |
---|
103 | void method (type1 arg1) |
---|
104 | |
---|
105 | #define STATRICKRDEF1(ret,method,type1) \ |
---|
106 | STATRICKRSTUB1(STATRICKCLASS,ret,method,type1) \ |
---|
107 | ret method (type1 arg1) |
---|
108 | |
---|
109 | #define STATRICKDEF2(method,type1,type2) \ |
---|
110 | STATRICKSTUB2(STATRICKCLASS,method,type1,type2) \ |
---|
111 | void method (type1 arg1,type2 arg2) |
---|
112 | |
---|
113 | #define STATRICKRDEF2(ret,method,type1,type2) \ |
---|
114 | STATRICKRSTUB2(STATRICKCLASS,ret,method,type1,type2) \ |
---|
115 | ret method (type1 arg1,type2 arg2) |
---|
116 | |
---|
117 | #endif |
---|