ZFFramework
 
Loading...
Searching...
No Matches
ZFCoreOrderMap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFCoreOrderMap_h_
7#define _ZFI_ZFCoreOrderMap_h_
8
9#include "ZFCorePointer.h"
10#include "ZFCoreArray.h"
11#include "zfiter.h"
12#include "ZFToken.h"
13
15
16zfclassFwd _ZFP_ZFCoreOrderMapPrivate;
21public:
33 zffinal ZFCoreOrderMap &operator = (ZF_IN const ZFCoreOrderMap &ref);
37 zffinal zfbool operator == (ZF_IN const ZFCoreOrderMap &ref) const;
41 zffinal zfbool operator != (ZF_IN const ZFCoreOrderMap &ref) const {return !this->operator == (ref);}
42 ~ZFCoreOrderMap(void);
43
44public:
49 zfstring ret;
50 this->objectInfoT(ret);
51 return ret;
52 }
53
54public:
58 , ZF_IN_OPT zfindex maxCount = zfindexMax()
60 ) const;
63 ZF_IN_OPT zfindex maxCount = zfindexMax()
65 ) const {
66 zfstring ret;
67 this->objectInfoOfContentT(ret, maxCount, token);
68 return ret;
69 }
70
71public:
76
77public:
82
87
88public:
92 zffinal zfindex count(void) const;
93
97 zffinal zfbool isEmpty(void) const;
98
103
108
117 ZF_IN const zfstring &key
118 , ZF_IN const ZFCorePointer &value
119 );
123 zffinal const ZFCorePointer *get(ZF_IN const zfstring &key) const;
127 template<typename T_Element>
128 T_Element get(ZF_IN const zfstring &key) const {
129 const ZFCorePointer *t = this->get(key);
130 if(t != zfnull) {
131 return t->pointerValueT<T_Element>();
132 }
133 return zfnull;
134 }
135
141 inline ZFCoreArray<zfstring> allKey(void) const {
143 this->allKeyT(ret);
144 return ret;
145 }
146
154 this->allValueT(ret);
155 return ret;
156 }
157
159 template<typename T_Element>
161 ret.capacity(ret.count() + this->count());
162 for(zfiter it = this->iter(); it; ++it) {
163 ret.add(this->iterValue<T_Element>(it));
164 }
165 }
166
170 zffinal void remove(ZF_IN const zfstring &key);
171
175 zffinal void removeAll(void);
176
177 // ============================================================
178 // iterator access
179public:
181 zffinal zfiter iter(void) const;
182
185
189 zffinal const ZFCorePointer *iterValue(ZF_IN const zfiter &it) const;
190
193 ZF_IN_OUT zfiter &it
194 , ZF_IN const ZFCorePointer &newValue
195 );
198
201 ZF_IN const zfstring &key
202 , ZF_IN const ZFCorePointer &value
203 );
204
206 template<typename T_Element>
207 T_Element iterValue(ZF_IN const zfiter &it) const {
208 const ZFCorePointer *t = this->iterValue(it);
209 if(t != zfnull) {
210 return t->pointerValueT<T_Element>();
211 }
212 return zfnull;
213 }
214
215 // ============================================================
216 // order map spec
217public:
221 zffinal const ZFCorePointer *update(ZF_IN const zfstring &key) const;
225 template<typename T_Element>
226 T_Element update(ZF_IN const zfstring &key) const {
227 const ZFCorePointer *t = this->update(key);
228 if(t != zfnull) {
229 return t->pointerValueT<T_Element>();
230 }
231 return zfnull;
232 }
233
234private:
235 _ZFP_ZFCoreOrderMapPrivate *d;
236};
237ZFOUTPUT_TYPE(ZFCoreOrderMap, {v.objectInfoT(s);})
238
240
241#endif // #ifndef _ZFI_ZFCoreOrderMap_h_
242
light weight array
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
light weight smart pointer
#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 ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_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 zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#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
string token util
#define ZFTokenForKeyValueContainerDefault()
see ZFTokenForKeyValueContainer, modifyable, ZFTokenForKeyValueContainerTrim by default
Definition ZFToken.h:214
light weight array
Definition ZFCoreArray.h:331
map type which keeps item order, for private use only
Definition ZFCoreOrderMap.h:20
const ZFCorePointer * get(const zfstring &key) const
get value or null if not exist
zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
return contents info
Definition ZFCoreOrderMap.h:62
zfbool isContain(const zfstring &key) const
true if contains the key
void allKeyT(ZFCoreArray< zfstring > &ret) const
see allKey
zfindex objectRetainCount(void) const
get current retain count
void remove(const zfstring &key)
remove or do nothing if not exist
void swap(ZFCoreOrderMap &ref)
swap internal data
void iterRemove(zfiter &it)
see zfiter
T_Element get(const zfstring &key) const
get value or null if not exist
Definition ZFCoreOrderMap.h:128
zfstring iterKey(const zfiter &it) const
see zfiter
zfbool isEmpty(void) const
true if empty
ZFCoreArray< zfstring > allKey(void) const
return a copy of all keys
Definition ZFCoreOrderMap.h:141
void allValueT(ZFCoreArray< T_Element > &ret) const
see allValue
Definition ZFCoreOrderMap.h:160
T_Element update(const zfstring &key) const
try update value order by moving to tail, return null if not exist
Definition ZFCoreOrderMap.h:226
T_Element iterValue(const zfiter &it) const
see zfiter
Definition ZFCoreOrderMap.h:207
void removeAll(void)
remove all content
zfiter iterFind(const zfstring &key) const
see zfiter
ZFCoreOrderMap(void)
construct an empty map
zfstring objectInfo(void) const
return object info
Definition ZFCoreOrderMap.h:48
zfiter iter(void) const
see zfiter
ZFCoreOrderMap(const ZFCoreOrderMap &ref)
retain the ref, to copy, use copyFrom
const ZFCorePointer * iterValue(const zfiter &it) const
see zfiter
void allValueT(ZFCoreArray< const ZFCorePointer * > &ret) const
see allValue
void set(const zfstring &key, const ZFCorePointer &value)
change value or create if not exist, value would be retained by this method
void addFrom(const ZFCoreOrderMap &ref)
add elements from ref
ZFCoreArray< const ZFCorePointer * > allValue(void) const
return a copy of all values
Definition ZFCoreOrderMap.h:152
void copyFrom(const ZFCoreOrderMap &ref)
copy all contents from ref, remove all before copy
void iterValue(zfiter &it, const ZFCorePointer &newValue)
see zfiter
const ZFCorePointer * update(const zfstring &key) const
try update value order by moving to tail, return null if not exist
void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
see objectInfoOfContent
zfindex count(void) const
return count
void objectInfoT(zfstring &ret) const
see objectInfo
void iterAdd(const zfstring &key, const ZFCorePointer &value)
see zfiter
abstract base class for ZFCorePointerT
Definition ZFCorePointer.h:46
T_PointerDesired pointerValueT(void) const
util method to get and cast to desired type
Definition ZFCorePointer.h:124
util class to hold string tokens
Definition ZFToken.h:113
iterator for ZFFramework
Definition zfiter.h:40
iterator in ZFFramework