5#ifndef _ZFI_ZFCorePointer_h_
6#define _ZFI_ZFCorePointer_h_
15template<
typename T_Po
inter>
17template<
typename T_Po
inter>
20 static inline void *toNonConstRaw(
ZF_IN T_Pointer *p) {
23 template<
typename T_ZFCorePo
inter>
24 static inline T_Pointer *toPointer(
ZF_IN T_ZFCorePointer p) {
25 return (T_Pointer *)p->pointerValueAccessNonConst();
28template<
typename T_Po
inter>
31 static inline void *toNonConstRaw(
ZF_IN const T_Pointer *p) {
34 template<
typename T_ZFCorePo
inter>
35 static inline const T_Pointer *toPointer(
ZF_IN T_ZFCorePointer p) {
36 return (
const T_Pointer *)p->pointerValueAccess();
50 ZFCorePointer(
void) {}
51 virtual ~ZFCorePointer(
void) {}
109 zfdelete(
const_cast<ZFCorePointer *
>(
this));
123 template<
typename T_Po
interDesired>
125 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this);
136template<typename T_Pointer>
140 T_Pointer pointerValue;
142 _ZFP_ZFCorePointerPrivate(
void)
180template<
typename T_Po
inter,
typename T_ZFCorePo
interType>
187 if(d->pointerValue != value) {
188 T_Pointer pointerValueOld = d->pointerValue;
189 d->pointerValue = value;
191 T_ZFCorePointerType::pointerOnRetain(d->pointerValue);
193 if(pointerValueOld !=
zfnull) {
194 T_ZFCorePointerType::pointerOnDelete(pointerValueOld);
202 return d->pointerValue;
207 inline T_Pointer operator -> (
void)
const {
208 return d->pointerValue;
211 return (d->pointerValue ==
zfnull);
214 return (d->pointerValue !=
zfnull);
216 inline zfbool operator == (
ZF_IN T_Pointer
const &p)
const {
217 return (d->pointerValue == p);
219 inline zfbool operator != (
ZF_IN T_Pointer
const &p)
const {
220 return (d->pointerValue != p);
223 return (d->pointerValue == ref.d->pointerValue);
226 return (d->pointerValue == ref.d->pointerValue);
233 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
237 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
241 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
243 this->pointerValue(value);
252 if(d->refCount == 0) {
253 if(d->pointerValue !=
zfnull) {
254 T_ZFCorePointerType::pointerOnDelete(d->pointerValue);
260 _ZFP_ZFCorePointerPrivate<T_Pointer> *dTmp = d;
264 if(dTmp->refCount == 0) {
265 if(dTmp->pointerValue !=
zfnull) {
266 T_ZFCorePointerType::pointerOnDelete(dTmp->pointerValue);
273 this->pointerValue(value);
276 operator T_Pointer (
void)
const {
277 return d->pointerValue;
291 if(infoGetter !=
zfnull) {
292 infoGetter(ret, d->pointerValue);
301 virtual const ZFCorePointer *
refNew(
void)
const {
306 return d->pointerValue;
310 return _ZFP_ZFCorePointerHelper<T_Pointer>::toNonConstRaw(d->pointerValue);
319 template<
typename T_Po
interDesired>
320 inline T_PointerDesired pointerValueT(
void)
const {
321 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this);
326 _ZFP_ZFCorePointerPrivate<T_Pointer> *d;
348 template<
typename T_Po
inter> \
351 static inline void pointerOnRetain(T_Pointer
const &p) \
352 pointerRetainAction \
353 static
inline void pointerOnDelete(T_Pointer
const &p) \
354 pointerDeleteAction \
357 template<
typename T_Po
inter> \
361 T_ZFCorePointer(
void) \
365 T_ZFCorePointer(
ZF_IN T_Pointer
const &value) \
373 T_ZFCorePointer(
ZF_IN ZFCorePointerT<T_Pointer, _ZFP_CPT_##T_ZFCorePointer<T_Pointer> >
const &ref) \
377 T_ZFCorePointer<T_Pointer> &operator = (
ZF_IN T_Pointer
const &value) { \
381 T_ZFCorePointer<T_Pointer> &operator = (
ZF_IN ZFCorePointerT<T_Pointer, _ZFP_CPT_##T_ZFCorePointer<T_Pointer> >
const &ref) { \
385 template<
typename T_Po
interDesired> \
386 inline T_PointerDesired pointerValueT(
void)
const { \
387 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this); \
389 inline T_Pointer operator -> (
void)
const { \
390 return this->pointerValue(); \
392 template<
typename T_Ref> \
393 inline T_Ref operator * (
void)
const { \
394 return *(this->pointerValue()); \
397 return (this->pointerValue() ==
zfnull); \
400 return (this->pointerValue() !=
zfnull); \
402 inline zfbool operator == (
ZF_IN T_Pointer
const &p)
const { \
403 return (this->pointerValue() == p); \
405 inline zfbool operator != (
ZF_IN T_Pointer
const &p)
const { \
406 return (this->pointerValue() != p); \
408 inline zfbool operator == (
ZF_IN T_ZFCorePointer<T_Pointer>
const &ref)
const { \
409 return (this->pointerValue() == ref.pointerValue()); \
411 inline zfbool operator != (
ZF_IN T_ZFCorePointer<T_Pointer>
const &ref)
const { \
412 return (this->pointerValue() == ref.pointerValue()); \
416 ZFOUTPUT_TYPE_TEMPLATE(
typename T_Pointer, T_ZFCorePointer<T_Pointer>, {v.objectInfoT(s);})
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZFCOREPOINTER_DECLARE(T_ZFCorePointer, pointerRetainAction, pointerDeleteAction)
declare your custom ZFCorePointerT type
Definition ZFCorePointer.h:347
#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 zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfpurevirtual
dummy macro shows that a method is pure virtual method
Definition ZFCoreTypeDef_ClassType.h:68
#define zfdelete(instance)
same as delete defined for future use
Definition ZFCoreTypeDef_ClassType.h:91
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define zffree(ptr)
same as free defined for future use, do nothing if ptr is NULL
Definition ZFCoreTypeDef_ClassType.h:112
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#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 zfnew(Type,...)
same as new defined for future use
Definition ZFCoreTypeDef_ClassType.h:89
#define zfnullT
type for zfnull, can be used for function overload
Definition ZFCoreTypeDef_CoreType.h:85
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
#define ZFOUTPUT_TYPE_TEMPLATE(T_typenameList, T_Type, outputAction)
see ZFOUTPUT_TYPE
Definition ZFCoreTypeDef_OtherType.h:262
#define ZFTOKEN_zfnull
string tokens
Definition ZFCoreTypeDef_OtherType.h:16
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
@ ZFCompareUncomparable
Definition ZFCoreTypeDef_OtherType.h:29
@ ZFCompareEqual
Definition ZFCoreTypeDef_OtherType.h:31
void zftToStringT(zfstring &s, T_Type const &v)
util function to obtain object info
Definition ZFCoreTypeDef_OtherType.h:182
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFM_EXPAND(...)
macro to expand a macro
Definition ZFCoreUtilMacro.h:148
#define zfpoolDelete(obj)
see zfpoolNew
Definition ZFMemPool.h:38
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
void(* InfoGetter)(zfstring &ret, T_Type const &v)
proto type for obtain object info, see zftToStringT
Definition ZFCoreTypeDef_OtherType.h:151
see ZFCorePointerT
Definition ZFCorePointer.h:420
see ZFCorePointerT
Definition ZFCorePointer.h:419
see ZFCorePointerT
Definition ZFCorePointer.h:418
see ZFCorePointerT
Definition ZFCorePointer.h:421
abstract base class for ZFCorePointerT
Definition ZFCorePointer.h:46
virtual ZFCompareResult objectCompare(const ZFCorePointer &another) const
compare by internal pointer value
Definition ZFCorePointer.h:87
virtual const ZFCorePointer * refNew(void) const =0
create a new reference to the smart pointer
virtual void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFCorePointer.h:56
T_PointerDesired pointerValueT(void) const
util method to get and cast to desired type
Definition ZFCorePointer.h:124
virtual void objectInfoOfContentT(zfstring &ret) const =0
see objectInfoOfContent
virtual const void * pointerValueAccess(void) const =0
get the internal pointer
virtual zfstring objectInfoOfContent(void) const
get content info or ZFTOKEN_zftToStringNotAvailable if not available
Definition ZFCorePointer.h:77
virtual zfstring objectInfo(void) const
return object info
Definition ZFCorePointer.h:65
virtual void * pointerValueAccessNonConst(void) const =0
get the internal pointer
virtual void refDelete(void) const
see refNew
Definition ZFCorePointer.h:108
virtual zfindex objectRetainCount(void) const =0
get current retain count
pointer container with reference count logic
Definition ZFCorePointer.h:181
virtual zfindex objectRetainCount(void) const
get current retain count
Definition ZFCorePointer.h:314
void pointerValue(T_Pointer const &value)
set the pointer value
Definition ZFCorePointer.h:186
virtual const ZFCorePointer * refNew(void) const
create a new reference to the smart pointer
Definition ZFCorePointer.h:301
virtual void objectInfoOfContentT(zfstring &ret) const
see objectInfoOfContent
Definition ZFCorePointer.h:283
T_Pointer const & pointerValue(void) const
get the pointer value
Definition ZFCorePointer.h:201
virtual void * pointerValueAccessNonConst(void) const
get the internal pointer
Definition ZFCorePointer.h:309
virtual void objectInfoOfContentT(zfstring &ret, typename ZFCoreInfoGetter< T_Pointer >::InfoGetter infoGetter) const
see objectInfoOfContent
Definition ZFCorePointer.h:287
virtual const void * pointerValueAccess(void) const
get the internal pointer
Definition ZFCorePointer.h:305