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) {}
108 zfdelete(
const_cast<ZFCorePointer *
>(
this));
122 template<
typename T_Po
interDesired>
124 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this);
135template<typename T_Pointer>
139 T_Pointer pointerValue;
141 _ZFP_ZFCorePointerPrivate(
void)
179template<
typename T_Po
inter,
typename T_ZFCorePo
interType>
186 if(d->pointerValue != value) {
187 T_Pointer pointerValueOld = d->pointerValue;
188 d->pointerValue = value;
190 T_ZFCorePointerType::pointerOnRetain(d->pointerValue);
192 if(pointerValueOld !=
zfnull) {
193 T_ZFCorePointerType::pointerOnDelete(pointerValueOld);
201 return d->pointerValue;
206 inline T_Pointer operator -> (
void)
const {
207 return d->pointerValue;
210 return (d->pointerValue ==
zfnull);
213 return (d->pointerValue !=
zfnull);
215 inline zfbool operator == (
ZF_IN T_Pointer
const &p)
const {
216 return (d->pointerValue == p);
218 inline zfbool operator != (
ZF_IN T_Pointer
const &p)
const {
219 return (d->pointerValue != p);
222 return (d->pointerValue == ref.d->pointerValue);
225 return (d->pointerValue == ref.d->pointerValue);
232 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
236 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
240 : d(
zfnew(_ZFP_ZFCorePointerPrivate<T_Pointer>))
242 this->pointerValue(value);
251 if(d->refCount == 0) {
252 if(d->pointerValue !=
zfnull) {
253 T_ZFCorePointerType::pointerOnDelete(d->pointerValue);
259 _ZFP_ZFCorePointerPrivate<T_Pointer> *dTmp = d;
263 if(dTmp->refCount == 0) {
264 if(dTmp->pointerValue !=
zfnull) {
265 T_ZFCorePointerType::pointerOnDelete(dTmp->pointerValue);
272 this->pointerValue(value);
275 operator T_Pointer (
void)
const {
276 return d->pointerValue;
290 if(infoGetter !=
zfnull) {
291 infoGetter(ret, d->pointerValue);
300 virtual const ZFCorePointer *
refNew(
void)
const {
305 return d->pointerValue;
309 return _ZFP_ZFCorePointerHelper<T_Pointer>::toNonConstRaw(d->pointerValue);
318 template<
typename T_Po
interDesired>
319 inline T_PointerDesired pointerValueT(
void)
const {
320 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this);
325 _ZFP_ZFCorePointerPrivate<T_Pointer> *d;
347 template<
typename T_Po
inter> \
350 static inline void pointerOnRetain(T_Pointer
const &p) \
351 pointerRetainAction \
352 static
inline void pointerOnDelete(T_Pointer
const &p) \
353 pointerDeleteAction \
356 template<
typename T_Po
inter> \
360 T_ZFCorePointer(
void) \
364 T_ZFCorePointer(
ZF_IN T_Pointer
const &value) \
372 T_ZFCorePointer(
ZF_IN ZFCorePointerT<T_Pointer, _ZFP_CPT_##T_ZFCorePointer<T_Pointer> >
const &ref) \
376 T_ZFCorePointer<T_Pointer> &operator = (
ZF_IN T_Pointer
const &value) { \
380 T_ZFCorePointer<T_Pointer> &operator = (
ZF_IN ZFCorePointerT<T_Pointer, _ZFP_CPT_##T_ZFCorePointer<T_Pointer> >
const &ref) { \
384 template<
typename T_Po
interDesired> \
385 inline T_PointerDesired pointerValueT(
void)
const { \
386 return _ZFP_ZFCorePointerHelper<T_PointerDesired>::toPointer(
this); \
388 inline T_Pointer operator -> (
void)
const { \
389 return this->pointerValue(); \
391 template<
typename T_Ref> \
392 inline T_Ref operator * (
void)
const { \
393 return *(this->pointerValue()); \
396 return (this->pointerValue() ==
zfnull); \
399 return (this->pointerValue() !=
zfnull); \
401 inline zfbool operator == (
ZF_IN T_Pointer
const &p)
const { \
402 return (this->pointerValue() == p); \
404 inline zfbool operator != (
ZF_IN T_Pointer
const &p)
const { \
405 return (this->pointerValue() != p); \
407 inline zfbool operator == (
ZF_IN T_ZFCorePointer<T_Pointer>
const &ref)
const { \
408 return (this->pointerValue() == ref.pointerValue()); \
410 inline zfbool operator != (
ZF_IN T_ZFCorePointer<T_Pointer>
const &ref)
const { \
411 return (this->pointerValue() == ref.pointerValue()); \
415 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:346
#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:110
#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:104
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
#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 zfnew(Type,...)
same as new defined for future use
Definition ZFCoreTypeDef_ClassType.h:107
#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 ZFM_COMMA()
macro to a comma
Definition ZFCoreUtilMacro.h:143
#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:419
see ZFCorePointerT
Definition ZFCorePointer.h:418
see ZFCorePointerT
Definition ZFCorePointer.h:417
see ZFCorePointerT
Definition ZFCorePointer.h:420
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:123
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:107
virtual zfindex objectRetainCount(void) const =0
get current retain count
pointer container with reference count logic
Definition ZFCorePointer.h:180
virtual zfindex objectRetainCount(void) const
get current retain count
Definition ZFCorePointer.h:313
void pointerValue(T_Pointer const &value)
set the pointer value
Definition ZFCorePointer.h:185
virtual const ZFCorePointer * refNew(void) const
create a new reference to the smart pointer
Definition ZFCorePointer.h:300
virtual void objectInfoOfContentT(zfstring &ret) const
see objectInfoOfContent
Definition ZFCorePointer.h:282
T_Pointer const & pointerValue(void) const
get the pointer value
Definition ZFCorePointer.h:200
virtual void * pointerValueAccessNonConst(void) const
get the internal pointer
Definition ZFCorePointer.h:308
virtual void objectInfoOfContentT(zfstring &ret, typename ZFCoreInfoGetter< T_Pointer >::InfoGetter infoGetter) const
see objectInfoOfContent
Definition ZFCorePointer.h:286
virtual const void * pointerValueAccess(void) const
get the internal pointer
Definition ZFCorePointer.h:304