YSTest: YBaseMacro.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YBaseMacro.h
浏览该文件的文档.
1 /*
2 © 2010-2015 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YF_INC_YBaseMacro_h_
29 #define YF_INC_YBaseMacro_h_ 1
30
31 #include <ydef.h>
32
77
78 //函数宏。
79
81 #define PDefH(_t, _n, ...) \
82 _t \
83 _n(__VA_ARGS__)
84
86 #define PDefHOp(_t, _op, ...) \
87 PDefH(_t, operator _op, __VA_ARGS__)
88
90 #define PDefCvt(_t) \
91 operator _t()
92
93
95
96 #define ImplExpr(...) \
97 { \
98 (__VA_ARGS__), void(); \
99 }
100 #define ImplRet(...) \
101 { \
102 return __VA_ARGS__; \
103 }
104 #define ImplThrow(...) \
106 { \
107 throw __VA_ARGS__; \
108 }
109 // NOTE: GCC complains about 'void(yunseq(__VA_ARGS__))'.
110 #define ImplUnseq(...) \
111 { \
112 static_cast<void>(yunseq(__VA_ARGS__)); \
113 }
114
115
116
118
119 #define TryExpr(...) \
121 try \
122 ImplExpr(__VA_ARGS__)
123 #define TryRet(...) \
125 try \
126 ImplRet(__VA_ARGS__)
127
129 #define CatchExpr(_ex, ...) \
130 catch(_ex) \
131 ImplExpr(__VA_ARGS__)
132 #define CatchIgnore(_ex) \
134 catch(_ex) \
135 {}
136 #define CatchRet(_ex, ...) \
138 catch(_ex) \
139 ImplRet(__VA_ARGS__)
140 #define CatchThrow(_ex, ...) \
142 catch(_ex) \
143 ImplThrow(__VA_ARGS__)
144
145
146
148
149
156 #define DefDeCtor(_t) \
157 _t() = default;
158 #define DefDelCtor(_t) \
159 _t() = delete;
160
161 #define DefDeCopyCtor(_t) \
162 _t(const _t&) = default;
163 #define DefDelCopyCtor(_t) \
164 _t(const _t&) = delete;
165
166 #define DefDeMoveCtor(_t) \
167 _t(_t&&) = default;
168 #define DefDelMoveCtor(_t) \
169 _t(_t&&) = delete;
170
172 #define DefDeCopyMoveCtor(_t) \
173 DefDeCopyCtor(_t) \
174 DefDeMoveCtor(_t)
175
176 #define DefDeDtor(_t) \
177 ~_t() = default;
178 #define DefDelDtor(_t) \
179 ~_t() = delete;
180
182 #define ImplDeDtor(_t) \
183 _t::DefDeDtor(_t)
184
185 #define DefDeCopyAssignment(_t) \
186 _t& operator=(const _t&) = default;
187 #define DefDelCopyAssignment(_t) \
188 _t& operator=(const _t&) = delete;
189
190 #define DefDeMoveAssignment(_t) \
191 _t& operator=(_t&&) = default;
192 #define DefDelMoveAssignment(_t) \
193 _t& operator=(_t&&) = delete;
194
196 #define DefDeCopyMoveAssignment(_t) \
197 DefDeCopyAssignment(_t) \
198 DefDeMoveAssignment(_t)
199
201 #define DefDeCopyMoveCtorAssignment(_t) \
202 DefDeCopyMoveCtor(_t) \
203 DefDeCopyMoveAssignment(_t)
204
205 #define DefCvt(_q, _t, ...) \
206 operator _t() _q \
207 ImplRet(__VA_ARGS__)
208 #define DefCvtBase(_q, _t, _b) \
209 DefCvt(_q, _t, _b::operator _t())
210 #define DefCvtMem(_q, _t, _m) \
211 DefCvt(_q, _t, (_m).operator _t())
212
218 #define DefNeg \
219 PDefHOp(bool, !, ) const ynothrow \
220 ImplRet(!bool(*this))
221
227 #define DefBoolNeg(_spec, ...) \
228 DefNeg \
229 _spec DefCvt(const ynothrow, bool, __VA_ARGS__)
230
231 #define DefPred(_q, _n, ...) \
232 bool \
233 YPP_Concat(Is, _n)() _q \
234 ImplRet(__VA_ARGS__)
235 #define DefPredBase(_q, _n, _b) \
236 DefPred(_q, _n, _b::YPP_Concat(Is, _n)())
237 #define DefPredMem(_q, _n, _m) \
238 DefPred(_q, _n, (_m).YPP_Concat(Is, _n)())
239
240 #define DefGetter(_q, _t, _n, ...) \
241 _t \
242 YPP_Concat(Get, _n)() _q \
243 ImplRet(__VA_ARGS__)
244 #define DefGetterBase(_q, _t, _n, _b) \
245 DefGetter(_q, _t, _n, _b::YPP_Concat(Get, _n)())
246 #define DefGetterMem(_q, _t, _n, _m) \
247 DefGetter(_q, _t, _n, (_m).YPP_Concat(Get, _n)())
248
250
251 #define DefSetter(_q, _t, _n, _m) \
252 void \
253 YPP_Concat(Set, _n)(_t _tempArgName) _q \
254 ImplExpr((_m) = _tempArgName)
255 #define DefSetterDe(_q, _t, _n, _m, _defv) \
256 void \
257 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
258 ImplExpr((_m) = _tempArgName)
259 #define DefSetterBase(_q, _t, _n, _b) \
260 void \
261 YPP_Concat(Set, _n)(_t _tempArgName) _q \
262 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
263 #define DefSetterBaseDe(_q, _t, _n, _b, _defv) \
264 void \
265 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
266 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
267 #define DefSetterMem(_q, _t, _n, _m) \
268 void \
269 YPP_Concat(Set, _n)(_t _tempArgName) _q \
270 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
271 #define DefSetterMemDe(_q, _t, _n, _m, _defv) \
272 void \
273 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
274 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
275 #define DefSetterEx(_q, _t, _n, _m, ...) \
276 void \
277 YPP_Concat(Set, _n)(_t _tempArgName) _q \
278 ImplExpr((_m) = (__VA_ARGS__))
279 #define DefSetterDeEx(_q, _t, _n, _m, _defv, ...) \
280 void \
281 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
282 ImplExpr((_m) = (__VA_ARGS__))
283
284
285
286
293 #define DefClone(_q, _t) \
294 PDefH(_t*, clone, ) _q \
295 ImplRet(new _t(*this))
296
297
303 #define DefSwap(_q, _t) \
304 PDefH(void, swap, _t& _x, _t& _y) _q \
305 ImplExpr(_x.swap(_y))
306
307
308 //成员函数和模板映射。
309
310
315 #define DefFwdFn(_q, _t, _n, ...) \
316 inline _t \
317 _n() _q \
318 { \
319 return (__VA_ARGS__); \
320 }
321
326 #define DefFwdTmpl(_q, _t, _n, ...) \
327 template<typename... _tParams> \
328 inline _t \
329 _n(_tParams&&... args) _q \
330 { \
331 return (__VA_ARGS__); \
332 }
333
338 #define DefFwdTmplAuto(_n, ...) \
339 DefFwdTmpl(ynoexcept_spec(decltype(__VA_ARGS__)(__VA_ARGS__)) \
340 -> decltype(__VA_ARGS__), auto, _n, __VA_ARGS__)
341
342
348 #define YInterface(_attr, _n) struct _attr _n
350
351 #define implements public
352
357 #define YInterfaceHead(_n) { \
358 protected: \
359 DefDeCtor(_n) \
360 DefDeCopyCtor(_n) \
361 \
362 public:
363
364 #define FwdDeclI(_n) YInterface(, _n);
365
370 #define DeclI(_attr, _n) \
371 YInterface(_attr, _n) \
372 YInterfaceHead(_n) \
373 virtual ~_n();
374
375 /*
376 \brief 定义派生接口类型。
377 \note 由于接口定义为 struct 类型，因此通常只需指定是否为 virtual 继承。
378 \since build 362
379 */
380 #define DeclDerivedI(_attr, _n, ...) \
381 YInterface(_attr, _n) : __VA_ARGS__ \
382 YInterfaceHead(_n) \
383 ~_n() ImplI(__VA_ARGS__);
384
386 #define ImplI(...) override
387
392 #define ImplA(...)
393
394 #define DeclIEntry(_sig) virtual _sig = 0;
395
396 #define EndDecl };
397
398
403 #define DeclSEntry(...)
404
408 #define ImplS(...)
409
410
411
417 #define DefExtendClass(_attr, _n, ...) \
418 class _attr _n : __VA_ARGS__ \
419 { \
420 public: \
421 _n(); \
422 };
423
424
431 #define DefBitmaskAnd(_tBitmask, _tInt) \
432 yconstfn _tBitmask operator&(_tBitmask _x, _tBitmask _y) \
433 ImplRet(static_cast<_tBitmask>( \
434 static_cast<_tInt>(_x) & static_cast<_tInt>(_y)))
435
436 #define DefBitmaskOr(_tBitmask, _tInt) \
437 yconstfn _tBitmask operator|(_tBitmask _x, _tBitmask _y) \
438 ImplRet(static_cast<_tBitmask>( \
439 static_cast<_tInt>(_x) | static_cast<_tInt>(_y)))
440
441 #define DefBitmaskXor(_tBitmask, _tInt) \
442 yconstfn _tBitmask operator^(_tBitmask _x, _tBitmask _y) \
443 ImplRet(static_cast<_tBitmask>( \
444 static_cast<_tInt>(_x) ^ static_cast<_tInt>(_y)))
445
446 #define DefBitmaskNot(_tBitmask, _tInt) \
447 yconstfn _tBitmask operator~(_tBitmask _x) \
448 ImplRet(static_cast<_tBitmask>(~static_cast<_tInt>(_x)))
449
450 #define DefBitmaskAndAssignment(_tBitmask, _tInt) \
451 inline _tBitmask& operator&=(_tBitmask& _x, _tBitmask _y) \
452 ImplRet(_x = _x & _y)
453
454 #define DefBitmaskOrAssignment(_tBitmask, _tInt) \
455 inline _tBitmask& operator|=(_tBitmask& _x, _tBitmask _y) \
456 ImplRet(_x = _x | _y)
457
458 #define DefBitmaskXorAssignment(_tBitmask, _tInt) \
459 inline _tBitmask& operator^=(_tBitmask& _x, _tBitmask _y) \
460 ImplRet(_x = _x ^ _y)
461
462 #define DefBitmaskOperations(_tBitmask, _tInt) \
463 DefBitmaskAnd(_tBitmask, _tInt) \
464 DefBitmaskOr(_tBitmask, _tInt) \
465 DefBitmaskXor(_tBitmask, _tInt) \
466 DefBitmaskNot(_tBitmask, _tInt) \
467 DefBitmaskAndAssignment(_tBitmask, _tInt) \
468 DefBitmaskOrAssignment(_tBitmask, _tInt) \
469 DefBitmaskXorAssignment(_tBitmask, _tInt)
470
475 #define DefBitmaskEnum(_tEnum) \
476 DefBitmaskOperations(_tEnum, std::underlying_type<_tEnum>::type)
477
478
479
480 #endif
481
ydef.h
系统环境和公用类型和宏的基础定义。