-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDGLIntf.inc_pas
221 lines (180 loc) · 5.55 KB
/
DGLIntf.inc_pas
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//------------------------------------------------------------------------------
// Copyright (c) 2004
// Delhi泛型库--DGL(The Delphi Generic Library)
// Author: HouSisong
//------------------------------------------------------------------------------
// DGL库中的接口(interface)的声明的实现
// Create by HouSisong, 2005.10.12
//------------------------------------------------------------------------------
//DGLIntf.inc_h
//DGLIntf.inc_pas
{$ifndef __DGLIntf_inc_pas_}
{$define __DGLIntf_inc_pas_}
{$ifndef _DGL_Compare}
function _IsEqual(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
begin
result:=(Value0=Value1);
end;
function _IsLess(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
begin
result:=(Value0<Value1);
end;
{$endif}
{$ifndef _DGL_Compare_Value}
function _IsEqual_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
begin
result:=(Value0=Value1);
end;
function _IsLess_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
begin
result:=(Value0<Value1);
end;
{$endif}
{ _TAbstractIterator }
class function _TAbstractIterator.Distance(const SelfItData:_IIterator;const Iterator: _IIterator): integer;
var
It :_IIterator;
begin
It:=SelfItData;
result:=0;
while (not self.IsEqual(It,Iterator)) do
begin
inc(result);
self.Next(It);
end;
end;
class function _TAbstractIterator.GetNextValue(const SelfItData:_IIterator;const Step:integer): _ValueType;
var
It: _IIterator;
begin
It:=SelfItData;
self.Next(It,Step);
result:=self.GetValue(It);
end;
class procedure _TAbstractIterator.SetNextValue(const SelfItData:_IIterator;const Step:integer;const aValue:_ValueType);var
It: _IIterator;
begin
It:=SelfItData;
Self.Next(It,Step);
Self.SetValue(It,aValue);
end;
class procedure _TAbstractIterator.Next(var SelfItData:_IIterator;const Step: integer);
var
i : integer;
begin
if Step>=0 then
for i:=0 to Step-1 do self.Next(SelfItData)
else
for i:=0 to (-Step)-1 do self.Previous(SelfItData);
end;
class function _TAbstractIterator.Clone(const SelfItData:_IIterator;const NextStep:integer):_IIterator;
begin
result:=SelfItData;
self.Next(result,NextStep);
end;
class function _TAbstractIterator.Clone(const SelfItData:_IIterator):_IIterator;
begin
result:=SelfItData;
end;
class procedure _TAbstractIterator.Assign(var SelfItData:_IIterator;const Iterator: _IIterator);
begin
SelfItData:=Iterator;
end;
class procedure _TAbstractIterator.ItCreate(var SelfItData:_IIterator;const AIterator: _IIterator);
begin
SelfItData:=AIterator;
end;
class procedure _TAbstractIterator.ItCreate(var SelfItData:_IIterator);
begin
SelfItData.SetIteratorNil();
end;
class function _TAbstractIterator.IteratorTraits():TIteratorTraits;
begin
result:=itTrivialTag;
end;
{ _IMapIterator }
function _IMapIterator.GetKey(): _KeyType;
begin
result:=self._ObjIteratorClass.Map_GetKey(self);
end;
{ _IIterator }
procedure _IIterator.Assign(const Iterator: _IIterator);
begin
self:=Iterator;
end;
function _IIterator.Clone: _IIterator;
begin
result:=self;
end;
function _IIterator.Clone(const NextStep: integer): _IIterator;
begin
result:=self;
result._ObjIteratorClass.Next(result,NextStep);
end;
function _IIterator.Distance(const Iterator: _IIterator): integer;
begin
result:=self._ObjIteratorClass.Distance(self,Iterator);
end;
function _IIterator.GetNextValue(const Step: integer): _ValueType;
begin
result:=self._ObjIteratorClass.GetNextValue(self,Step);
end;
function _IIterator.GetValue: _ValueType;
begin
result:=self._ObjIteratorClass.GetValue(self);
end;
function _IIterator.IsEqual(const Iterator: _IIterator): boolean;
begin
result:=self._ObjIteratorClass.IsEqual(self,Iterator);
end;
procedure _IIterator.Next(const Step: integer);
begin
self._ObjIteratorClass.Next(self,Step);
end;
procedure _IIterator.Next;
begin
self._ObjIteratorClass.Next(self);
end;
procedure _IIterator.Previous;
begin
self._ObjIteratorClass.Previous(self);
end;
procedure _IIterator.SetNextValue(const Step: integer;const aValue: _ValueType);
begin
self._ObjIteratorClass.SetNextValue(self,Step,aValue);
end;
procedure _IIterator.SetIteratorNil;
begin
self._ObjIteratorClass:=nil;
self._Data0:=0;
self._Data1:=0;
self._Data2:=0;
end;
procedure _IIterator.SetValue(const aValue: _ValueType);
begin
self._ObjIteratorClass.SetValue(self,aValue);
end;
function _IIterator.IteratorTraits():TIteratorTraits;
begin
result:=_ObjIteratorClass.IteratorTraits();
end;
constructor _TEnumerator.Create(Container: _IContainer);
begin
FContainer := Container;
FIterator := Container.ItBegin;
end;
function _TEnumerator.GetCurrent: _ValueType;
begin
Result := FIterator.Value;
end;
function _TEnumerator.MoveNext: Boolean;
begin
FIterator.Next;
Result := not FIterator.IsEqual(FContainer.ItEnd);
end;
function _TInterfacedObject.GetEnumerator: _TEnumerator;
begin
Result := _TEnumerator.Create(_IContainer(_IEnumerator(Self)));
end;
{$endif } // __DGLIntf_inc_pas_