ZFFramework
 
Loading...
Searching...
No Matches
zfwrap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfwrap_h_
7#define _ZFI_zfwrap_h_
8
9#include "ZFTypeId.h"
10
12
13// ============================================================
36public:
37 zfwrap(void) : zfauto() {}
38 template<typename T_ZFObject>
39 zfwrap(ZF_IN T_ZFObject const &obj) : zfauto(obj) {}
40
41public:
42 template<typename T_ZFObject>
43 inline zfwrap &operator = (ZF_IN T_ZFObject const &obj) {
44 zfauto::operator=(obj);
45 return *this;
46 }
47
48public:
49 template<typename T_ZFObject>
50 inline zfbool operator == (ZF_IN T_ZFObject const &obj) const {
51 return zfauto::operator==(obj);
52 }
53 template<typename T_ZFObject>
54 inline zfbool operator != (ZF_IN T_ZFObject const &obj) const {
55 return zfauto::operator!=(obj);
56 }
57
58public:
59 inline ZFObject *operator -> (void) const {
60 return this->toObject();
61 }
62 inline operator zfbool (void) const {
63 return this->toObject() != zfnull;
64 }
65 inline operator ZFObject * (void) const {
66 return this->toObject();
67 }
68 template<typename T_ZFObject>
69 inline operator T_ZFObject * (void) const {
70 return zfcast(T_ZFObject *, this->toObject());
71 }
72
73public:
74 static const ZFClass *ClassData(void) {
75 return zfauto::ClassData();
76 }
78
79public:
83 inline zfbool valid(void) const {
84 return this->toObject() != zfnull;
85 }
86
90 inline zfany get(void) const {
91 return this->toObject();
92 }
93
96 template<typename T_ZFObject>
97 void set(ZF_IN T_ZFObject const &obj) {
98 zfauto::operator=(obj);
99 }
100
101public:
105 inline ZFObject *toObject(void) const {
106 return zfauto::toObject();
107 }
108
111 template<typename T_ZFObject>
112 inline T_ZFObject to(void) const {
113 return zfcast(T_ZFObject, this->toObject());
114 }
115
119 const zfany &asAny(void) const {
120 return zfauto::asAny();
121 }
122};
124 if(v) {
125 s += "[strong]";
126 v.toObject()->objectInfoT(s);
127 }
128 else {
129 s += ZFTOKEN_zfnull;
130 }
131})
134
135
136// ============================================================
137template<typename T_ZFObject>
138inline zfbool operator == (ZF_IN T_ZFObject *obj, ZF_IN zfwrap const &e) {
139 return e.toObject() == _ZFP_zfanyCast(obj);
140}
141template<typename T_ZFObject>
142inline zfbool operator != (ZF_IN T_ZFObject *obj, ZF_IN zfwrap const &e) {
143 return e.toObject() != _ZFP_zfanyCast(obj);
144}
146
148#endif // #ifndef _ZFI_zfwrap_h_
149
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#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 ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#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
#define ZFTOKEN_zfnull
string tokens
Definition ZFCoreTypeDef_OtherType.h:16
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
reflectable type define
#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
ZFObject's class info.
Definition ZFClass.h:66
base class of all objects
Definition ZFObjectCore.h:205
util method to cast ZFObject types freely
Definition zfany.h:35
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
ZFObject * toObject(void) const
get the holded object
Definition zfautoFwd.h:89
const zfany & asAny(void) const
access as zfany
Definition zfautoFwd.h:75
strong reference to ZFObject
Definition zfwrap.h:34
const zfany & asAny(void) const
access as zfany
Definition zfwrap.h:119
zfany get(void) const
get the holded object
Definition zfwrap.h:90
ZFObject * toObject(void) const
get the holded object
Definition zfwrap.h:105
zfbool valid(void) const
true if the holded object is not null
Definition zfwrap.h:83
void set(T_ZFObject const &obj)
set the holded object
Definition zfwrap.h:97
T_ZFObject to(void) const
cast by zfcast
Definition zfwrap.h:112
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition zfcast.h:24