ZFFramework
 
Loading...
Searching...
No Matches
zfiter.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfiter_h_
7#define _ZFI_zfiter_h_
8
9#include "ZFCoreTypeDef.h"
10
12
41
42public:
44 inline zfbool valid(void) const {
45 return d && d->valid();
46 }
47
48 inline void next(void) const {
49 if(d) {
50 d->next();
51 }
52 }
53
54 inline zfiter copy(void) const {
55 return zfiter(d ? d->copy() : zfnull);
56 }
57
58 inline zfbool isEqual(ZF_IN const zfiter &ref) const {
59 return this->operator == (ref);
60 }
61
62 inline operator zfbool (void) const {
63 return this->valid();
64 }
65 inline zfiter &operator ++ (void) {
66 this->next();
67 return *this;
68 }
69 inline zfiter operator ++ (int) {
70 if(d) {
71 zfiter ret(d->copy());
72 d->next();
73 return ret;
74 }
75 else {
76 return zfnull;
77 }
78 }
80
81 // ============================================================
82public:
85 public:
86 virtual ~Impl(void) {}
87 public:
89 virtual zfbool valid(void) zfpurevirtual;
91 virtual void next(void) zfpurevirtual;
93 virtual Impl *copy(void) zfpurevirtual;
95 virtual void destroy(void) zfpurevirtual;
98 };
99
100public:
104 zfiter(void) : d(zfnull) {}
110 }
111
115 inline Impl *impl(void) const {
116 return d;
117 }
118
122 template<typename T_Impl>
123 inline T_Impl impl(void) const {
124 return (T_Impl)d;
125 }
126
127public:
132 zfstring ret;
133 this->objectInfoT(ret);
134 return ret;
135 }
136
137public:
139 zfiter(ZF_IN const zfnullT &dummy) : d(zfnull) {}
140 zfiter(ZF_IN const zfiter &ref) : d(ref.d ? ref.d->copy() : zfnull) {}
141 ~zfiter(void) {
142 if(d) {
143 d->destroy();
144 }
145 }
146 zfiter &operator = (ZF_IN const zfnullT &ref) {
147 if(d) {
148 Impl *dOld = d;
149 d = zfnull;
150 if(dOld) {
151 dOld->destroy();
152 }
153 }
154 return *this;
155 }
156 zfiter &operator = (ZF_IN const zfiter &ref) {
157 if(this != &ref) {
158 Impl *dOld = d;
159 d = (ref.d ? ref.d->copy() : zfnull);
160 if(dOld) {
161 dOld->destroy();
162 }
163 }
164 return *this;
165 }
166 inline zfbool operator == (ZF_IN const zfnullT &ref) const {return !this->valid();}
167 inline zfbool operator != (ZF_IN const zfnullT &ref) const {return this->valid();}
168 zfbool operator == (ZF_IN const zfiter &ref) const {
169 if(d == ref.d) {
170 return zftrue;
171 }
172 else if(d == zfnull || !d->valid()) {
173 return ref.d == zfnull || !ref.d->valid();
174 }
175 else {
176 return ref.d != zfnull && d->isEqual(ref.d);
177 }
178 }
179 inline zfbool operator != (ZF_IN const zfiter &ref) const {return !this->operator == (ref);}
181private:
182 Impl *d;
183};
184ZFOUTPUT_TYPE(zfiter, {v.objectInfoT(s);})
185
187
188#endif // #ifndef _ZFI_zfiter_h_
189
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
types for ZFFramework
#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 zfpurevirtual
dummy macro shows that a method is pure virtual method
Definition ZFCoreTypeDef_ClassType.h:68
#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 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
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#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 ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
see zfiter
Definition zfiter.h:84
virtual zfbool valid(void)=0
see zfiter
virtual zfbool isEqual(Impl *d)=0
see zfiter
virtual Impl * copy(void)=0
see zfiter
virtual void next(void)=0
see zfiter
virtual void destroy(void)=0
see zfiter
iterator for ZFFramework
Definition zfiter.h:40
zfiter copy(void) const
copy
Definition zfiter.h:54
zfiter(Impl *impl)
implementations of iterables must use this to create an iterator, see zfiter
Definition zfiter.h:109
zfbool isEqual(const zfiter &ref) const
compare
Definition zfiter.h:58
zfiter(void)
create a dummy iterator
Definition zfiter.h:104
Impl * impl(void) const
implementations may use this method to access data passed from constructor, see zfiter
Definition zfiter.h:115
void next(void) const
move to next
Definition zfiter.h:48
T_Impl impl(void) const
implementations may use this method to access data passed from constructor, see zfiter
Definition zfiter.h:123
zfstring objectInfo(void) const
return object info
Definition zfiter.h:131
zfbool valid(void) const
whether valid
Definition zfiter.h:44
void objectInfoT(zfstring &ret) const
see objectInfo