~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/scripting/sqplus/SqPlusConst.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// SqPlusConst.h
 
2
// SqPlus constant type and constant member function support created by Simon Michelmore.
 
3
// Modular integration 11/14/05 jcs.
 
4
 
 
5
#ifdef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
 
6
#undef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
 
7
 
 
8
// Kamaitati's NULL_INSTANCE support. 5/28/06 jcs
 
9
 
 
10
#ifdef SQPLUS_SUPPORT_NULL_INSTANCES
 
11
 
 
12
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
 
13
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
 
14
namespace SqPlus { \
 
15
inline void Push(HSQUIRRELVM v,const TYPE * value) { \
 
16
  if (!value) sq_pushnull(v); \
 
17
  else if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) \
 
18
    throw SquirrelError(sqT("Push(): could not create INSTANCE (check registration name)")); } \
 
19
inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(GetTypeName(value),value)) throw SquirrelError(sqT("Push(): could not create INSTANCE copy (check registration name)")); } \
 
20
inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return  GetInstance<TYPE,false>(v,idx) != NULL; } \
 
21
inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
 
22
} // nameSpace SqPlus
 
23
 
 
24
#else
 
25
 
 
26
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
 
27
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
 
28
namespace SqPlus { \
 
29
inline void Push(HSQUIRRELVM v,const TYPE * value) { if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) throw SquirrelError(sqT("Push(): could not create INSTANCE (check registration name)")); } \
 
30
inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(GetTypeName(value),value)) throw SquirrelError(sqT("Push(): could not create INSTANCE copy (check registration name)")); } \
 
31
inline bool     Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
 
32
inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
 
33
} // nameSpace SqPlus
 
34
 
 
35
#endif
 
36
 
 
37
#define DECLARE_INSTANCE_TYPE(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,TYPE)
 
38
#define DECLARE_INSTANCE_TYPE_NAME(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME)
 
39
#endif
 
40
 
 
41
#ifdef SQPLUS_CALL_CONST_MFUNC_RET0
 
42
#undef SQPLUS_CALL_CONST_MFUNC_RET0
 
43
template <typename Callee>
 
44
static int Call(Callee & callee,RT (Callee::*func)() const,HSQUIRRELVM v,int /*index*/) {
 
45
  RT ret = (callee.*func)();
 
46
  Push(v,ret);
 
47
  return 1;
 
48
}
 
49
 
 
50
template <typename Callee,typename P1>
 
51
static int Call(Callee & callee,RT (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
 
52
  sq_argassert(1,index + 0);
 
53
  RT ret = (callee.*func)(
 
54
    Get(TypeWrapper<P1>(),v,index + 0)
 
55
    );
 
56
  Push(v,ret);
 
57
  return 1;
 
58
}
 
59
 
 
60
template<typename Callee,typename P1,typename P2>
 
61
static int Call(Callee & callee,RT (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
 
62
  sq_argassert(1,index + 0);
 
63
  sq_argassert(2,index + 1);
 
64
  RT ret = (callee.*func)(
 
65
    Get(TypeWrapper<P1>(),v,index + 0),
 
66
    Get(TypeWrapper<P2>(),v,index + 1)
 
67
    );
 
68
  Push(v,ret);
 
69
  return 1;
 
70
}
 
71
 
 
72
template<typename Callee,typename P1,typename P2,typename P3>
 
73
static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
 
74
  sq_argassert(1,index + 0);
 
75
  sq_argassert(2,index + 1);
 
76
  sq_argassert(3,index + 2);
 
77
  RT ret = (callee.*func)(
 
78
    Get(TypeWrapper<P1>(),v,index + 0),
 
79
    Get(TypeWrapper<P2>(),v,index + 1),
 
80
    Get(TypeWrapper<P3>(),v,index + 2)
 
81
    );
 
82
  Push(v,ret);
 
83
  return 1;
 
84
}
 
85
 
 
86
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
 
87
static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
 
88
  sq_argassert(1,index + 0);
 
89
  sq_argassert(2,index + 1);
 
90
  sq_argassert(3,index + 2);
 
91
  sq_argassert(4,index + 3);
 
92
  RT ret = (callee.*func)(
 
93
    Get(TypeWrapper<P1>(),v,index + 0),
 
94
    Get(TypeWrapper<P2>(),v,index + 1),
 
95
    Get(TypeWrapper<P3>(),v,index + 2),
 
96
    Get(TypeWrapper<P4>(),v,index + 3)
 
97
    );
 
98
  Push(v,ret);
 
99
  return 1;
 
100
}
 
101
 
 
102
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
 
103
static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
 
104
  sq_argassert(1,index + 0);
 
105
  sq_argassert(2,index + 1);
 
106
  sq_argassert(3,index + 2);
 
107
  sq_argassert(4,index + 3);
 
108
  sq_argassert(5,index + 4);
 
109
  RT ret = (callee.*func)(
 
110
    Get(TypeWrapper<P1>(),v,index + 0),
 
111
    Get(TypeWrapper<P2>(),v,index + 1),
 
112
    Get(TypeWrapper<P3>(),v,index + 2),
 
113
    Get(TypeWrapper<P4>(),v,index + 3),
 
114
    Get(TypeWrapper<P5>(),v,index + 4)
 
115
    );
 
116
  Push(v,ret);
 
117
  return 1;
 
118
}
 
119
 
 
120
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
 
121
static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
 
122
  sq_argassert(1,index + 0);
 
123
  sq_argassert(2,index + 1);
 
124
  sq_argassert(3,index + 2);
 
125
  sq_argassert(4,index + 3);
 
126
  sq_argassert(5,index + 4);
 
127
  sq_argassert(6,index + 5);
 
128
  RT ret = (callee.*func)(
 
129
    Get(TypeWrapper<P1>(),v,index + 0),
 
130
    Get(TypeWrapper<P2>(),v,index + 1),
 
131
    Get(TypeWrapper<P3>(),v,index + 2),
 
132
    Get(TypeWrapper<P4>(),v,index + 3),
 
133
    Get(TypeWrapper<P5>(),v,index + 4),
 
134
    Get(TypeWrapper<P6>(),v,index + 5)
 
135
    );
 
136
  Push(v,ret);
 
137
  return 1;
 
138
}
 
139
 
 
140
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
 
141
static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
 
142
  sq_argassert(1,index + 0);
 
143
  sq_argassert(2,index + 1);
 
144
  sq_argassert(3,index + 2);
 
145
  sq_argassert(4,index + 3);
 
146
  sq_argassert(5,index + 4);
 
147
  sq_argassert(6,index + 5);
 
148
  sq_argassert(7,index + 6);
 
149
  RT ret = (callee.*func)(
 
150
    Get(TypeWrapper<P1>(),v,index + 0),
 
151
    Get(TypeWrapper<P2>(),v,index + 1),
 
152
    Get(TypeWrapper<P3>(),v,index + 2),
 
153
    Get(TypeWrapper<P4>(),v,index + 3),
 
154
    Get(TypeWrapper<P5>(),v,index + 4),
 
155
    Get(TypeWrapper<P6>(),v,index + 5),
 
156
    Get(TypeWrapper<P7>(),v,index + 6)
 
157
    );
 
158
  Push(v,ret);
 
159
  return 1;
 
160
}
 
161
#endif
 
162
 
 
163
#ifdef SQPLUS_CALL_CONST_MFUNC_NORET
 
164
#undef SQPLUS_CALL_CONST_MFUNC_NORET
 
165
template<typename Callee>
 
166
static int Call(Callee & callee,void (Callee::*func)() const,HSQUIRRELVM,int /*index*/) {
 
167
  (callee.*func)();
 
168
  return 0;
 
169
}
 
170
 
 
171
template<typename Callee,typename P1>
 
172
static int Call(Callee & callee,void (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
 
173
  sq_argassert(1,index + 0);
 
174
  (callee.*func)(
 
175
    Get(TypeWrapper<P1>(),v,index + 0)
 
176
    );
 
177
  return 0;
 
178
}
 
179
 
 
180
template<typename Callee,typename P1,typename P2>
 
181
static int Call(Callee & callee,void (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
 
182
  sq_argassert(1,index + 0);
 
183
  sq_argassert(2,index + 1);
 
184
  (callee.*func)(
 
185
    Get(TypeWrapper<P1>(),v,index + 0),
 
186
    Get(TypeWrapper<P2>(),v,index + 1)
 
187
    );
 
188
  return 0;
 
189
}
 
190
 
 
191
template<typename Callee,typename P1,typename P2,typename P3>
 
192
static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
 
193
  sq_argassert(1,index + 0);
 
194
  sq_argassert(2,index + 1);
 
195
  sq_argassert(3,index + 2);
 
196
  (callee.*func)(
 
197
    Get(TypeWrapper<P1>(),v,index + 0),
 
198
    Get(TypeWrapper<P2>(),v,index + 1),
 
199
    Get(TypeWrapper<P3>(),v,index + 2)
 
200
    );
 
201
  return 0;
 
202
}
 
203
 
 
204
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
 
205
static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
 
206
  sq_argassert(1,index + 0);
 
207
  sq_argassert(2,index + 1);
 
208
  sq_argassert(3,index + 2);
 
209
  sq_argassert(4,index + 3);
 
210
  (callee.*func)(
 
211
    Get(TypeWrapper<P1>(),v,index + 0),
 
212
    Get(TypeWrapper<P2>(),v,index + 1),
 
213
    Get(TypeWrapper<P3>(),v,index + 2),
 
214
    Get(TypeWrapper<P4>(),v,index + 3)
 
215
    );
 
216
  return 0;
 
217
}
 
218
 
 
219
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
 
220
static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
 
221
  sq_argassert(1,index + 0);
 
222
  sq_argassert(2,index + 1);
 
223
  sq_argassert(3,index + 2);
 
224
  sq_argassert(4,index + 3);
 
225
  sq_argassert(5,index + 4);
 
226
  (callee.*func)(
 
227
    Get(TypeWrapper<P1>(),v,index + 0),
 
228
    Get(TypeWrapper<P2>(),v,index + 1),
 
229
    Get(TypeWrapper<P3>(),v,index + 2),
 
230
    Get(TypeWrapper<P4>(),v,index + 3),
 
231
    Get(TypeWrapper<P5>(),v,index + 4)
 
232
    );
 
233
  return 0;
 
234
}
 
235
 
 
236
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
 
237
static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
 
238
  sq_argassert(1,index + 0);
 
239
  sq_argassert(2,index + 1);
 
240
  sq_argassert(3,index + 2);
 
241
  sq_argassert(4,index + 3);
 
242
  sq_argassert(5,index + 4);
 
243
  sq_argassert(6,index + 5);
 
244
  (callee.*func)(
 
245
    Get(TypeWrapper<P1>(),v,index + 0),
 
246
    Get(TypeWrapper<P2>(),v,index + 1),
 
247
    Get(TypeWrapper<P3>(),v,index + 2),
 
248
    Get(TypeWrapper<P4>(),v,index + 3),
 
249
    Get(TypeWrapper<P5>(),v,index + 4),
 
250
    Get(TypeWrapper<P6>(),v,index + 5)
 
251
    );
 
252
  return 0;
 
253
}
 
254
 
 
255
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
 
256
static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
 
257
  sq_argassert(1,index + 0);
 
258
  sq_argassert(2,index + 1);
 
259
  sq_argassert(3,index + 2);
 
260
  sq_argassert(4,index + 3);
 
261
  sq_argassert(5,index + 4);
 
262
  sq_argassert(6,index + 5);
 
263
  sq_argassert(7,index + 6);
 
264
  (callee.*func)(
 
265
    Get(TypeWrapper<P1>(),v,index + 0),
 
266
    Get(TypeWrapper<P2>(),v,index + 1),
 
267
    Get(TypeWrapper<P3>(),v,index + 2),
 
268
    Get(TypeWrapper<P4>(),v,index + 3),
 
269
    Get(TypeWrapper<P5>(),v,index + 4),
 
270
    Get(TypeWrapper<P6>(),v,index + 5),
 
271
    Get(TypeWrapper<P7>(),v,index + 6)
 
272
    );
 
273
  return 0;
 
274
}
 
275
#endif
 
276
 
 
277
#ifdef SQPLUS_CALL_CONST_MFUNC_RET1
 
278
#undef SQ_REG_CONST_STATIC_VAR
 
279
template<typename Callee,typename RT>
 
280
int Call(Callee & callee, RT (Callee::*func)() const,HSQUIRRELVM v,int index) {
 
281
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
282
}
 
283
 
 
284
template<typename Callee,typename RT,typename P1>
 
285
int Call(Callee & callee,RT (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
 
286
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
287
}
 
288
 
 
289
template<typename Callee,typename RT,typename P1,typename P2>
 
290
int Call(Callee & callee,RT (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
 
291
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
292
}
 
293
 
 
294
template<typename Callee,typename RT,typename P1,typename P2,typename P3>
 
295
int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
 
296
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
297
}
 
298
 
 
299
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4>
 
300
int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
 
301
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
302
}
 
303
 
 
304
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5>
 
305
int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
 
306
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
307
}
 
308
 
 
309
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
 
310
int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
 
311
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
312
}
 
313
 
 
314
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
 
315
int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
 
316
  return ReturnSpecialization<RT>::Call(callee,func,v,index);
 
317
}
 
318
#undef SQPLUS_CALL_CONST_MFUNC_RET1
 
319
#endif
 
320
 
 
321
#ifdef SQ_REG_CONST_STATIC_VAR
 
322
template<typename VarType>
 
323
SQClassDef & staticVar(const VarType * pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_ONLY) {
 
324
  struct CV {
 
325
    const VarType * var;
 
326
  } cv; // Cast Variable helper.
 
327
  cv.var = pvar;
 
328
  RegisterInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,VarAccessType(access|VAR_ACCESS_STATIC));
 
329
  return *this;
 
330
} // staticVar
 
331
#endif
 
332
 
 
333
// SqPlusConst.h