YSTest: YBaseMacro.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
YBaseMacro.h
浏览该文件的文档.
1 /*
2 © 2010-2014 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
33 /* \defgroup cmacro Macros For Code Compressing
34 \brief 缩写代码用的宏。
35
36 以下名构词缩写的含义：
37 Ctor constructor
38 Cvt converter
39 De default
40 Decl declare
41 Def define
42 Del deleted
43 Dtor destructor
44 Expr expression
45 Fn function
46 Fwd forward
47 H head
48 I interface
49 Impl implement
50 Mem member
51 Op operator
52 P partially
53 PDecl pre-declare
54 Pred predicate
55 Ret returning
56 S statically
57 Tmpl template
58
59 以下宏参数缩写的含义：
60 _a argument
61 _alist arguments list
62 _attr attributes
63 _b base
64 _e expression
65 _i interface
66 _m member
67 _n name
68 _op operator
69 _p parameter
70 _plist parameters list
71 _q qualifier(s)
72 _sig signature
73 _t type
74 \since 早于 build 132
75 */
77
78 //函数宏。
79
80 //通用头定义。
81 #define PDefH(_t, _n, ...) \
82 _t \
83 _n(__VA_ARGS__)
84 #define PDefHOp(_t, _op, ...) \
85 PDefH(_t, operator _op, __VA_ARGS__)
86
87 #define PDefCvt(_t) \
88 operator _t()
89
90
91 //简单通用函数实现。
92 //prefix "Impl" = Implementation;
93 #define ImplExpr(...) \
94 { \
95 (__VA_ARGS__), void(); \
96 }
97 #define ImplRet(...) \
98 { \
99 return __VA_ARGS__; \
100 }
101 #define ImplThrow(...) \
103 { \
104 throw __VA_ARGS__; \
105 }
106 // NOTE: GCC complains about 'void(yunseq(__VA_ARGS__))'.
107 #define ImplUnseq(...) \
108 { \
109 yunused(yunseq(__VA_ARGS__)); \
110 }
111
112 //基类同名函数映射和成员同名函数映射实现。
113 //prefix "Impl" = Implement;
114 #define ImplBodyBase(_b, _n, ...) \
115 ImplRet(_b::_n(__VA_ARGS__))
116 #define ImplBodyMem(_m, _n, ...) \
117 ImplRet((_m)._n(__VA_ARGS__))
118
119
120 //简单通用成员函数定义。
121 //prefix "Def" = Define;
131 #define DefDeCtor(_t) \
132 _t() = default;
133 #define DefDelCtor(_t) \
134 _t() = delete;
135
136 #define DefDeCopyCtor(_t) \
137 _t(const _t&) = default;
138 #define DefDelCopyCtor(_t) \
139 _t(const _t&) = delete;
140
141 #define DefDeMoveCtor(_t) \
142 _t(_t&&) = default;
143 #define DefDelMoveCtor(_t) \
144 _t(_t&&) = delete;
145
146 #define DefDeDtor(_t) \
147 ~_t() = default;
148 #define DefDelDtor(_t) \
149 ~_t() = delete;
150
151 #define ImplEmptyDtor(_t) \
152 inline _t::DefDeDtor(_t)
153
154 #define DefDeCopyAssignment(_t) \
155 _t& operator=(const _t&) = default;
156 #define DefDelCopyAssignment(_t) \
157 _t& operator=(const _t&) = delete;
158
159 #define DefDeMoveAssignment(_t) \
160 _t& operator=(_t&&) = default;
161 #define DefDelMoveAssignment(_t) \
162 _t& operator=(_t&&) = delete;
163
164 #define DefCvt(_q, _t, ...) \
165 operator _t() _q \
166 ImplRet(__VA_ARGS__)
167 #define DefCvtBase(_q, _t, _b) \
168 DefCvt(_q, _t, _b::operator _t())
169 #define DefCvtMem(_q, _t, _m) \
170 DefCvt(_q, _t, (_m).operator _t())
171
172 #define DefPred(_q, _n, ...) \
173 bool YPP_Concat(Is, _n)() _q \
174 ImplRet(__VA_ARGS__)
175 #define DefPredBase(_q, _n, _b) \
176 DefPred(_q, _n, _b::YPP_Concat(Is, _n)())
177 #define DefPredMem(_q, _n, _m) \
178 DefPred(_q, _n, (_m).YPP_Concat(Is, _n)())
179
180 #define DefGetter(_q, _t, _n, ...) \
181 _t YPP_Concat(Get, _n)() _q \
182 ImplRet(__VA_ARGS__)
183 #define DefGetterBase(_q, _t, _n, _b) \
184 DefGetter(_q, _t, _n, _b::YPP_Concat(Get, _n)())
185 #define DefGetterMem(_q, _t, _n, _m) \
186 DefGetter(_q, _t, _n, (_m).YPP_Concat(Get, _n)())
187
188 #define DefSetter(_t, _n, _m) \
189 void YPP_Concat(Set, _n)(_t _tempArgName) \
190 ImplExpr((_m) = _tempArgName)
191 #define DefSetterDe(_t, _n, _m, _defv) \
192 void YPP_Concat(Set, _n)(_t _tempArgName = _defv) \
193 ImplExpr((_m) = _tempArgName)
194 #define DefSetterBase(_t, _n, _b) \
195 void YPP_Concat(Set, _n)(_t _tempArgName) \
196 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
197 #define DefSetterBaseDe(_t, _n, _b, _defv) \
198 void YPP_Concat(Set, _n)(_t _tempArgName = _defv) \
199 ImplExpr(_b::YPP_Concat(Set, _n)(_tempArgName))
200 #define DefSetterMem(_t, _n, _m) \
201 void YPP_Concat(Set, _n)(_t _tempArgName) \
202 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
203 #define DefSetterMemDe(_t, _n, _m, _defv) \
204 void YPP_Concat(Set, _n)(_t _tempArgName = _defv) \
205 ImplExpr((_m).YPP_Concat(Set, _n)(_tempArgName))
206 #define DefSetterEx(_t, _n, _m, ...) \
207 void YPP_Concat(Set, _n)(_t _tempArgName) \
208 ImplExpr((_m) = (__VA_ARGS__))
209 #define DefSetterDeEx(_t, _n, _m, _defv, ...) \
210 void YPP_Concat(Set, _n)(_t _tempArgName = _defv) \
211 ImplExpr((_m) = (__VA_ARGS__))
212
213
221 #define DefClone(_q, _t) \
222 PDefH(_t*, clone, ) _q \
223 ImplRet(new _t(*this))
224
225
232 #define DefSwap(_q, _t) \
233 PDefH(void, swap, _t& _x, _t& _y) _q \
234 ImplExpr(_x.swap(_y))
235
236
237 //成员函数和模板映射。
238
239
244 #define DefFwdFn(_q, _t, _n, ...) \
245 inline _t \
246 _n() _q \
247 { \
248 return (__VA_ARGS__); \
249 }
250
255 #define DefFwdTmpl(_q, _t, _n, ...) \
256 template<typename... _tParams> \
257 inline _t \
258 _n(_tParams&&... args) _q \
259 { \
260 return (__VA_ARGS__); \
261 }
262
263
269
270 #define _yInterface struct
271
272 #define implements public
273
279 #define _yInterfaceHead(_n) { \
280 protected: \
281 DefDeCtor(_n) \
282 \
283 public: \
284 virtual DefDeDtor(_n)
285
286 #define FwdDeclI(_n) _yInterface _n;
287
293 #define DeclI(_attr, _n) \
294 _yInterface _attr _n \
295 _yInterfaceHead(_n)
296
297 /*
298 \def DeclDerivedI
299 \brief 定义派生接口类型。
300 \note 由于接口定义为 struct 类型，因此通常只需指定是否为 virtual 继承。
301 \since build 362
302 */
303 #define DeclDerivedI(_attr, _n, ...) \
304 _yInterface _attr _n : __VA_ARGS__ \
305 _yInterfaceHead(_n)
306
307 // ImplI = Implements Interface;
308 #define ImplI(...) virtual
309
310 //抽象实现：保留接口供派生类实现（可以提供接口函数的默认实现）。
311 // ImplA = Implements Abstractly;
312 #define ImplA(...)
313
314 #define DeclIEntry(_sig) virtual _sig = 0;
315
316 #define EndDecl };
317
318
323 #define DeclSEntry(...)
324
328 #define ImplS(...)
329
330
331
337 #define DefExtendClass(_attr, _n, ...) \
338 class _attr _n : __VA_ARGS__ \
339 { \
340 public: \
341 _n(); \
342 };
343
344
351 #define DefBitmaskAnd(_tBitmask, _tInt) \
352 yconstfn _tBitmask operator&(_tBitmask _x, _tBitmask _y) \
353 ImplRet(static_cast<_tBitmask>( \
354 static_cast<_tInt>(_x) & static_cast<_tInt>(_y)))
355
356 #define DefBitmaskOr(_tBitmask, _tInt) \
357 yconstfn _tBitmask operator|(_tBitmask _x, _tBitmask _y) \
358 ImplRet(static_cast<_tBitmask>( \
359 static_cast<_tInt>(_x) | static_cast<_tInt>(_y)))
360
361 #define DefBitmaskXor(_tBitmask, _tInt) \
362 yconstfn _tBitmask operator^(_tBitmask _x, _tBitmask _y) \
363 ImplRet(static_cast<_tBitmask>( \
364 static_cast<_tInt>(_x) ^ static_cast<_tInt>(_y)))
365
366 #define DefBitmaskNot(_tBitmask, _tInt) \
367 yconstfn _tBitmask operator~(_tBitmask _x) \
368 ImplRet(static_cast<_tBitmask>(~static_cast<_tInt>(_x)))
369
370 #define DefBitmaskAndAssignment(_tBitmask, _tInt) \
371 inline _tBitmask& operator&=(_tBitmask& _x, _tBitmask _y) \
372 ImplRet(_x = _x & _y)
373
374 #define DefBitmaskOrAssignment(_tBitmask, _tInt) \
375 inline _tBitmask& operator|=(_tBitmask& _x, _tBitmask _y) \
376 ImplRet(_x = _x | _y)
377
378 #define DefBitmaskXorAssignment(_tBitmask, _tInt) \
379 inline _tBitmask& operator^=(_tBitmask& _x, _tBitmask _y) \
380 ImplRet(_x = _x ^ _y)
381
382 #define DefBitmaskOperations(_tBitmask, _tInt) \
383 DefBitmaskAnd(_tBitmask, _tInt) \
384 DefBitmaskOr(_tBitmask, _tInt) \
385 DefBitmaskXor(_tBitmask, _tInt) \
386 DefBitmaskNot(_tBitmask, _tInt) \
387 DefBitmaskAndAssignment(_tBitmask, _tInt) \
388 DefBitmaskOrAssignment(_tBitmask, _tInt) \
389 DefBitmaskXorAssignment(_tBitmask, _tInt)
390
392 #define DefBitmaskEnum(_tEnum) \
393 DefBitmaskOperations(_tEnum, typename std::underlying_type<_tEnum>::type)
394
395
396
397 #endif
398
ydef.h
系统环境和公用类型和宏的基础定义。