source: cpp/frams/util/statrick.h @ 999

Last change on this file since 999 was 286, checked in by Maciej Komosinski, 10 years ago

Updated headers

  • Property svn:eol-style set to native
File size: 3.0 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
[109]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)                                \
70static void method ## _statrick (cls * instance)        \
71{ instance -> method (); }
72
73#define STATRICKSTUB1(cls,method,type1) \
74static void method ## _statrick (cls * instance, type1 arg1)    \
75{ instance -> method (arg1); }
76
77#define STATRICKSTUB2(cls,method,type1,type2)                                                   \
78static void method ## _statrick (cls * instance, type1 arg1, type2 arg2) \
79{ instance -> method (arg1,arg2); }
80
81#define STATRICKRSTUB(cls,ret,method)                           \
82static ret method ## _statrick (cls * instance) \
83{ return instance -> method (); }
84
85#define STATRICKRSTUB1(cls,ret,method,type1) \
86static ret method ## _statrick (cls * instance, type1 arg1)     \
87{ return instance -> method (arg1); }
88
89#define STATRICKRSTUB2(cls,ret,method,type1,type2)                                                      \
90static ret method ## _statrick (cls * instance, type1 arg1, type2 arg2) \
91{ return instance -> method (arg1,arg2); }
92
93#define STATRICKDEF(method)                     \
94 STATRICKSTUB(STATRICKCLASS,method)              \
95void method ()
96
97#define STATRICKRDEF(ret,method)        \
98 STATRICKRSTUB(STATRICKCLASS,ret,method)                 \
99ret method ()
100
101#define STATRICKDEF1(method,type1)      \
102 STATRICKSTUB1(STATRICKCLASS,method,type1)             \
103void method (type1 arg1)
104
105#define STATRICKRDEF1(ret,method,type1) \
106 STATRICKRSTUB1(STATRICKCLASS,ret,method,type1)             \
107ret method (type1 arg1)
108
109#define STATRICKDEF2(method,type1,type2)        \
110STATRICKSTUB2(STATRICKCLASS,method,type1,type2)                \
111void method (type1 arg1,type2 arg2)
112
113#define STATRICKRDEF2(ret,method,type1,type2)   \
114STATRICKRSTUB2(STATRICKCLASS,ret,method,type1,type2)                \
115ret method (type1 arg1,type2 arg2)
116
117#endif
Note: See TracBrowser for help on using the repository browser.