ZFFramework
 
Loading...
Searching...
No Matches
zfany.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfany_h_
7#define _ZFI_zfany_h_
8
9#include "ZFObjectCast.h"
11
13
14// ============================================================
15// zfany
37public:
38 zfany(void) : _ZFP_obj(zfnull) {}
39 zfany(ZF_IN zfany const &obj) : _ZFP_obj(obj._ZFP_obj) {}
40 zfany(ZF_IN ZFObject *obj) : _ZFP_obj(obj) {}
41 template<typename T_ZFObject>
42 zfany(ZF_IN T_ZFObject const &obj) : _ZFP_obj(_ZFP_zfanyCast(obj)) {}
43
44public:
45 inline zfany &operator = (ZF_IN zfany const &obj) {
46 _ZFP_obj = obj._ZFP_obj;
47 return *this;
48 }
49 template<typename T_ZFObject>
50 inline zfany &operator = (ZF_IN T_ZFObject const &obj) {
51 _ZFP_obj = _ZFP_zfanyCast(obj);
52 return *this;
53 }
54
55public:
56 template<typename T_ZFObject>
57 inline zfbool operator == (ZF_IN T_ZFObject const &obj) const {
58 return this->toObject() == _ZFP_zfanyCast(obj);
59 }
60 template<typename T_ZFObject>
61 inline zfbool operator != (ZF_IN T_ZFObject const &obj) const {
62 return this->toObject() != _ZFP_zfanyCast(obj);
63 }
64
65public:
66 inline ZFObject *operator -> (void) const {
67 return _ZFP_obj;
68 }
69 inline operator ZFObject * (void) const {
70 return _ZFP_obj;
71 }
72 template<typename T_ZFObject>
73 inline operator T_ZFObject * (void) const {
74 return zfcast(T_ZFObject *, _ZFP_obj);
75 }
76
77public:
78 static const ZFClass *ClassData(void);
80
81public:
85 inline ZFObject *toObject(void) const {
86 return _ZFP_obj;
87 }
88
91 template<typename T_ZFObject>
92 inline T_ZFObject to(void) const {
93 return zfcast(T_ZFObject, _ZFP_obj);
94 }
95
96private:
97 ZFObject *_ZFP_obj;
98};
100
101// ============================================================
105template<typename T_ZFObjectBase>
108public:
109 zfanyT(void) : zfany() {}
110 zfanyT(ZF_IN zfany const &obj) : zfany(obj) {}
111 zfanyT(ZF_IN zfanyT<T_ZFObjectBase> const &obj) : zfany((zfany const &)obj) {}
112 zfanyT(ZF_IN ZFObject *obj) : zfany(obj) {}
113 template<typename T_ZFObject>
114 zfanyT(ZF_IN T_ZFObject const &obj) : zfany(obj) {}
115
116public:
117 inline zfanyT<T_ZFObjectBase> &operator = (ZF_IN zfany const &obj) {
118 zfany::operator = (obj);
119 return *this;
120 }
121 inline zfanyT<T_ZFObjectBase> &operator = (ZF_IN zfanyT<T_ZFObjectBase> const &obj) {
122 zfany::operator = ((zfany const &)obj);
123 return *this;
124 }
125 template<typename T_ZFObject>
126 inline zfanyT<T_ZFObjectBase> &operator = (ZF_IN T_ZFObject const &obj) {
127 zfany::operator = (obj);
128 return *this;
129 }
130
131public:
132 template<typename T_ZFObject>
133 inline zfbool operator == (ZF_IN T_ZFObject const &obj) const {
134 return this->toObject() == _ZFP_zfanyCast(obj);
135 }
136 template<typename T_ZFObject>
137 inline zfbool operator != (ZF_IN T_ZFObject const &obj) const {
138 return this->toObject() != _ZFP_zfanyCast(obj);
139 }
140
141public:
142 inline T_ZFObjectBase *operator -> (void) const {
143 return zfcast(T_ZFObjectBase *, this->toObject());
144 }
145
146public:
147 inline ZFObject *toObject(void) const { // required for _ZFP_zfanyCast to work
148 return zfany::toObject();
149 }
150
151public:
152 static const ZFClass *ClassData(void) {
153 return T_ZFObjectBase::ClassData();
154 }
156};
158
159// ============================================================
161template<typename T_ZFObject>
162inline zfbool operator == (ZF_IN T_ZFObject *obj, ZF_IN zfany const &e) {
163 return e.toObject() == _ZFP_zfanyCast(obj);
164}
165template<typename T_ZFObject>
166inline zfbool operator != (ZF_IN T_ZFObject *obj, ZF_IN zfany const &e) {
167 return e.toObject() != _ZFP_zfanyCast(obj);
168}
169
170// ============================================================
171template<typename T_ZFObject, typename T_ZFObjectBase>
172inline zfbool operator == (ZF_IN T_ZFObject *obj, ZF_IN zfanyT<T_ZFObjectBase> const &e) {
173 return e.toObject() == _ZFP_zfanyCast(obj);
174}
175template<typename T_ZFObject, typename T_ZFObjectBase>
176inline zfbool operator != (ZF_IN T_ZFObject *obj, ZF_IN zfanyT<T_ZFObjectBase> const &e) {
177 return e.toObject() != _ZFP_zfanyCast(obj);
178}
180
182#endif // #ifndef _ZFI_zfany_h_
183
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#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:180
#define zfclassPOD
shows the class is a POD type
Definition ZFCoreTypeDef_ClassType.h:35
#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 zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFCORE_POD_DECLARE_NO_COMPARER(Type)
explicitly declare as POD
Definition ZFCoreUtilTemplate.h:563
#define ZFCORE_POD_DECLARE_TEMPLATE_NO_COMPARER(T_Type, Type)
explicitly declare as POD
Definition ZFCoreUtilTemplate.h:566
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
zfcast declarations
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
ZFObject's class info.
Definition ZFClass.h:67
base class of all objects
Definition ZFObjectCore.h:209
util method to cast ZFObject types freely
Definition zfany.h:35
T_ZFObject to(void) const
cast by zfcast
Definition zfany.h:92
ZFObject * toObject(void) const
get the holded object
Definition zfany.h:85
see zfany
Definition zfany.h:106