forked from Nexusoft/PrimeSoloMiner
-
Notifications
You must be signed in to change notification settings - Fork 4
/
enumerator.h
131 lines (105 loc) · 2.6 KB
/
enumerator.h
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
#ifndef _FRM_ENUMERATOR_H
#define _FRM_ENUMERATOR_H
template <class T>
class CEnumerateByValue
{
typedef struct __wraper__
{
struct __wraper__ *next, *prev;
T ptr;
}WRAPER, *LPWRAPER;
CLinkedListByValue<T> *liste;
LPWRAPER actWraper;
public:
CEnumerateByValue(CLinkedListByValue<T> *list)
{
this->liste = list;
this->actWraper = (LPWRAPER)this->liste->firstElement;
}
~CEnumerateByValue()
{
}
void Reset()
{
this->actWraper = (LPWRAPER)this->liste->firstElement;
}
T GetActValue()
{
if(actWraper == NULL)
return (T)0;
return actWraper->ptr;
}
bool SetToNextElement()
{
if(actWraper == NULL)
return false;
actWraper = actWraper->next;
return true;
}
bool SetToPrevElement()
{
if(actWraper == NULL)
return false;
actWraper = actWraper->prev;
return true;
}
bool IsCurrentValidValue()
{
if(actWraper == NULL)
return false;
return true;
}
};
template <class T>
class CEnumerateByRef
{
typedef struct __wraper__
{
struct __wraper__ *next, *prev;
T* ptr;
}WRAPER, *LPWRAPER;
CLinkedListByRef<T> *liste;
LPWRAPER actWraper;
public:
CEnumerateByRef(CLinkedListByRef<T> *list)
{
this->liste = list;
this->actWraper = (LPWRAPER)this->liste->firstElement;
}
~CEnumerateByRef()
{
}
void Reset()
{
this->actWraper = (LPWRAPER)this->liste->firstElement;
}
T* GetActValue()
{
if(actWraper == NULL)
return NULL;
return actWraper->ptr;
}
bool SetToNextElement()
{
if(actWraper == NULL)
return false;
actWraper = actWraper->next;
return true;
}
bool SetToPrevElement()
{
if(actWraper == NULL)
return false;
actWraper = actWraper->prev;
return true;
}
bool IsCurrentValidValue()
{
if(actWraper == NULL)
return false;
return true;
}
};
#define FOREACH_REF(type, pointer, list) for(bool __int__oneTimeLoop__=true;__int__oneTimeLoop__;)for(CEnumerateByRef<type> __int__enMine__(&(list));__int__oneTimeLoop__;__int__oneTimeLoop__=false)for(type* pointer=__int__enMine__.GetActValue();__int__enMine__.IsCurrentValidValue() && pointer != NULL;__int__enMine__.SetToNextElement(),pointer=__int__enMine__.GetActValue())
#define FOREACH_VALUE(type, valName, list) for(bool __int__oneTimeLoop__=true;__int__oneTimeLoop__;)for(CEnumerateByValue<type> __int__enMine__(&(list));__int__oneTimeLoop__;__int__oneTimeLoop__=false)for(type valName=__int__enMine__.GetActValue();__int__enMine__.IsCurrentValidValue();__int__enMine__.SetToNextElement(),valName=__int__enMine__.GetActValue())
#endif