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 zfstlless
15 #define zfstlless std::less
16#endif
17
19#ifndef zfstlmap
20 #define zfstlmap std::map
21#endif
22
23// ============================================================
25template<typename T_Key, typename T_Value, typename T_Compare = zfstlless<T_Key> >
27private:
29 public:
30 typename zfimplmap<T_Key, T_Value, T_Compare>::iterator it;
31 typename zfimplmap<T_Key, T_Value, T_Compare>::iterator end;
32 public:
34 virtual zfbool valid(void) {
35 return it != end;
36 }
38 virtual void next(void) {
39 ++it;
40 }
42 virtual Impl *copy(void) {
43 _Iter *ret = zfpoolNew(_Iter);
44 ret->it = it;
45 ret->end = end;
46 return ret;
47 }
49 virtual void destroy(void) {
50 zfpoolDelete(this);
51 }
53 virtual zfbool isEqual(ZF_IN Impl *d) {
54 _Iter *t = (_Iter *)d;
55 return it == t->it;
56 }
57 };
58
59public:
60 zffinal inline zfiter iter(void) {
61 _Iter *impl = zfpoolNew(_Iter);
62 impl->it = this->begin();
63 impl->end = this->end();
64 return zfiter(impl);
65 }
66
67 zffinal inline zfiter iterFind(ZF_IN T_Key const &key) {
68 _Iter *impl = zfpoolNew(_Iter);
69 impl->it = this->find(key);
70 impl->end = this->end();
71 return zfiter(impl);
72 }
73
74 zffinal inline T_Key const &iterKey(ZF_IN const zfiter &it) {
75 return it.impl<_Iter *>()->it->first;
76 }
77 zffinal inline T_Value &iterValue(ZF_IN const zfiter &it) {
78 return it.impl<_Iter *>()->it->second;
79 }
80
81 zffinal inline void iterValue(
83 , ZF_IN T_Value const &newValue
84 ) {
85 it.impl<_Iter *>()->it->second = newValue;
86 }
87 zffinal inline void iterRemove(ZF_IN_OUT zfiter &it) {
88 this->erase((it.impl<_Iter *>()->it)++);
89 }
90
91 zffinal inline zfiter iterAdd(
92 ZF_IN T_Key const &key
93 , ZF_IN T_Value const &value
94 ) {
95 _Iter *impl = zfpoolNew(_Iter);
96 impl->it = this->insert(zfstlpair<T_Key, T_Value>(key, value)).first;
97 impl->end = this->end();
98 return zfiter(impl);
99 }
100};
102
103#endif // #ifndef _ZFI_zfstlmap_h_
104
#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 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:196
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:212
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zfpoolDelete(obj)
see zfnew
Definition ZFMemPool.h:81
#define zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:80
see zfiter
Definition zfiter.h:84
iterator for ZFFramework
Definition zfiter.h:40
#define zfstlmap
stl wrapper
Definition zfstlmap.h:20
stl wrapper, note it's internal use only
#define zfstlpair
stl wrapper
Definition zfstlpair.h:15