YSTest: YBaseMacro.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

YBaseMacro.h
浏览该文件的文档.
1 /*
2 © 2010-2016 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
157 #define DefDeCtor(_t) \
158 _t() = default;
159 #define DefDelCtor(_t) \
160 _t() = delete;
161
162 #define DefDeCopyCtor(_t) \
163 _t(const _t&) = default;
164 #define DefDelCopyCtor(_t) \
165 _t(const _t&) = delete;
166
167 #define DefDeMoveCtor(_t) \
168 _t(_t&&) = default;
169 #define DefDelMoveCtor(_t) \
170 _t(_t&&) = delete;
171
173 #define DefDeCopyMoveCtor(_t) \
174 DefDeCopyCtor(_t) \
175 DefDeMoveCtor(_t)
176
177 #define DefDeDtor(_t) \
178 ~_t() = default;
179 #define DefDelDtor(_t) \
180 ~_t() = delete;
181
183 #define ImplDeDtor(_t) \
184 _t::DefDeDtor(_t)
185
186 #define DefDeCopyAssignment(_t) \
187 _t& operator=(const _t&) = default;
188 #define DefDelCopyAssignment(_t) \
189 _t& operator=(const _t&) = delete;
190
191 #define DefDeMoveAssignment(_t) \
192 _t& operator=(_t&&) = default;
193 #define DefDelMoveAssignment(_t) \
194 _t& operator=(_t&&) = delete;
195
197 #define DefDeCopyMoveAssignment(_t) \
198 DefDeCopyAssignment(_t) \
199 DefDeMoveAssignment(_t)
200
202 #define DefDeCopyMoveCtorAssignment(_t) \
203 DefDeCopyMoveCtor(_t) \
204 DefDeCopyMoveAssignment(_t)
205
206 #define DefCvt(_q, _t, ...) \
207 operator _t() _q \
208 ImplRet(__VA_ARGS__)
209 #define DefCvtBase(_q, _t, _b) \
210 DefCvt(_q, _t, _b::operator _t())
211 #define DefCvtMem(_q, _t, _m) \
212 DefCvt(_q, _t, (_m).operator _t())
213
219 #define DefNeg \
220 PDefHOp(bool, !, ) const ynothrow \
221 ImplRet(!bool(*this))
222
228 #define DefBoolNeg(_spec, ...) \
229 DefNeg \
230 _spec DefCvt(const ynothrow, bool, __VA_ARGS__)
231
232 #define DefPred(_q, _n, ...) \
233 bool \
234 YPP_Concat(Is, _n)() _q \
235 ImplRet(__VA_ARGS__)
236 #define DefPredBase(_q, _n, _b) \
237 DefPred(_q, _n, _b::YPP_Concat(Is, _n)())
238 #define DefPredMem(_q, _n, _m) \
239 DefPred(_q, _n, (_m).YPP_Concat(Is, _n)())
240
241 #define DefGetter(_q, _t, _n, ...) \
242 _t \
243 YPP_Concat(Get, _n)() _q \
244 ImplRet(__VA_ARGS__)
245 #define DefGetterBase(_q, _t, _n, _b) \
246 DefGetter(_q, _t, _n, _b::YPP_Concat(Get, _n)())
247 #define DefGetterMem(_q, _t, _n, _m) \
248 DefGetter(_q, _t, _n, (_m).YPP_Concat(Get, _n)())
249
251
252 #define DefSetter(_q, _t, _n, _m) \
253 void \
254 YPP_Concat(Set, _n)(_t _tempArgName) _q \
255 ImplExpr((_m) = _tempArgName)
256 #define DefSetterDe(_q, _t, _n, _m, _defv) \
257 void \
258 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
259 ImplExpr((_m) = _tempArgName)
260 #define DefSetterBase(_q, _t, _n, _b) \
261 void \
262 YPP_Concat(Set, _n)(_t _tempArgName) _q \
263 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
264 #define DefSetterBaseDe(_q, _t, _n, _b, _defv) \
265 void \
266 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
267 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
268 #define DefSetterMem(_q, _t, _n, _m) \
269 void \
270 YPP_Concat(Set, _n)(_t _tempArgName) _q \
271 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
272 #define DefSetterMemDe(_q, _t, _n, _m, _defv) \
273 void \
274 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
275 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
276 #define DefSetterEx(_q, _t, _n, _m, ...) \
277 void \
278 YPP_Concat(Set, _n)(_t _tempArgName) _q \
279 ImplExpr((_m) = (__VA_ARGS__))
280 #define DefSetterDeEx(_q, _t, _n, _m, _defv, ...) \
281 void \
282 YPP_Concat(Set, _n)(_t _tempArgName = _defv) _q \
283 ImplExpr((_m) = (__VA_ARGS__))
284
285
286
287
294 #define DefClone(_q, _t) \
295 PDefH(_t*, clone, ) _q \
296 ImplRet(new _t(*this))
297
298
304 #define DefSwap(_q, _t) \
305 PDefH(void, swap, _t& _x, _t& _y) _q \
306 ImplExpr(_x.swap(_y))
307
308
309 //成员函数和模板映射。
310
311
316 #define DefFwdFn(_q, _t, _n, ...) \
317 inline _t \
318 _n() _q \
319 { \
320 return (__VA_ARGS__); \
321 }
322
327 #define DefFwdTmpl(_q, _t, _n, ...) \
328 template<typename... _tParams> \
329 inline _t \
330 _n(_tParams&&... args) _q \
331 { \
332 return (__VA_ARGS__); \
333 }
334
339 #define DefFwdTmplAuto(_n, ...) \
340 DefFwdTmpl(ynoexcept_spec(decltype(__VA_ARGS__)(__VA_ARGS__)) \
341 -> decltype(__VA_ARGS__), auto, _n, __VA_ARGS__)
342
343
349 #define YInterface(_attr, _n) struct _attr _n
351
352 #define implements public
353
358 #define YInterfaceHead(_n) { \
359 protected: \
360 DefDeCtor(_n) \
361 DefDeCopyCtor(_n) \
362 \
363 public:
364
365 #define FwdDeclI(_n) YInterface(, _n);
366
371 #define DeclI(_attr, _n) \
372 YInterface(_attr, _n) \
373 YInterfaceHead(_n) \
374 virtual \
375 ~_n();
376
377 /*
378 \brief 定义派生接口类型。
379 \note 由于接口定义为 struct 类型，因此通常只需指定是否为 virtual 继承。
380 \since build 362
381 */
382 #define DeclDerivedI(_attr, _n, ...) \
383 YInterface(_attr, _n) : __VA_ARGS__ \
384 YInterfaceHead(_n) \
385 ~_n() ImplI(__VA_ARGS__);
386
388 #define ImplI(...) override
389
394 #define ImplA(...)
395
396 #define DeclIEntry(_sig) virtual _sig = 0;
397
398 #define EndDecl };
399
400
405 #define DeclSEntry(...)
406
410 #define ImplS(...)
411
412
413
419 #define DefExtendClass(_attr, _n, ...) \
420 class _attr _n : __VA_ARGS__ \
421 { \
422 public: \
423 _n(); \
424 };
425
426
434 #define DefBitmaskAnd(_tBitmask, _tInt) \
435 yconstfn PDefHOp(_tBitmask, &, _tBitmask _x, _tBitmask _y) ynothrow \
436 ImplRet(static_cast<_tBitmask>( \
437 static_cast<_tInt>(_x) & static_cast<_tInt>(_y)))
438
439 #define DefBitmaskOr(_tBitmask, _tInt) \
440 yconstfn PDefHOp(_tBitmask, |, _tBitmask _x, _tBitmask _y) ynothrow \
441 ImplRet(static_cast<_tBitmask>( \
442 static_cast<_tInt>(_x) | static_cast<_tInt>(_y)))
443
444 #define DefBitmaskXor(_tBitmask, _tInt) \
445 yconstfn PDefHOp(_tBitmask, ^, _tBitmask _x, _tBitmask _y) ynothrow \
446 ImplRet(static_cast<_tBitmask>( \
447 static_cast<_tInt>(_x) ^ static_cast<_tInt>(_y)))
448
449 #define DefBitmaskNot(_tBitmask, _tInt) \
450 yconstfn PDefHOp(_tBitmask, ~, _tBitmask _x) ynothrow \
451 ImplRet(static_cast<_tBitmask>(~static_cast<_tInt>(_x)))
452
453 #define DefBitmaskAndAssignment(_tBitmask, _tInt) \
454 yconstfn_relaxed PDefHOp(_tBitmask&, &=, _tBitmask& _x, _tBitmask _y) \
455 ynothrow \
456 ImplRet(_x = _x & _y)
457
458 #define DefBitmaskOrAssignment(_tBitmask, _tInt) \
459 yconstfn_relaxed PDefHOp(_tBitmask&, |=, _tBitmask& _x, _tBitmask _y) \
460 ynothrow \
461 ImplRet(_x = _x | _y)
462
463 #define DefBitmaskXorAssignment(_tBitmask, _tInt) \
464 yconstfn_relaxed PDefHOp(_tBitmask&, ^=, _tBitmask& _x, _tBitmask _y) \
465 ynothrow \
466 ImplRet(_x = _x ^ _y)
467
468 #define DefBitmaskOperations(_tBitmask, _tInt) \
469 DefBitmaskAnd(_tBitmask, _tInt) \
470 DefBitmaskOr(_tBitmask, _tInt) \
471 DefBitmaskXor(_tBitmask, _tInt) \
472 DefBitmaskNot(_tBitmask, _tInt) \
473 DefBitmaskAndAssignment(_tBitmask, _tInt) \
474 DefBitmaskOrAssignment(_tBitmask, _tInt) \
475 DefBitmaskXorAssignment(_tBitmask, _tInt)
476
481 #define DefBitmaskEnum(_tEnum) \
482 DefBitmaskOperations(_tEnum, std::underlying_type<_tEnum>::type)
483
484
485
486 #endif
487
ydef.h
系统环境和公用类型和宏的基础定义。