-
Notifications
You must be signed in to change notification settings - Fork 2
/
frmiterator.cpp
152 lines (131 loc) · 3.56 KB
/
frmiterator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iterator>
#include "parser.h"
#define ITMPL typename iterator_type, typename reference_type, typename iterator_type_const, typename reference_type_const, typename iterator_type_nonconst, typename reference_type_nonconst
#define ITPAR iterator_type, reference_type, iterator_type_const, reference_type_const, iterator_type_nonconst, reference_type_nonconst
#define ITPAR_CONST iterator_type_const, reference_type_const, iterator_type_const, reference_type_const, iterator_type_nonconst, reference_type_nonconst
template<ITMPL>
frmiterator<ITPAR>::frmiterator(void) :
wildcard(NULL),
curnum(0)
{
return;
}
template<ITMPL>
frmiterator<ITPAR>::frmiterator(const fldformat *iwildcard, iterator_type iit, iterator_type ibegin, iterator_type iend, int icurnum) :
wildcard(iwildcard),
it(iit),
next(iit==iend?iend:++iit),
begin(ibegin),
end(iend),
curnum(icurnum)
{
while(it!=end && it->first<0)
++it;
return;
}
template<ITMPL>
frmiterator<ITPAR>::frmiterator(const frmiterator &it) :
tmpmap(it.tmpmap),
wildcard(it.wildcard),
it(it.it),
next(it.next),
begin(it.begin),
end(it.end),
curnum(it.curnum)
{
return;
}
template<ITMPL>
frmiterator<ITPAR>::frmiterator(const std::map<int,fldformat> &i_tmpmap, const fldformat *i_wildcard, const iterator_type &i_it, const iterator_type &i_next, const iterator_type &i_begin, const iterator_type &i_end, int i_curnum) :
tmpmap(i_tmpmap),
wildcard(i_wildcard),
it(i_it),
next(i_next),
begin(i_begin),
end(i_end),
curnum(i_curnum)
{
return;
}
template<ITMPL>
frmiterator<ITPAR>::~frmiterator(void)
{
return;
}
template<ITMPL>
frmiterator<ITPAR>& frmiterator<ITPAR>::operator=(const frmiterator<ITPAR> &other)
{
wildcard=other.wildcard;
it=other.it;
next=other.next;
begin=other.begin;
end=other.end;
tmpmap=other.tmpmap;
curnum=other.curnum;
return *this;
}
template<ITMPL>
bool frmiterator<ITPAR>::operator!=(frmiterator<ITPAR> const &other) const
{
return !(*this==other);//it!=other.it || curnum!=other.curnum;
}
template<ITMPL>
bool frmiterator<ITPAR>::operator==(frmiterator<ITPAR> const &other) const
{
return it==other.it && curnum==other.curnum;
}
template<ITMPL>
reference_type& frmiterator<ITPAR>::operator*(void)
{
return *this->operator->();
}
template<ITMPL>
reference_type* frmiterator<ITPAR>::operator->(void)
{
if(!wildcard || (it!=end && (it->first==curnum || curnum<0)))
return it.operator->();
else
{
tmpmap[curnum]=*wildcard; //construct a temporary map of the missing references
return tmpmap.find(curnum).operator->();
}
}
template<ITMPL>
frmiterator<ITPAR>& frmiterator<ITPAR>::operator++(void)
{
if(!wildcard)
{
++it;
return *this;
}
++curnum;
if(next!=end && curnum==next->first)
{
it=next;
++next;
}
return *this;
}
template<ITMPL>
frmiterator<ITPAR>& frmiterator<ITPAR>::operator--(void)
{
if(!wildcard)
{
--it;
return *this;
}
if(it!=end && curnum==it->first)
{
next=it;
--it;
}
--curnum;
return *this;
}
template<ITMPL>
frmiterator<ITPAR>::operator frmiterator<ITPAR_CONST>(void) const
{
return frmiterator<ITPAR_CONST>(tmpmap, wildcard, it, next, begin, end, curnum);
}
template class frmiterator<std::map<int,fldformat>::iterator, std::pair<const int, fldformat>, std::map<int,fldformat>::const_iterator, const std::pair<const int, fldformat>, std::map<int,fldformat>::iterator, std::pair<const int, fldformat> >;
template class frmiterator<std::map<int,fldformat>::const_iterator, const std::pair<const int, fldformat>, std::map<int,fldformat>::const_iterator, const std::pair<const int, fldformat>, std::map<int,fldformat>::iterator, std::pair<const int, fldformat> >;