ZFFramework
 
Loading...
Searching...
No Matches
ZFCoreMap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFCoreMap_h_
7#define _ZFI_ZFCoreMap_h_
8
9#include "ZFCorePointer.h"
10#include "ZFCoreArray.h"
11#include "zfiter.h"
12#include "ZFToken.h"
13
15
16zfclassFwd _ZFP_ZFCoreMapPrivate;
27public:
31 ZFCoreMap(void);
39 zffinal ZFCoreMap &operator = (ZF_IN const ZFCoreMap &ref);
43 zffinal zfbool operator == (ZF_IN const ZFCoreMap &ref) const;
47 zffinal zfbool operator != (ZF_IN const ZFCoreMap &ref) const {return !this->operator == (ref);}
48 ~ZFCoreMap(void);
49
50public:
55 zfstring ret;
56 this->objectInfoT(ret);
57 return ret;
58 }
59
60public:
64 , ZF_IN_OPT zfindex maxCount = zfindexMax()
66 ) const;
69 ZF_IN_OPT zfindex maxCount = zfindexMax()
71 ) const {
72 zfstring ret;
73 this->objectInfoOfContentT(ret, maxCount, token);
74 return ret;
75 }
76
77public:
82
83public:
87 zffinal void copyFrom(ZF_IN const ZFCoreMap &ref);
88
93
94public:
98 zffinal zfindex count(void) const;
99
103 zffinal zfbool isEmpty(void) const;
104
109
113 zffinal void addFrom(ZF_IN const ZFCoreMap &ref);
114
123 ZF_IN const zfstring &key
124 , ZF_IN const ZFCorePointer &value
125 );
129 zffinal const ZFCorePointer *get(ZF_IN const zfstring &key) const;
133 template<typename T_Element>
134 T_Element get(ZF_IN const zfstring &key) const {
135 const ZFCorePointer *t = this->get(key);
136 if(t != zfnull) {
137 return t->pointerValueT<T_Element>();
138 }
139 return zfnull;
140 }
141
147 inline ZFCoreArray<zfstring> allKey(void) const {
149 this->allKeyT(ret);
150 return ret;
151 }
152
160 this->allValueT(ret);
161 return ret;
162 }
163
165 template<typename T_Element>
167 ret.capacity(ret.count() + this->count());
168 for(zfiter it = this->iter(); it; ++it) {
169 ret.add(this->iterValue<T_Element>(it));
170 }
171 }
172
176 zffinal void remove(ZF_IN const zfstring &key);
177
181 zffinal void removeAll(void);
182
183 // ============================================================
184 // iterator access
185public:
187 zffinal zfiter iter(void) const;
188
191
195 zffinal const ZFCorePointer *iterValue(ZF_IN const zfiter &it) const;
196
199 ZF_IN_OUT zfiter &it
200 , ZF_IN const ZFCorePointer &newValue
201 );
204
207 ZF_IN const zfstring &key
208 , ZF_IN const ZFCorePointer &value
209 );
210
212 template<typename T_Element>
213 T_Element iterValue(ZF_IN const zfiter &it) const {
214 const ZFCorePointer *t = this->iterValue(it);
215 if(t != zfnull) {
216 return t->pointerValueT<T_Element>();
217 }
218 return zfnull;
219 }
220
221private:
222 _ZFP_ZFCoreMapPrivate *d;
223};
224ZFOUTPUT_TYPE(ZFCoreMap, {v.objectInfoT(s);})
225
227
228#endif // #ifndef _ZFI_ZFCoreMap_h_
229
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
core map type for private use only
Definition ZFCoreMap.h:26
void swap(ZFCoreMap &ref)
swap internal data
void allValueT(ZFCoreArray< T_Element > &ret) const
see allValue
Definition ZFCoreMap.h:166
zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
return contents info
Definition ZFCoreMap.h:68
void remove(const zfstring &key)
remove or do nothing if not exist
void objectInfoT(zfstring &ret) const
see objectInfo
T_Element get(const zfstring &key) const
get value or null if not exist
Definition ZFCoreMap.h:134
zfstring iterKey(const zfiter &it) const
see zfiter
const ZFCorePointer * iterValue(const zfiter &it) const
see zfiter
zfbool isContain(const zfstring &key) const
true if contains the key
ZFCoreMap(void)
construct an empty map
zfstring objectInfo(void) const
return object info
Definition ZFCoreMap.h:54
zfiter iterFind(const zfstring &key) const
see zfiter
void iterAdd(const zfstring &key, const ZFCorePointer &value)
see zfiter
zfiter iter(void) const
see zfiter
void addFrom(const ZFCoreMap &ref)
add elements from ref
void allKeyT(ZFCoreArray< zfstring > &ret) const
see allKey
void iterValue(zfiter &it, const ZFCorePointer &newValue)
see zfiter
void removeAll(void)
remove all content
zfbool isEmpty(void) const
true if empty
T_Element iterValue(const zfiter &it) const
see zfiter
Definition ZFCoreMap.h:213
void set(const zfstring &key, const ZFCorePointer &value)
change value or create if not exist, value would be retained by this method
void allValueT(ZFCoreArray< const ZFCorePointer * > &ret) const
see allValue
ZFCoreMap(const ZFCoreMap &ref)
retain the ref, to copy, use copyFrom
void iterRemove(zfiter &it)
see zfiter
zfindex objectRetainCount(void) const
get current retain count
void copyFrom(const ZFCoreMap &ref)
copy all contents from ref, remove all before copy
zfindex count(void) const
return count
ZFCoreArray< zfstring > allKey(void) const
return a copy of all keys
Definition ZFCoreMap.h:147
const ZFCorePointer * get(const zfstring &key) const
get value or null if not exist
ZFCoreArray< const ZFCorePointer * > allValue(void) const
return a copy of all values
Definition ZFCoreMap.h:158
void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
see objectInfoOfContent
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