6#ifndef _ZFI_ZFCoreMap_h_
7#define _ZFI_ZFCoreMap_h_
21 virtual ~BaseKey(
void) {}
31 virtual ~BaseValue(
void) {}
40 typedef BaseValue *(*Fn_ValueCreate)(void);
44 static _ZFP_ZFCoreMap *create(
void);
45 static void destroy(
ZF_IN _ZFP_ZFCoreMap *d);
46 _ZFP_ZFCoreMap(
void) : refCount(1) {}
47 virtual ~_ZFP_ZFCoreMap(
void) {}
49 virtual void objectInfoOfContentT(
76template<
typename T_Key>
85template<
typename T_Key>
100template<
typename T_Key,
typename T_Value,
typename T_Hash = ZFCoreMapKeyHash<T_Key>,
typename T_Equal = ZFCoreMapKeyEqual<T_Key> >
119 _ZFP_ZFCoreMap *dTmp = d;
124 if(dTmp && (--(dTmp->refCount)) == 0) {
125 _ZFP_ZFCoreMap::destroy(dTmp);
138 if(d && (--(d->refCount)) == 0) {
139 _ZFP_ZFCoreMap::destroy(d);
152 _ZFP_ZFCoreMap *dTmp = d;
154 if(--(dTmp->refCount) == 0) {
179 return d->objectCompareValue(ref.d);
202 ret += token.tokenLeft;
204 d->objectInfoOfContentT(ret, maxCount, token);
206 ret += token.tokenRight;
224 _ZFP_ZFCoreMap *dTmp = d;
258 return d ? d->count() : 0;
265 return !d || d->isEmpty();
272 return d && d->isContain(_KeyCreate(key));
299 ZF_IN const T_Key &key
300 ,
ZF_IN const T_Value &value
303 d->set(_KeyCreate(key), _ValueCreate(value));
310 ImplValue *value = (ImplValue *)d->get(_KeyCreate(key));
322 ImplValue *value = (ImplValue *)d->get(_KeyCreate(key));
334 return ((ImplValue *)d->access(_KeyCreate(key), _ValueCreate))->v;
340 for(
zfiter it = d->iter(); it; ++it) {
341 ret.add(((
const ImplKey *)d->iterKey(it))->v);
357 for(
zfiter it = d->iter(); it; ++it) {
358 ret.add(((
const ImplValue *)d->iterValue(it))->v);
376 d->remove(_KeyCreate(key));
394 return d ? d->iter() :
zfiter();
399 return d ? d->iterFind(_KeyCreate(key)) :
zfiter();
404 return ((
const ImplKey *)d->iterKey(it))->v;
408 return ((
const ImplValue *)d->iterValue(it))->v;
413 return ((ImplValue *)d->iterValue(it))->v;
418 ,
ZF_IN const T_Value &value
421 d->iterValue(it, _ValueCreate(value));
433 ZF_IN const T_Key &key
434 ,
ZF_IN const T_Value &value
437 return d->iterAdd(_KeyCreate(key), _ValueCreate(value));
444 ImplKey(
ZF_IN T_Key
const &v) : v(v) {}
446 virtual zfidentity implHash(
void)
const {
return T_Hash()(v);}
447 virtual zfbool implEqual(
ZF_IN const BaseKey *ref)
const {
return T_Equal()(v, ((ImplKey *)ref)->v);}
449 virtual BaseKey *implCopy(
void)
const {
return zfpoolNew(ImplKey, v);}
455 ImplValue(
void) : v() {}
456 ImplValue(
ZF_IN T_Value
const &v) : v(v) {}
458 virtual void implCopy(
ZF_IN const BaseValue *ref) {v = ((ImplValue *)ref)->v;}
461 virtual BaseValue *implCopy(
void)
const {
return zfpoolNew(ImplValue, v);}
464 static _ZFP_ZFCoreMap::BaseKey *_KeyCreate(
ZF_IN T_Key
const &v) {
467 static _ZFP_ZFCoreMap::BaseValue *_ValueCreate(
ZF_IN T_Value
const &v) {
470 static _ZFP_ZFCoreMap::BaseValue *_ValueCreate(
void) {
475 inline void _dInit(
void) {
477 d = _ZFP_ZFCoreMap::create();
#define ZFComparerDefault
default comparer for common types, see ZFComparer
Definition ZFComparer.h:262
#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 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:184
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:188
#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:200
_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
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
#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
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
#define ZFOUTPUT_TYPE_TEMPLATE(T_typenameList, T_Type, outputAction)
see ZFOUTPUT_TYPE
Definition ZFCoreTypeDef_OtherType.h:262
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
@ ZFCompareUncomparable
Definition ZFCoreTypeDef_OtherType.h:29
@ ZFCompareEqual
Definition ZFCoreTypeDef_OtherType.h:31
void zftToStringT(zfstring &s, T_Type const &v)
util function to obtain object info
Definition ZFCoreTypeDef_OtherType.h:182
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFM_EXPAND(...)
macro to expand a macro
Definition ZFCoreUtilMacro.h:148
zfidentity zfhash(const T_Type &v)
std::hash wrapper
Definition ZFCoreUtilTemplate.h:518
#define zfpoolDelete(obj)
see zfpoolNew
Definition ZFMemPool.h:38
#define zfpoolNew(T_Type,...)
internal use only, for allocating internal types for performance
Definition ZFMemPool.h:37
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define ZFTokenForKeyValueContainerDefault()
see ZFTokenForKeyValueContainer, modifyable, ZFTokenForKeyValueContainerTrim by default
Definition ZFToken.h:214
light weight array
Definition ZFCoreArray.h:348
core map type for private use only
Definition ZFCoreMap.h:101
void refDelete(void)
delete reference
Definition ZFCoreMap.h:150
void set(const T_Key &key, const T_Value &value)
change value or create if not exist, value would be retained by this method
Definition ZFCoreMap.h:298
void swap(ZFCoreMap< T_Key, T_Value > &ref)
swap internal data
Definition ZFCoreMap.h:222
void removeAll(void)
remove all content
Definition ZFCoreMap.h:383
ZFCompareResult objectCompareValue(ZFCoreMap< T_Key, T_Value > const &ref) const
compare by instance
Definition ZFCoreMap.h:176
T_Value & access(const T_Key &key)
access value or create if not exist
Definition ZFCoreMap.h:332
zfiter iterAdd(const T_Key &key, const T_Value &value)
see zfiter
Definition ZFCoreMap.h:432
ZFCompareResult objectCompare(ZFCoreMap< T_Key, T_Value > const &ref) const
compare by instance
Definition ZFCoreMap.h:172
void iterRemove(zfiter &it)
see zfiter
Definition ZFCoreMap.h:425
void copyFrom(const ZFCoreMap< T_Key, T_Value > &ref)
copy all contents from ref, remove all before copy
Definition ZFCoreMap.h:234
ZFCoreMap(void)
construct an empty map
Definition ZFCoreMap.h:106
zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
return contents info
Definition ZFCoreMap.h:209
ZFCoreArray< T_Key > allKey(void) const
return a copy of all keys
Definition ZFCoreMap.h:348
zfstring objectInfo(void) const
return object info
Definition ZFCoreMap.h:166
void refPrepare(void)
prepare instance to make it able to be shared between each copy
Definition ZFCoreMap.h:146
void remove(const T_Key &key)
remove or do nothing if not exist
Definition ZFCoreMap.h:374
const T_Value * get(const T_Key &key) const
get value or null if not exist
Definition ZFCoreMap.h:308
T_Value * get(const T_Key &key)
get value or null if not exist
Definition ZFCoreMap.h:320
void iterValue(zfiter &it, const T_Value &value)
see zfiter
Definition ZFCoreMap.h:416
ZFCoreMap(const ZFCoreMap< T_Key, T_Value > &ref)
retain the ref, to copy, use copyFrom
Definition ZFCoreMap.h:110
zfindex count(void) const
return count
Definition ZFCoreMap.h:257
zfiter iterFind(const T_Key &key) const
see zfiter
Definition ZFCoreMap.h:398
void addFrom(const ZFCoreMap< T_Key, T_Value > &ref)
add elements from ref
Definition ZFCoreMap.h:278
const T_Value & iterValue(const zfiter &it) const
see zfiter
Definition ZFCoreMap.h:407
void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFCoreMap.h:162
void allKeyT(ZFCoreArray< T_Key > &ret) const
see allKey
Definition ZFCoreMap.h:338
void allValueT(ZFCoreArray< T_Value > &ret) const
see allValue
Definition ZFCoreMap.h:355
void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
see objectInfoOfContent
Definition ZFCoreMap.h:197
zfiter iter(void) const
see zfiter
Definition ZFCoreMap.h:393
T_Value & iterValue(const zfiter &it)
see zfiter
Definition ZFCoreMap.h:412
ZFCoreArray< T_Value > allValue(void) const
return a copy of all values
Definition ZFCoreMap.h:365
const T_Key & iterKey(const zfiter &it) const
see zfiter
Definition ZFCoreMap.h:403
zfbool isEmpty(void) const
true if empty
Definition ZFCoreMap.h:264
zfbool isContain(const T_Key &key) const
true if contains the key
Definition ZFCoreMap.h:271
default key equal function
Definition ZFCoreMap.h:86
default key hash function
Definition ZFCoreMap.h:77
util class to hold string tokens
Definition ZFToken.h:113
iterator for ZFFramework
Definition zfiter.h:40