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);
203
204// ============================================================
210#define ZFPROTOCOL_INTERFACE_CLASS(ModuleName) \
211 ZFPInterface_##ModuleName
212
213#define _ZFP_ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName) \
214 zfclassNotPOD ZFLIB_ ZFPROTOCOL_INTERFACE_CLASS(ModuleName) : zfextend ZFProtocol { \
215 protected: \
216 \
217 typedef ZFProtocol zfsuper; \
218 \
219 typedef ZFPROTOCOL_INTERFACE_CLASS(ModuleName) zfself; \
220 public: \
221 zfoverride \
222 virtual const zfchar *protocolName(void) const { \
223 return #ModuleName; \
224 } \
225 public: \
226 static _ZFP_ZFProtocolData &_ZFP_ZFProtocolDataRef(void) { \
227 static _ZFP_ZFProtocolData &_d = _ZFP_ZFProtocolImplDataRegister( \
228 zftext(#ModuleName), \
229 zfself::_ZFP_ZFProtocolTryAccessCallbackFunc, \
230 zfself::_ZFP_ZFProtocolOptional()); \
231 return _d; \
232 } \
233 static void _ZFP_ZFProtocolDataRegister(void) { \
234 (void)zfself::_ZFP_ZFProtocolDataRef(); \
235 } \
236 static ZFProtocol *_ZFP_ZFProtocolTryAccessCallbackFunc(void) { \
237 return ZFPROTOCOL_TRY_ACCESS(ModuleName); \
238 } \
239 static void _ZFP_ZFProtocolInstanceCleanupCallback(ZF_IN _ZFP_ZFProtocolData *implData) { \
240 if(implData->implInstance != zfnull) { \
241 zfdelete(implData->implInstance); \
242 implData->implInstance = zfnull; \
243 } \
244 } \
245 static void _ZFP_ZFProtocolImplRegister( \
246 ZF_IN _ZFP_ZFProtocolConstructor implConstructor \
247 , ZF_IN _ZFP_ZFProtocolIsAvailableCkCallback isAvailableCk \
248 , ZF_IN const zfchar *implName \
249 , ZF_IN ZFProtocolLevel implLevel \
250 ) { \
251 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
252 if(_d.implConstructor != zfnull) { \
253 if(_d.implLevel == implLevel) { \
254 ZFCoreCriticalMessageTrim("only one implementation is allowed for protocol \"%s\", while we have: \"%s\", \"%s\"", \
255 #ModuleName, \
256 _d.implName, \
257 implName); \
258 return; \
259 } \
260 else if(_d.implLevel > implLevel) { \
261 /* \
262 ZFCoreLogTrim("ignore implementation \"%s\" while having \"%s\" for protocol \"%s\"", \
263 implName, _d.implName, #ModuleName); \
264 */ \
265 return; \
266 } \
267 else { \
268 /* \
269 ZFCoreLogTrim("reset implementation for protocol \"%s\", old: \"%s\", new: \"%s\"", \
270 #ModuleName, _d.implName, implName); \
271 */ \
272 } \
273 } \
274 _d.implConstructor = implConstructor; \
275 _d.isAvailableCk = isAvailableCk; \
276 _d.implName = implName; \
277 _d.implLevel = implLevel; \
278 _d.implCleanupCallback = zfself::_ZFP_ZFProtocolInstanceCleanupCallback; \
279 } \
280 static void _ZFP_ZFProtocolImplChange( \
281 ZF_IN _ZFP_ZFProtocolConstructor implConstructor \
282 , ZF_IN _ZFP_ZFProtocolIsAvailableCkCallback isAvailableCk \
283 , ZF_IN const zfchar *implName \
284 , ZF_IN ZFProtocolLevel implLevel \
285 ) { \
286 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
287 if(_d.implInstance != zfnull) { \
288 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnDeallocPrepare; \
289 _d.implInstance->protocolOnDeallocPrepare(); \
290 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnDealloc; \
291 _d.implInstance->protocolOnDealloc(); \
292 _d.implInstance->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInit; \
293 } \
294 zfself::_ZFP_ZFProtocolInstanceCleanupCallback(&_d); \
295 if(implConstructor != zfnull && !zfstringIsEmpty(implName)) { \
296 _d.implConstructor = implConstructor; \
297 _d.isAvailableCk = isAvailableCk; \
298 _d.implName = implName; \
299 _d.implLevel = implLevel; \
300 } \
301 else { \
302 _d.implConstructor = zfnull; \
303 _d.isAvailableCk = zfnull; \
304 _d.implName.removeAll(); \
305 _d.implLevel = v_ZFProtocolLevel::e_Default; \
306 } \
307 } \
308 static inline zfbool _ZFP_ZFProtocolIsAvailable(void) { \
309 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
310 return _d.implConstructor != zfnull && _d.isAvailableCk(); \
311 } \
312 static zfself *_ZFP_ZFProtocolNewInstance(void) { \
313 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
314 _ZFP_ZFProtocolImplAccess(); \
315 zfself *retVal = zfnull; \
316 if(_d.isAvailableCk != zfnull && _d.isAvailableCk()) { \
317 retVal = (zfself *)_d.implConstructor(); \
318 if(retVal != zfnull) { \
319 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInit; \
320 retVal->protocolOnInit(); \
321 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_OnInitFinish; \
322 retVal->protocolOnInitFinish(); \
323 retVal->_ZFP_ZFProtocol_protocolInstanceState = v_ZFProtocolInstanceState::e_Idle; \
324 } \
325 } \
326 return retVal; \
327 } \
328 static zfself *_ZFP_ZFProtocolAccess(void) { \
329 static ZFProtocol *&impl = zfself::_ZFP_ZFProtocolDataRef().implInstance; \
330 if(impl == zfnull) { \
331 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
332 _d.implInstance = zfself::_ZFP_ZFProtocolNewInstance(); \
333 if(_d.implInstance == zfnull) { \
334 ZFCoreCriticalMessageTrim("no implementation for protocol \"%s\"", \
335 #ModuleName); \
336 return zfnull; \
337 } \
338 const zfchar *desiredImplPlatformHint = zfnull; \
339 const zfchar *mismatchProtocolName = zfnull; \
340 ZFProtocol *mismatchImpl = zfnull; \
341 if(!_d.implInstance->_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl)) { \
342 ZFCoreCriticalErrorPrepare(); \
343 zfstring err; \
344 zfstringAppend(err, "(%s)%s depends on (%s)\"%s\"", \
345 _d.implInstance->protocolName(), \
346 _d.implInstance->protocolImplName(), \
347 mismatchProtocolName, \
348 desiredImplPlatformHint); \
349 if(mismatchImpl == zfnull) { \
350 zfstringAppend(err, " but it's not implemented"); \
351 } \
352 else { \
353 zfstringAppend(err, " but it's implementation \"%s\" mismatch", \
354 mismatchImpl->protocolImplPlatformHint()); \
355 } \
356 ZFCoreLogTrim(err); \
357 ZFCoreCriticalError(); \
358 zfdelete(_d.implInstance); \
359 _d.implInstance = zfnull; \
360 return zfnull; \
361 } \
362 } \
363 return (zfself *)impl; \
364 } \
365 static zfself *_ZFP_ZFProtocolTryAccess(void) { \
366 static ZFProtocol *&impl = zfself::_ZFP_ZFProtocolDataRef().implInstance; \
367 if(impl == zfnull) { \
368 _ZFP_ZFProtocolData &_d = zfself::_ZFP_ZFProtocolDataRef(); \
369 _d.implInstance = zfself::_ZFP_ZFProtocolNewInstance(); \
370 const zfchar *desiredImplPlatformHint = zfnull; \
371 const zfchar *mismatchProtocolName = zfnull; \
372 ZFProtocol *mismatchImpl = zfnull; \
373 if(_d.implInstance != zfnull \
374 && !_d.implInstance->_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl) \
375 ) { \
376 zfdelete(_d.implInstance); \
377 _d.implInstance = zfnull; \
378 } \
379 } \
380 return (zfself *)impl; \
381 } \
382 static zfbool _ZFP_ZFProtocolIsAvailableCk(void) { \
383 return zftrue; \
384 }
385#define _ZFP_ZFPROTOCOL_INTERFACE_END(ModuleName) \
386 };
387
408 * @endcode
409 * for the difference between them, see #ZFPROTOCOL_TRY_ACCESS\n
410 * for how to implement it, see #ZFPROTOCOL_IMPLEMENTATION_BEGIN\n
411 * for how to access the implementation, see #ZFPROTOCOL_TRY_ACCESS
412 * @note all protocol is singleton mode
413 */
414#define ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName) \
415 _ZFP_ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName)
416
420#define ZFPROTOCOL_INTERFACE_END(ModuleName) \
421 _ZFP_ZFPROTOCOL_INTERFACE_END(ModuleName)
422
426#define ZFPROTOCOL_INTERFACE_OPTIONAL \
427 protected: \
428 static zfbool _ZFP_ZFProtocolOptional(void) { \
429 return zftrue; \
430 } \
431 public:
432
435
436#define ZFPROTOCOL_INTERFACE_REGISTER(ModuleName) \
437 ZF_STATIC_REGISTER_INIT(ZFProtocolInterfaceRegister_##ModuleName) { \
438 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolDataRegister(); \
439 } \
440 ZF_STATIC_REGISTER_END(ZFProtocolInterfaceRegister_##ModuleName)
441
442// ============================================================
461 * ZFPROTOCOL_TRY_ACCESS would create new instance only for the first time,
462 * and the instance would be destroyed at a certain proper time\n
463 * \n
464 * when using ZFPROTOCOL_TRY_ACCESS, you take full responsibility to check whether
465 * the implmentation is available
466 */
467#define ZFPROTOCOL_TRY_ACCESS(ModuleName) \
468 (ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolTryAccess())
469
473#define ZFPROTOCOL_ACCESS(ModuleName) \
474 (ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolAccess())
475
479#define ZFPROTOCOL_IS_AVAILABLE(ModuleName) \
480 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolIsAvailable()
481
482typedef void (*_ZFP_ZFProtocolImplRegisterHolderClearCallback)(void);
483zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFProtocolImplRegisterHolder {
484public:
485 _ZFP_ZFProtocolImplRegisterHolder(ZF_IN _ZFP_ZFProtocolImplRegisterHolderClearCallback callback)
486 : callback(callback)
487 {
488 }
489 ~_ZFP_ZFProtocolImplRegisterHolder(void) {
490 this->callback();
491 }
492private:
493 _ZFP_ZFProtocolImplRegisterHolderClearCallback callback;
494};
495// ============================================================
496#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN_(ImplementationName, ImplementationClass, ModuleName, implLevel) \
497 zfclassNotPOD ImplementationClass : zfextend ZFPROTOCOL_INTERFACE_CLASS(ModuleName) { \
498 protected: \
499 \
500 typedef ZFPROTOCOL_INTERFACE_CLASS(ModuleName) zfsuper; \
501 \
502 typedef ImplementationClass zfself; \
503 public: \
504 zfoverride \
505 virtual const zfchar *protocolImplName(void) const { \
506 return #ImplementationName; \
507 } \
508 zfoverride \
509 virtual ZFProtocolLevel protocolImplLevel(void) const { \
510 return implLevel; \
511 } \
512 public: \
513 static ZFProtocol *_ZFP_##ImplementationClass##_ctor(void) { \
514 return zfnew(ImplementationClass); \
515 } \
516 static void _ZFP_ZFProtocolUnregister(void) { \
517 if(ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolDataRef().implConstructor == &ImplementationClass::_ZFP_##ImplementationClass##_ctor) { \
518 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange(zfnull, zfnull, zfnull, v_ZFProtocolLevel::e_Default); \
519 } \
520 _ZFP_ZFProtocolImplDataUnregister(#ModuleName); \
521 } \
522 static void _ZFP_ZFProtocolRegister(void) { \
523 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplRegister( \
524 &ImplementationClass::_ZFP_##ImplementationClass##_ctor, \
525 &ImplementationClass::_ZFP_ZFProtocolIsAvailableCk, \
526 zftext(#ImplementationName), \
527 implLevel); \
528 static _ZFP_ZFProtocolImplRegisterHolder _holder(&ImplementationClass::_ZFP_ZFProtocolUnregister); \
529 } \
530 static void _ZFP_ZFProtocolChange(void) { \
531 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange( \
532 &ImplementationClass::_ZFP_##ImplementationClass##_ctor, \
533 &ImplementationClass::_ZFP_ZFProtocolIsAvailableCk, \
534 zftext(#ImplementationName), \
535 implLevel); \
536 }
537#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ImplementationClass, ModuleName, implLevel) \
538 _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN_(ImplementationName, ImplementationClass, ModuleName, implLevel)
539
540#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_END_(ImplementationName, ImplementationClass) \
541 }; \
542 ZFOUTPUT_TYPE(ImplementationClass, {zftToStringT(s, (ZFProtocol const &)v);}) \
543 ZF_STATIC_REGISTER_INIT(ZFPImplReg_##ImplementationClass) { \
544 ImplementationClass::_ZFP_ZFProtocolRegister(); \
545 } \
546 ZF_STATIC_REGISTER_END(ZFPImplReg_##ImplementationClass)
547#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName, ImplementationClass) \
548 _ZFP_ZFPROTOCOL_IMPLEMENTATION_END_(ImplementationName, ImplementationClass)
549
550#define _ZFP_ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction) \
551 static zfbool _ZFP_ZFProtocolIsAvailableCk(void) { \
552 CheckAction \
553 }
554
573 * so that native code can use native code to reflect and access the internal types
574 *
575 * \n
576 * if you are able to access an implementation,
577 * you may check its platform hint by #ZFProtocol::protocolImplPlatformHint
578 */
579#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_HINT(PlatformHint) \
580 public: \
581 virtual const zfchar *protocolImplPlatformHint(void) const { \
582 return PlatformHint; \
583 }
584
591 * ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_ITEM(ProtocolName, "DependencyPlatformHint")
592 * ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_END()
593 * ZFPROTOCOL_IMPLEMENTATION_END(...)
594 * @endcode
595 * the DependencyPlatformHint is the string declared by #ZFPROTOCOL_IMPLEMENTATION_PLATFORM_HINT
596 */
597#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_BEGIN() \
598 public: \
599 virtual zfbool _ZFP_ZFProtocol_checkImplDependency( \
600 ZF_OUT const zfchar *&desiredImplPlatformHint \
601 , ZF_OUT const zfchar *&mismatchProtocolName \
602 , ZF_OUT ZFProtocol *&mismatchImpl \
603 ) const { \
604 if(!zfsuper::_ZFP_ZFProtocol_checkImplDependency(desiredImplPlatformHint, mismatchProtocolName, mismatchImpl)) { \
605 return zffalse; \
606 }
608#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_ITEM(Protocol, DependencyPlatformHint) \
609 if(ZFPROTOCOL_TRY_ACCESS(Protocol) == zfnull \
610 || !zfstringIsEqual(ZFPROTOCOL_ACCESS(Protocol)->protocolImplPlatformHint(), DependencyPlatformHint) \
611 ) { \
612 desiredImplPlatformHint = DependencyPlatformHint; \
613 mismatchProtocolName = ZFM_TOSTRING(Protocol); \
614 mismatchImpl = ZFPROTOCOL_TRY_ACCESS(Protocol); \
615 return zffalse; \
616 }
618#define ZFPROTOCOL_IMPLEMENTATION_PLATFORM_DEPENDENCY_END() \
619 return zftrue; \
620 } \
621 public:
624
628#define ZFPROTOCOL_IMPLEMENTATION_CLASS(Implementation) \
629 ZFPImpl_##Implementation
630
701 * return ZFPROTOCOL_IS_AVAILABLE(OtherProtocol);
702 * })
703 * ...
704 * ZFPROTOCOL_IMPLEMENTATION_END(YourImplementation)
705 * @endcode
706 */
707#define ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ModuleName, implLevel) \
708 _ZFP_ZFPROTOCOL_IMPLEMENTATION_BEGIN(ImplementationName, ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName), ModuleName, implLevel)
711 */
712#define ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName) \
713 _ZFP_ZFPROTOCOL_IMPLEMENTATION_END(ImplementationName, ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName))
717#define ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction) \
718 _ZFP_ZFPROTOCOL_IMPLEMENTATION_CHECK(CheckAction)
719
720// ============================================================
722 * @brief change the implementation at runtime
723 *
724 * old implementation's level is ignored and forced to be replaced\n
725 * it's your responsibility to make sure old implementation isn't in use,
726 * otherwise, app may crash
727 */
728#define ZFProtocolImplChange(ImplementationName) \
729 ZFPROTOCOL_IMPLEMENTATION_CLASS(ImplementationName)::_ZFP_ZFProtocolChange()
733#define ZFProtocolImplRemove(ModuleName) \
734 ZFPROTOCOL_INTERFACE_CLASS(ModuleName)::_ZFP_ZFProtocolImplChange(zfnull, zfnull, zfnull, v_ZFProtocolLevel::e_Default)
735
736// ============================================================
745 , ZFMP_IN(const zfchar *, name)
746 , ZFMP_IN_OPT(const zfchar *, desiredImpl, zfnull)
747 )
756 , ZFMP_IN(const zfchar *, name)
757 , ZFMP_IN_OPT(const zfchar *, desiredImpl, zfnull)
759
760// ============================================================
765public:
778
779public:
781 zffinal void objectInfoT(ZF_IN_OUT zfstring &ret) const;
782
783 zffinal zfstring objectInfo(void) const {
784 zfstring ret;
785 this->objectInfoT(ret);
786 return ret;
787 }
788
789public:
791 zfbool operator == (ZF_IN const ZFProtocolImplInfo &ref) const {
792 return (zftrue
793 && this->protocolName == ref.protocolName
794 && this->protocolOptional == ref.protocolOptional
795 && this->protocolImpl == ref.protocolImpl
796 );
798 zfbool operator != (ZF_IN const ZFProtocolImplInfo &ref) const {
799 return !this->operator == (ref);
800 }
802};
806
823 , ZFMP_IN_OPT(const ZFOutput &, callback, ZFOutputDefault())
824 )
829 , ZFMP_IN(const ZFProtocolImplInfo &, data)
830 , ZFMP_IN_OPT(const ZFOutput &, callback, ZFOutputDefault())
831 )
832
834#endif // #ifndef _ZFI_ZFProtocol_h_
835
#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:180
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
#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:196
#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
ZFProtocol * ZFProtocolForName(const zfchar *name, const zfchar *desiredImpl=(zft_zfnull))
get protocol with name or null if no such protocol
ZFCoreArray< ZFProtocolImplInfo > ZFProtocolImplInfoGetAll()
for debug use only, get all protocol's info
ZFCoreArray< ZFProtocolImplInfo > ZFProtocolImplInfoGetAllNotImplemented()
util method to ZFProtocolImplInfoGetAll
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:758
void objectInfoT(zfstring &ret) const
see objectInfo
zfstring objectInfo(void) const
return object info
Definition ZFProtocol.h:777
zfbool protocolOptional
whether protocol is optional
Definition ZFProtocol.h:767
zfstring protocolName
protocol's name
Definition ZFProtocol.h:763
ZFProtocol * protocolImpl
protocol's implementation, or null if currently not implemented
Definition ZFProtocol.h:771
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:66
zfstring zfstr(const zfchar *fmt=zft_zfnull)
string format util
Definition zfstr.h:59