ZFFramework
 
Loading...
Searching...
No Matches
ZFProtocol.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFProtocol_h_
7#define _ZFI_ZFProtocol_h_
8
9#include "ZFObject.h"
11
12// ============================================================
19 ZFENUM_VALUE(Default = 1000)
20 ZFENUM_VALUE(SystemLow = 2000)
21 ZFENUM_VALUE(SystemNormal = 3000)
22 ZFENUM_VALUE(SystemHigh = 4000)
23 ZFENUM_VALUE(AppLow = 5000)
24 ZFENUM_VALUE(AppNormal = 6000)
25 ZFENUM_VALUE(AppHigh = 7000)
28 ZFENUM_VALUE_REGISTER(SystemLow)
29 ZFENUM_VALUE_REGISTER(SystemNormal)
30 ZFENUM_VALUE_REGISTER(SystemHigh)
32 ZFENUM_VALUE_REGISTER(AppNormal)
36
50 ZFENUM_VALUE(OnInit = 0x01)
51 ZFENUM_VALUE(OnInitFinish = 0x03)
52 ZFENUM_VALUE(Idle = 0)
53 ZFENUM_VALUE(OnDeallocPrepare = 0x30)
54 ZFENUM_VALUE(OnDealloc = 0x10)
57 ZFENUM_VALUE_REGISTER(OnInitFinish)
59 ZFENUM_VALUE_REGISTER(OnDeallocPrepare)
60 ZFENUM_VALUE_REGISTER(OnDealloc)
63
64// ============================================================
70
71public:
85 virtual void protocolOnInit(void) {
86 }
87
88 virtual void protocolOnInitFinish(void) {
89 }
90
91 virtual void protocolOnDeallocPrepare(void) {
92 }
93
94 virtual void protocolOnDealloc(void) {
95 }
96
97public:
102 return _ZFP_ZFProtocol_protocolInstanceState;
103 }
104 ZFProtocolInstanceState _ZFP_ZFProtocol_protocolInstanceState;
105
106public:
110 virtual const zfchar *protocolName(void) const {
111 return zfnull;
112 }
113
116 virtual const zfchar *protocolImplName(void) const {
117 return zfnull;
118 }
119
122 virtual ZFProtocolLevel protocolImplLevel(void) const {
124 }
125
133 virtual const zfchar *protocolImplPlatformHint(void) const {
134 return "";
135 }
136
137public:
139 virtual void objectInfoT(ZF_IN_OUT zfstring &ret) const {
140 zfstringAppend(ret, "<[%s] %s%s>",
141 this->protocolName(),
142 this->protocolImplName(),
143 (!zfstringIsEmpty(this->protocolImplPlatformHint()) ? zfstr(" (%s)", this->protocolImplPlatformHint()).cString() : "")
144 );
145 }
146
149 virtual inline zfstring objectInfo(void) const {
150 zfstring ret;
151 this->objectInfoT(ret);
152 return ret;
153 }
154
155public:
156 virtual zfbool _ZFP_ZFProtocol_checkImplDependency(
157 ZF_OUT const zfchar *&desiredImplPlatformHint
158 , ZF_OUT const zfchar *&mismatchProtocolName
159 , ZF_OUT ZFProtocol *&mismatchImpl
160 ) const {
161 return zftrue;
162 }
163protected:
164 static zfbool _ZFP_ZFProtocolOptional(void) {
165 return zffalse;
166 }
167
168public:
170 ZFProtocol(void) : _ZFP_ZFProtocol_protocolInstanceState(v_ZFProtocolInstanceState::e_OnInit) {}
171 virtual ~ZFProtocol(void) {}
173};
176ZFOUTPUT_TYPE(ZFProtocol, {v.objectInfoT(s);})
177
178// ============================================================
179zfclassFwd _ZFP_ZFProtocolData;
180typedef ZFProtocol *(*_ZFP_ZFProtocolTryAccessCallback)(void);
181typedef ZFProtocol *(*_ZFP_ZFProtocolConstructor)(void);
182typedef zfbool (*_ZFP_ZFProtocolIsAvailableCkCallback)(void);
183typedef void (*_ZFP_ZFProtocolCleanupCallback)(ZF_IN _ZFP_ZFProtocolData *implData);
184zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFProtocolData {
185public:
186 zfstring protocolName;
187 zfbool protocolOptional;
188 _ZFP_ZFProtocolTryAccessCallback implTryAccessCallback;
189 _ZFP_ZFProtocolConstructor implConstructor;
190 _ZFP_ZFProtocolIsAvailableCkCallback isAvailableCk;
191 zfstring implName;
192 ZFProtocolLevel implLevel;
193 _ZFP_ZFProtocolCleanupCallback implCleanupCallback;
194 ZFProtocol *implInstance;
195};
196extern ZFLIB_ZFCore _ZFP_ZFProtocolData &_ZFP_ZFProtocolImplDataRegister(
197 ZF_IN const zfchar *protocolName
198 , ZF_IN _ZFP_ZFProtocolTryAccessCallback implTryAccessCallback
199 , ZF_IN zfbool protocolOptional
200 );
201extern ZFLIB_ZFCore void _ZFP_ZFProtocolImplDataUnregister(const zfchar *protocolName);
202extern ZFLIB_ZFCore void _ZFP_ZFProtocolImplAccess(void);
203extern ZFLIB_ZFCore void _ZFP_ZFProtocolImplFail(
204 ZF_IN const zfchar *protocolName
205 , ZF_IN const zfchar *protocolImplName
206 , ZF_IN const zfchar *mismatchProtocolName
207 , ZF_IN const zfchar *desiredImplPlatformHint
208 , ZF_IN ZFProtocol *mismatchImpl
209 );
210
211// ============================================================
217#define ZFPROTOCOL_INTERFACE_CLASS(ModuleName) \
218 ZFPInterface_##ModuleName
219
220#define _ZFP_ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName) \
221 zfclassNotPOD ZFLIB_ ZFPROTOCOL_INTERFACE_CLASS(ModuleName) : zfextend ZFProtocol { \
222 protected: \
223 \
224 typedef ZFProtocol zfsuper; \
225 \
226 typedef ZFPROTOCOL_INTERFACE_CLASS(ModuleName) zfself; \
227 public: \
228 zfoverride \
229 virtual const zfchar *protocolName(void) const { \
230 return #ModuleName; \
231 } \
232 public: \
233 static _ZFP_ZFProtocolData &_ZFP_ZFProtocolDataRef(void) { \
234 static _ZFP_ZFProtocolData &_d = _ZFP_ZFProtocolImplDataRegister( \
235 zftext(#ModuleName), \
236 zfself::_ZFP_ZFProtocolTryAccessCallbackFunc, \
237 zfself::_ZFP_ZFProtocolOptional()); \
238 return _d; \
239 } \
240 static void _ZFP_ZFProtocolDataRegister(void) { \
241 (void)zfself::_ZFP_ZFProtocolDataRef(); \
242 } \
243 static ZFProtocol *_ZFP_ZFProtocolTryAccessCallbackFunc(void) { \
244 return ZFPROTOCOL_TRY_ACCESS(ModuleName); \
245 } \
246 static void _ZFP_ZFProtocolInstanceCleanupCallback(ZF_IN _ZFP_ZFProtocolData *implData) { \
247 if(implData->implInstance != zfnull) { \
248 zfdelete(implData->implInstance); \
249 implData->implInstance = zfnull; \
250 } \
251 } \
252 static void _ZFP_ZFProtocolImplRegister( \
253 ZF_IN _ZFP_ZFProtocolConstructor implConstructor \
254 , ZF_IN _ZFP_ZFProtocolIsAvailableCkCallback isAvailableCk \
255 , ZF_IN const zfchar *implName \
256 , ZF_IN ZFProtocolLevel implLevel \
257 ) { \
258 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
259 if(_d.implConstructor != zfnull) { \
260 if(_d.implLevel == implLevel) { \
261 ZFCoreCriticalMessageTrim("only one implementation is allowed for protocol \"%s\", while we have: \"%s\", \"%s\"", \
262 #ModuleName, \
263 _d.implName, \
264 implName); \
265 return; \
266 } \
267 else if(_d.implLevel > implLevel) { \
268 /* \
269 ZFCoreLogTrim("ignore implementation \"%s\" while having \"%s\" for protocol \"%s\"", \
270 implName, _d.implName, #ModuleName); \
271 */ \
272 return; \
273 } \
274 else { \
275 /* \
276 ZFCoreLogTrim("reset implementation for protocol \"%s\", old: \"%s\", new: \"%s\"", \
277 #ModuleName, _d.implName, implName); \
278 */ \
279 } \
280 } \
281 _d.implConstructor = implConstructor; \
282 _d.isAvailableCk = isAvailableCk; \
283 _d.implName = implName; \
284 _d.implLevel = implLevel; \
285 _d.implCleanupCallback = zfself::_ZFP_ZFProtocolInstanceCleanupCallback; \
286 } \
287 static void _ZFP_ZFProtocolImplChange( \
288 ZF_IN _ZFP_ZFProtocolConstructor implConstructor \
289 , ZF_IN _ZFP_ZFProtocolIsAvailableCkCallback isAvailableCk \
290 , ZF_IN const zfchar *implName \
291 , ZF_IN ZFProtocolLevel implLevel \
292 ) { \
293 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
294 if(_d.implInstance != zfnull) { \
295 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnDeallocPrepare; \
296 _d.implInstance->protocolOnDeallocPrepare(); \
297 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnDealloc; \
298 _d.implInstance->protocolOnDealloc(); \
299 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInit; \
300 } \
301 zfself::_ZFP_ZFProtocolInstanceCleanupCallback(&_d); \
302 if(implConstructor != zfnull && !zfstringIsEmpty(implName)) { \
303 _d.implConstructor = implConstructor; \
304 _d.isAvailableCk = isAvailableCk; \
305 _d.implName = implName; \
306 _d.implLevel = implLevel; \
307 } \
308 else { \
309 _d.implConstructor = zfnull; \
310 _d.isAvailableCk = zfnull; \
311 _d.implName.removeAll(); \
312 _d.implLevel = v_ZFProtocolLevel::e_Default; \
313 } \
314 } \
315 static inline zfbool _ZFP_ZFProtocolIsAvailable(void) { \
316 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
317 return _d.implConstructor != zfnull && _d.isAvailableCk(); \
318 } \
319 static zfself *_ZFP_ZFProtocolNewInstance(void) { \
320 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
321 _ZFP_ZFProtocolImplAccess(); \
322 zfself *retVal = zfnull; \
323 if(_d.isAvailableCk != zfnull && _d.isAvailableCk()) { \
324 retVal = (zfself *)_d.implConstructor(); \
325 if(retVal != zfnull) { \
326 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInit; \
327 retVal->protocolOnInit(); \
328 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInitFinish; \
329 retVal->protocolOnInitFinish(); \
330 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_Idle; \
331 } \
332 } \
333 return retVal; \
334 } \
335 static zfself *_ZFP_ZFProtocolAccess(void) { \
336 static ZFProtocol *&impl = zfself::_ZFP_ZFProtocolDataRef().implInstance; \
337 if(impl == zfnull) { \
338 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
339 _d.implInstance = zfself::_ZFP_ZFProtocolNewInstance(); \
340 if(_d.implInstance == zfnull) { \
341 ZFCoreCriticalMessageTrim("no implementation for protocol \"%s\"", \
342 #ModuleName); \
343 return zfnull; \
344 } \
345 const zfchar *desiredImplPlatformHint = zfnull; \
346 const zfchar *mismatchProtocolName = zfnull; \
347 ZFProtocol *mismatchImpl = zfnull; \
348 if(!_d.implInstance->_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl)) { \
349 _ZFP_ZFProtocolImplFail( \
350 _d.implInstance->protocolName() \
351 , _d.implInstance->protocolImplName() \
352 , mismatchProtocolName \
353 , desiredImplPlatformHint \
354 , mismatchImpl \
355 ); \
356 zfdelete(_d.implInstance); \
357 _d.implInstance = zfnull; \
358 return zfnull; \
359 } \
360 } \
361 return (zfself *)impl; \
362 } \
363 static zfself *_ZFP_ZFProtocolTryAccess(void) { \
364 static ZFProtocol *&impl = zfself::_ZFP_ZFProtocolDataRef().implInstance; \
365 if(impl == zfnull) { \
366 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
367 _d.implInstance = zfself::_ZFP_ZFProtocolNewInstance(); \
368 const zfchar *desiredImplPlatformHint = zfnull; \
369 const zfchar *mismatchProtocolName = zfnull; \
370 ZFProtocol *mismatchImpl = zfnull; \
371 if(_d.implInstance != zfnull \
372 && !_d.implInstance->_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl) \
373 ) { \
374 zfdelete(_d.implInstance); \
375 _d.implInstance = zfnull; \
376 } \
377 } \
378 return (zfself *)impl; \
379 } \
380 static zfbool _ZFP_ZFProtocolIsAvailableCk(void) { \
381 return zftrue; \
382 }
383#define _ZFP_ZFPROTOCOL_INTERFACE_END(ModuleName) \
384 };
385
406 * @endcode
407 * for the difference between them, see #ZFPROTOCOL_TRY_ACCESS\n
408 * for how to implement it, see #ZFPROTOCOL_IMPLEMENTATION_BEGIN\n
409 * for how to access the implementation, see #ZFPROTOCOL_TRY_ACCESS
410 * @note all protocol is singleton mode
411 */
412#define ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName) \
413 _ZFP_ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName)
414
418#define ZFPROTOCOL_INTERFACE_END(ModuleName) \
419 _ZFP_ZFPROTOCOL_INTERFACE_END(ModuleName)
420
424#define ZFPROTOCOL_INTERFACE_OPTIONAL \
425 protected: \
426 static zfbool _ZFP_ZFProtocolOptional(void) { \
427 return zftrue; \
428 } \
429 public:
430
433
434#define ZFPROTOCOL_INTERFACE_REGISTER(ModuleName) \
435 ZF_STATIC_REGISTER_INIT(ZFProtocolInterfaceRegister_##ModuleName) { \
436 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolDataRegister(); \
437 } \
438 ZF_STATIC_REGISTER_END(ZFProtocolInterfaceRegister_##ModuleName)
439
440// ============================================================
459 * ZFPROTOCOL_TRY_ACCESS would create new instance only for the first time,
460 * and the instance would be destroyed at a certain proper time\n
461 * \n
462 * when using ZFPROTOCOL_TRY_ACCESS, you take full responsibility to check whether
463 * the implmentation is available
464 */
465#define ZFPROTOCOL_TRY_ACCESS(ModuleName) \
466 (ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolTryAccess())
467
471#define ZFPROTOCOL_ACCESS(ModuleName) \
472 (ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolAccess())
473
477#define ZFPROTOCOL_IS_AVAILABLE(ModuleName) \
478 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolIsAvailable()
479
480typedef void (*_ZFP_ZFProtocolImplRegisterHolderClearCallback)(void);
481zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFProtocolImplRegisterHolder {
482public:
483 _ZFP_ZFProtocolImplRegisterHolder(ZF_IN _ZFP_ZFProtocolImplRegisterHolderClearCallback callback)
484 : callback(callback)
485 {
486 }
487 ~_ZFP_ZFProtocolImplRegisterHolder(void) {
488 this->callback();
489 }
490private:
491 _ZFP_ZFProtocolImplRegisterHolderClearCallback callback;
492};
493// ============================================================
494#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN_(ImplementationName, ImplementationClass, ModuleName, implLevel) \
495 zfclassNotPOD ImplementationClass : zfextend ZFPROTOCOL_INTERFACE_CLASS(ModuleName) { \
496 protected: \
497 \
498 typedef ZFPROTOCOL_INTERFACE_CLASS(ModuleName) zfsuper; \
499 \
500 typedef ImplementationClass zfself; \
501 public: \
502 zfoverride \
503 virtual const zfchar *protocolImplName(void) const { \
504 return #ImplementationName; \
505 } \
506 zfoverride \
507 virtual ZFProtocolLevel protocolImplLevel(void) const { \
508 return implLevel; \
509 } \
510 public: \
511 static ZFProtocol *_ZFP_##ImplementationClass##_ctor(void) { \
512 return zfnew(ImplementationClass); \
513 } \
514 static void _ZFP_ZFProtocolUnregister(void) { \
515 if(ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolDataRef().implConstructor == &ImplementationClass::_ZFP_##ImplementationClass##_ctor) { \
516 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange(zfnull, zfnull, zfnull, v_ZFProtocolLevel::e_Default); \
517 } \
518 _ZFP_ZFProtocolImplDataUnregister(#ModuleName); \
519 } \
520 static void _ZFP_ZFProtocolRegister(void) { \
521 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplRegister( \
522 &ImplementationClass::_ZFP_##ImplementationClass##_ctor, \
523 &ImplementationClass::_ZFP_ZFProtocolIsAvailableCk, \
524 zftext(#ImplementationName), \
525 implLevel); \
526 static _ZFP_ZFProtocolImplRegisterHolder _holder(&ImplementationClass::_ZFP_ZFProtocolUnregister); \
527 } \
528 static void _ZFP_ZFProtocolChange(void) { \
529 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange( \
530 &ImplementationClass::_ZFP_##ImplementationClass##_ctor, \
531 &ImplementationClass::_ZFP_ZFProtocolIsAvailableCk, \
532 zftext(#ImplementationName), \
533 implLevel); \
534 }
535#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ImplementationClass, ModuleName, implLevel) \
536 _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN_(ImplementationName, ImplementationClass, ModuleName, implLevel)
537
538#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_END_(ImplementationName, ImplementationClass) \
539 }; \
540 ZFOUTPUT_TYPE(ImplementationClass, {zftToStringT(s, (ZFProtocol const &)v);}) \
541 ZF_STATIC_REGISTER_INIT(ZFPImplReg_##ImplementationClass) { \
542 ImplementationClass::_ZFP_ZFProtocolRegister(); \
543 } \
544 ZF_STATIC_REGISTER_END(ZFPImplReg_##ImplementationClass)
545#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName, ImplementationClass) \
546 _ZFP_ZFPROTOCOL_IMPLEMENTATION_END_(ImplementationName, ImplementationClass)
547
548#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction) \
549 static zfbool _ZFP_ZFProtocolIsAvailableCk(void) { \
550 CheckAction \
551 }
552
571 * so that native code can use native code to reflect and access the internal types
572 *
573 * \n
574 * if you are able to access an implementation,
575 * you may check its platform hint by #ZFProtocol::protocolImplPlatformHint
576 */
577#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_HINT(PlatformHint) \
578 public: \
579 virtual const zfchar *protocolImplPlatformHint(void) const { \
580 return PlatformHint; \
581 }
582
589 * ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_ITEM(ProtocolName, "DependencyPlatformHint")
590 * ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_END()
591 * ZFPROTOCOL_IMPLEMENTATION_END(...)
592 * @endcode
593 * the DependencyPlatformHint is the string declared by #ZFPROTOCOL_IMPLEMENTATION_PLATFORM_HINT
594 */
595#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_BEGIN() \
596 public: \
597 virtual zfbool _ZFP_ZFProtocol_checkImplDependency( \
598 ZF_OUT const zfchar *&desiredImplPlatformHint \
599 , ZF_OUT const zfchar *&mismatchProtocolName \
600 , ZF_OUT ZFProtocol *&mismatchImpl \
601 ) const { \
602 if(!zfsuper::_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl)) { \
603 return zffalse; \
604 }
606#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_ITEM(Protocol, DependencyPlatformHint) \
607 if(ZFProtocolTryAccess(ZFM_TOSTRING(Protocol), DependencyPlatformHint) == zfnull) { \
608 desiredImplPlatformHint = DependencyPlatformHint; \
609 mismatchProtocolName = ZFM_TOSTRING(Protocol); \
610 mismatchImpl = ZFProtocolTryAccess(ZFM_TOSTRING(Protocol)); \
611 return zffalse; \
612 }
614#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_END() \
615 return zftrue; \
616 } \
617 public:
620
624#define ZFPROTOCOL_IMPLEMENTATION_CLASS(Implementation) \
625 ZFPImpl_##Implementation
626
697 * return ZFPROTOCOL_IS_AVAILABLE(OtherProtocol);
698 * })
699 * ...
700 * ZFPROTOCOL_IMPLEMENTATION_END(YourImplementation)
701 * @endcode
702 */
703#define ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ModuleName, implLevel) \
704 _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName), ModuleName, implLevel)
707 */
708#define ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName) \
709 _ZFP_ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName, ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName))
713#define ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction) \
714 _ZFP_ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction)
715
716// ============================================================
718 * @brief change the implementation at runtime
719 *
720 * old implementation's level is ignored and forced to be replaced\n
721 * it's your responsibility to make sure old implementation isn't in use,
722 * otherwise, app may crash
723 */
724#define ZFProtocolImplChange(ImplementationName) \
725 ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName)::_ZFP_ZFProtocolChange()
729#define ZFProtocolImplRemove(ModuleName) \
730 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange(zfnull, zfnull, zfnull, v_ZFProtocolLevel::e_Default)
731
732// ============================================================
741 , ZFMP_IN(const zfchar *, name)
742 , ZFMP_IN_OPT(const zfchar *, desiredImpl, zfnull)
743 )
748 , ZFMP_IN(const zfchar *, name)
749 , ZFMP_IN_OPT(const zfchar *, desiredImpl, zfnull)
750 )
759 , ZFMP_IN(const zfchar *, name)
760 , ZFMP_IN_OPT(const zfchar *, desiredImpl, zfnull)
762
763// ============================================================
768public:
781
782public:
784 zffinal void objectInfoT(ZF_IN_OUT zfstring &ret) const;
785
786 zffinal zfstring objectInfo(void) const {
787 zfstring ret;
788 this->objectInfoT(ret);
789 return ret;
790 }
791
792public:
794 zfbool operator == (ZF_IN const ZFProtocolImplInfo &ref) const {
795 return (zftrue
796 && this->protocolName == ref.protocolName
797 && this->protocolOptional == ref.protocolOptional
798 && this->protocolImpl == ref.protocolImpl
799 );
801 zfbool operator != (ZF_IN const ZFProtocolImplInfo &ref) const {
802 return !this->operator == (ref);
803 }
805};
809
826 , ZFMP_IN_OPT(const ZFOutput &, callback, ZFOutputDefault())
827 )
832 , ZFMP_IN(const ZFProtocolImplInfo &, data)
833 , ZFMP_IN_OPT(const ZFOutput &, callback, ZFOutputDefault())
834 )
835
837#endif // #ifndef _ZFI_ZFProtocol_h_
838
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
zfbool zfstringIsEmpty(const zfchar *s)
util to check whether string is empty (null or empty string)
Definition ZFCoreStringUtil.h:197
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:192
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:200
#define ZFCLASS_DISALLOW_COPY_CONSTRUCTOR(ClassName)
a macro to show that a class doesn't allow copy constructor
Definition ZFCoreTypeDef_ClassType.h:81
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFENUM_SEPARATOR()
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:158
#define ZFENUM_VALUE_REGISTER(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:168
#define ZFENUM_REG(ZFLIB_, EnumName,...)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:186
#define ZFENUM_VALUE(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:151
#define ZFENUM_BEGIN(ZFLIB_, EnumName)
macros to define reflectable enum type
Definition ZFEnumDeclare.h:147
#define ZFENUM_END(ZFLIB_, EnumName)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:172
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_FUNC_DECLARE_2(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:763
#define ZFMETHOD_FUNC_DECLARE_0(ZFLIB_, ReturnType, MethodName)
declare function type of ZFMethod
Definition ZFMethodFuncDeclare.h:493
#define ZFMETHOD_FUNC_DECLARE_1(ZFLIB_, ReturnType, MethodName, ZFMP_0)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:624
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
ZFObject related include.
const ZFOutput & ZFOutputDefault(void)
default output callback, output source must be zfchar *string
ZFCoreArray< ZFProtocolImplInfo > ZFProtocolImplInfoGetAll()
for debug use only, get all protocol's info
ZFCoreArray< ZFProtocolImplInfo > ZFProtocolImplInfoGetAllNotImplemented()
util method to ZFProtocolImplInfoGetAll
ZFProtocol * ZFProtocolTryAccess(const zfchar *name, const zfchar *desiredImpl=(zft_zfnull))
get protocol with name or null if no such protocol
ZFProtocol * ZFProtocolAccess(const zfchar *name, const zfchar *desiredImpl=(zft_zfnull))
similar to ZFProtocolTryAccess, but assert fail if no implementation
ZFCoreArray< ZFProtocolImplInfo > ZFProtocolImplInfoGetAllImplemented()
util method to ZFProtocolImplInfoGetAll
v_ZFProtocolInstanceState::ZFEnumType ZFProtocolInstanceState
see v_ZFProtocolInstanceState
Definition ZFProtocol.h:61
zfbool ZFProtocolIsAvailable(const zfchar *name, const zfchar *desiredImpl=(zft_zfnull))
check whether protocol is available
v_ZFProtocolLevel::ZFEnumType ZFProtocolLevel
see v_ZFProtocolLevel
Definition ZFProtocol.h:34
void ZFProtocolImplInfoPrint(const ZFOutput &callback=(ZFOutputDefault()))
util method to ZFProtocolImplInfoGetAll
#define ZFTYPEID_ACCESS_ONLY_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:205
#define ZFTYPEID_ACCESS_ONLY_DECLARE(ZFLIB_, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:195
light weight array
Definition ZFCoreArray.h:331
general output callback
Definition ZFIOCallback_output.h:37
base class of all protocol of ZFFramework
Definition ZFProtocol.h:68
virtual const zfchar * protocolImplPlatformHint(void) const
get type hint of the implementation or empty string if not defined, e.g. "iOS:NSString" for iOS's str...
Definition ZFProtocol.h:133
virtual void protocolOnDeallocPrepare(void)
see protocolOnInit
Definition ZFProtocol.h:91
virtual void protocolOnInitFinish(void)
see protocolOnInit
Definition ZFProtocol.h:88
virtual void protocolOnDealloc(void)
see protocolOnInit
Definition ZFProtocol.h:94
virtual ZFProtocolLevel protocolImplLevel(void) const
get the level of the protocol implementation
Definition ZFProtocol.h:122
virtual const zfchar * protocolName(void) const
get the name of the protocol module, e.g. "ZFObject"
Definition ZFProtocol.h:110
virtual ZFProtocolInstanceState protocolInstanceState(void)
protocol instance's state
Definition ZFProtocol.h:101
virtual void protocolOnInit(void)
called to init the protocol
Definition ZFProtocol.h:85
virtual void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFProtocol.h:139
virtual zfstring objectInfo(void) const
get a short info about this object
Definition ZFProtocol.h:149
virtual const zfchar * protocolImplName(void) const
get the name of the protocol implementation, e.g. "ZFObject_default"
Definition ZFProtocol.h:116
see ZFProtocolImplInfoGetAll
Definition ZFProtocol.h:761
void objectInfoT(zfstring &ret) const
see objectInfo
zfstring objectInfo(void) const
return object info
Definition ZFProtocol.h:780
zfbool protocolOptional
whether protocol is optional
Definition ZFProtocol.h:770
zfstring protocolName
protocol's name
Definition ZFProtocol.h:766
ZFProtocol * protocolImpl
protocol's implementation, or null if currently not implemented
Definition ZFProtocol.h:774
instance state of ZFProtocol
Definition ZFProtocol.h:49
@ e_Default
Definition ZFProtocol.h:19
void zfstringAppend(zfstring &s, const zfchar *fmt)
see zfstr
Definition zfstr.h:71
zfstring zfstr(const zfchar *fmt=zft_zfnull)
string format util
Definition zfstr.h:59