ZFFramework
 
Loading...
Searching...
No Matches
zfstlmap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfstlmap_h_
7#define _ZFI_zfstlmap_h_
8
9#include "zfstlpair.h"
10#include <map>
11
12// ============================================================
14#ifndef zfstlmap
15 #define zfstlmap std::map
16#endif
17
19#ifndef zfstlless
20 #define zfstlless std::less
21#endif
22
23
24// ============================================================
26template<typename T_Key, typename T_Value, typename T_Compare = zfstlless<T_Key> >
27class zfimplmap : public zfstlmap<T_Key, T_Value, T_Compare> {
28private:
30 public:
31 typename zfimplmap<T_Key, T_Value, T_Compare>::iterator it;
32 typename zfimplmap<T_Key, T_Value, T_Compare>::iterator end;
33 public:
35 virtual zfbool valid(void) {
36 return it != end;
37 }
39 virtual void next(void) {
40 ++it;
41 }
43 virtual Impl *copy(void) {
44 _Iter *ret = zfpoolNew(_Iter);
45 ret->it = it;
46 ret->end = end;
47 return ret;
48 }
50 virtual void destroy(void) {
51 zfpoolDelete(this);
52 }
54 virtual zfbool isEqual(ZF_IN Impl *d) {
55 _Iter *t = (_Iter *)d;
56 return it == t->it;
57 }
58 };
59
60public:
61 zffinal inline zfiter iter(void) {
62 _Iter *impl = zfpoolNew(_Iter);
63 impl->it = this->begin();
64 impl->end = this->end();
65 return zfiter(impl);
66 }
67
68 zffinal inline zfiter iterFind(ZF_IN T_Key const &key) {
69 _Iter *impl = zfpoolNew(_Iter);
70 impl->it = this->find(key);
71 impl->end = this->end();
72 return zfiter(impl);
73 }
74
75 zffinal inline T_Key const &iterKey(ZF_IN const zfiter &it) {
76 return it.impl<_Iter *>()->it->first;
77 }
78 zffinal inline T_Value &iterValue(ZF_IN const zfiter &it) {
79 return it.impl<_Iter *>()->it->second;
80 }
81
82 zffinal inline void iterValue(
84 , ZF_IN T_Value const &newValue
85 ) {
86 it.impl<_Iter *>()->it->second = newValue;
87 }
88 zffinal inline void iterRemove(ZF_IN_OUT zfiter &it) {
89 this->erase((it.impl<_Iter *>()->it)++);
90 }
91
92 zffinal inline void iterAdd(
93 ZF_IN T_Key const &key
94 , ZF_IN T_Value const &value
95 ) {
96 this->insert(zfstlpair<T_Key, T_Value>(key, value));
97 }
98};
100
101#endif // #ifndef _ZFI_zfstlmap_h_
102
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#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
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#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
see zfiter
Definition zfiter.h:84
iterator for ZFFramework
Definition zfiter.h:40
#define zfstlmap
stl wrapper
Definition zfstlmap.h:15
stl wrapper, note it's internal use only
#define zfstlpair
stl wrapper
Definition zfstlpair.h:15