6#ifndef _ZFI_ZFCoreMap_h_
7#define _ZFI_ZFCoreMap_h_
19 virtual ~_ZFP_ZFCoreMapKey(
void) {}
24 virtual _ZFP_ZFCoreMapKey *implCopy(
void)
const zfpurevirtual;
29 virtual ~_ZFP_ZFCoreMapValue(
void) {}
34 virtual _ZFP_ZFCoreMapValue *implCopy(
void)
const zfpurevirtual;
39 typedef _ZFP_ZFCoreMapValue *(*Fn_ValueCreate)(void);
43 static _ZFP_ZFCoreMap *create(
void);
44 static void destroy(
ZF_IN _ZFP_ZFCoreMap *d);
45 _ZFP_ZFCoreMap(
void) : refCount(1) {}
46 virtual ~_ZFP_ZFCoreMap(
void) {}
48 virtual void objectInfoOfContentT(
62 virtual _ZFP_ZFCoreMapValue *access(
ZF_IN _ZFP_ZFCoreMapKey *key,
ZF_IN Fn_ValueCreate fn_ValueCreate)
zfpurevirtual;
77template<
typename T_Key>
86template<
typename T_Key>
101template<
typename T_Key,
typename T_Value,
typename T_Hash = ZFCoreMapKeyHash<T_Key>,
typename T_Equal = ZFCoreMapKeyEqual<T_Key> >
123 _ZFP_ZFCoreMap *dTmp = d;
128 if(dTmp && (--(dTmp->refCount)) == 0) {
129 _ZFP_ZFCoreMap::destroy(dTmp);
142 if(d && (--(d->refCount)) == 0) {
143 _ZFP_ZFCoreMap::destroy(d);
156 _ZFP_ZFCoreMap *dTmp = d;
158 if(--(dTmp->refCount) == 0) {
183 return d->objectCompareValue(ref.d);
206 ret += token.tokenLeft;
208 d->objectInfoOfContentT(ret, maxCount, token);
210 ret += token.tokenRight;
228 _ZFP_ZFCoreMap *dTmp = d;
270 return d ? d->count() : 0;
277 return !d || d->isEmpty();
284 return d && d->isContain(_KeyCreate(key));
311 ZF_IN const T_Key &key
312 ,
ZF_IN const T_Value &value
315 d->set(_KeyCreate(key), _ValueCreate(value));
322 ImplValue *value = (ImplValue *)d->get(_KeyCreate(key));
334 ImplValue *value = (ImplValue *)d->get(_KeyCreate(key));
346 return ((ImplValue *)d->access(_KeyCreate(key), _ValueCreate))->v;
352 for(
zfiter it = d->iter(); it; ++it) {
353 ret.add(((
const ImplKey *)d->iterKey(it))->v);
369 for(
zfiter it = d->iter(); it; ++it) {
370 ret.add(((
const ImplValue *)d->iterValue(it))->v);
388 d->remove(_KeyCreate(key));
406 return d ? d->iter() :
zfiter();
411 return d ? d->iterFind(_KeyCreate(key)) :
zfiter();
416 return ((
const ImplKey *)d->iterKey(it))->v;
420 return ((
const ImplValue *)d->iterValue(it))->v;
425 return ((ImplValue *)d->iterValue(it))->v;
430 ,
ZF_IN const T_Value &value
433 d->iterValue(it, _ValueCreate(value));
445 ZF_IN const T_Key &key
446 ,
ZF_IN const T_Value &value
449 return d->iterAdd(_KeyCreate(key), _ValueCreate(value));
454 return d->iterAccess(it, _KeyCreate(key), _ValueCreate);
461 ImplKey(
ZF_IN T_Key
const &v) : v(v) {}
463 virtual zfidentity implHash(
void)
const {
return T_Hash()(v);}
464 virtual zfbool implEqual(
ZF_IN const _ZFP_ZFCoreMapKey *ref)
const {
return T_Equal()(v, ((ImplKey *)ref)->v);}
466 virtual _ZFP_ZFCoreMapKey *implCopy(
void)
const {
return zfpoolNew(ImplKey, v);}
472 ImplValue(
void) : v() {}
473 ImplValue(
ZF_IN T_Value
const &v) : v(v) {}
475 virtual void implCopy(
ZF_IN const _ZFP_ZFCoreMapValue *ref) {v = ((ImplValue *)ref)->v;}
478 virtual _ZFP_ZFCoreMapValue *implCopy(
void)
const {
return zfpoolNew(ImplValue, v);}
481 static _ZFP_ZFCoreMapKey *_KeyCreate(
ZF_IN T_Key
const &v) {
484 static _ZFP_ZFCoreMapValue *_ValueCreate(
ZF_IN T_Value
const &v) {
487 static _ZFP_ZFCoreMapValue *_ValueCreate(
void) {
492 inline void _dInit(
void) {
494 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:198
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:202
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:206
#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:214
_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 zfnew
Definition ZFMemPool.h:63
#define zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:62
#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:297
core map type for private use only
Definition ZFCoreMap.h:102
void refDelete(void)
delete reference
Definition ZFCoreMap.h:154
void addFrom(const zfself &ref)
add elements from ref
Definition ZFCoreMap.h:290
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:310
void copyFrom(const zfself &ref)
copy all contents from ref, remove all before copy
Definition ZFCoreMap.h:238
void removeAll(void)
remove all content
Definition ZFCoreMap.h:395
ZFCompareResult objectCompare(zfself 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:344
zfiter iterAdd(const T_Key &key, const T_Value &value)
see zfiter
Definition ZFCoreMap.h:444
void iterRemove(zfiter &it)
see zfiter
Definition ZFCoreMap.h:437
ZFCoreMap(void)
construct an empty map
Definition ZFCoreMap.h:110
zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
return contents info
Definition ZFCoreMap.h:213
ZFCoreArray< T_Key > allKey(void) const
return a copy of all keys
Definition ZFCoreMap.h:360
zfstring objectInfo(void) const
return object info
Definition ZFCoreMap.h:170
void remove(const T_Key &key)
remove or do nothing if not exist
Definition ZFCoreMap.h:386
void capacity(zfindex capacity)
change capacity
Definition ZFCoreMap.h:261
const T_Value * get(const T_Key &key) const
get value or null if not exist
Definition ZFCoreMap.h:320
T_Value * get(const T_Key &key)
get value or null if not exist
Definition ZFCoreMap.h:332
zfbool iterAccess(zfiter &it, const T_Key &key)
return true if already exist, or false and insert <key, defValue> if not exist
Definition ZFCoreMap.h:452
void iterValue(zfiter &it, const T_Value &value)
see zfiter
Definition ZFCoreMap.h:428
zfindex count(void) const
return count
Definition ZFCoreMap.h:269
zfself & refPrepare(void)
prepare instance to make it able to be shared between each copy
Definition ZFCoreMap.h:150
ZFCoreMap< T_Key, T_Value, T_Hash, T_Equal > zfself
typedef for self
Definition ZFCoreMap.h:105
zfiter iterFind(const T_Key &key) const
see zfiter
Definition ZFCoreMap.h:410
const T_Value & iterValue(const zfiter &it) const
see zfiter
Definition ZFCoreMap.h:419
void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFCoreMap.h:166
void swap(zfself &ref)
swap internal data
Definition ZFCoreMap.h:226
void allKeyT(ZFCoreArray< T_Key > &ret) const
see allKey
Definition ZFCoreMap.h:350
void allValueT(ZFCoreArray< T_Value > &ret) const
see allValue
Definition ZFCoreMap.h:367
void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForKeyValueContainer &token=_ZFP_ZFTokenForKeyValueContainerDefault) const
Definition ZFCoreMap.h:201
ZFCoreMap(const zfself &ref)
retain the ref, to copy, use copyFrom
Definition ZFCoreMap.h:114
ZFCompareResult objectCompareValue(zfself const &ref) const
compare by instance
Definition ZFCoreMap.h:180
zfiter iter(void) const
see zfiter
Definition ZFCoreMap.h:405
T_Value & iterValue(const zfiter &it)
see zfiter
Definition ZFCoreMap.h:424
ZFCoreArray< T_Value > allValue(void) const
return a copy of all values
Definition ZFCoreMap.h:377
const T_Key & iterKey(const zfiter &it) const
see zfiter
Definition ZFCoreMap.h:415
zfbool isEmpty(void) const
true if empty
Definition ZFCoreMap.h:276
zfbool isContain(const T_Key &key) const
true if contains the key
Definition ZFCoreMap.h:283
default key equal function
Definition ZFCoreMap.h:87
default key hash function
Definition ZFCoreMap.h:78
util class to hold string tokens
Definition ZFToken.h:113
iterator for ZFFramework
Definition zfiter.h:40