source: branches/AS8051toC/Packages/TemplateGenerics/Specialized/SpecializedList.pas

Last change on this file was 26, checked in by chronos, 12 years ago
  • Upraveno: Překlad rozdělen do fáze zpracování maker a druhé fáze zpracování instrukcí.
File size: 9.0 KB
Line 
1unit SpecializedList;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils;
9
10type
11{$MACRO ON}
12
13// TListInteger<Integer, Integer>
14{$DEFINE TGListIndex := Integer}
15{$DEFINE TGListItem := Integer}
16{$DEFINE TGList := TListInteger}
17{$DEFINE INTERFACE}
18{$I 'GenericList.inc'}
19
20// TListBoolean<Integer, Boolean>
21{$DEFINE TGListIndex := Integer}
22{$DEFINE TGListItem := Boolean}
23{$DEFINE TGList := TListBoolean}
24{$DEFINE INTERFACE}
25{$I 'GenericList.inc'}
26
27// TListSmallInt<Integer, SmallInt>
28{$DEFINE TGListIndex := Integer}
29{$DEFINE TGListItem := SmallInt}
30{$DEFINE TGList := TListSmallInt}
31{$DEFINE INTERFACE}
32{$I 'GenericList.inc'}
33
34// TListDouble<Integer, Double>
35{$DEFINE TGListIndex := Integer}
36{$DEFINE TGListItem := Double}
37{$DEFINE TGList := TListDouble}
38{$DEFINE INTERFACE}
39{$INCLUDE '..\Generic\GenericList.inc'}
40
41// TListPointer<Integer, Pointer>
42{$DEFINE TGListIndex := Integer}
43{$DEFINE TGListItem := Pointer}
44{$DEFINE TGList := TListPointer}
45{$DEFINE INTERFACE}
46{$I 'GenericList.inc'}
47
48// TListString<Integer, string>
49{$DEFINE TGListStringIndex := Integer}
50{$DEFINE TGListStringItem := string}
51{$DEFINE TGListString := TListString}
52{$DEFINE INTERFACE}
53{$I 'GenericListString.inc'}
54
55// TListByte<Integer, Byte>
56{$DEFINE TGListIndex := Integer}
57{$DEFINE TGListItem := Byte}
58{$DEFINE TGList := TListByteBase}
59{$DEFINE INTERFACE}
60{$I 'GenericList.inc'}
61
62TListByte = class(TListByteBase)
63 procedure WriteToStream(Stream: TStream);
64 procedure WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
65 procedure ReplaceStream(Stream: TStream);
66 procedure ReplaceStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
67 procedure AddStream(Stream: TStream);
68 procedure AddStreamPart(Stream: TStream; ItemCount: TGListIndex);
69 procedure WriteBuffer(var Buffer; Count: Integer);
70 procedure ReadBuffer(var Buffer; Count: Integer);
71end;
72
73// TListChar<Integer, Char>
74{$DEFINE TGListIndex := Integer}
75{$DEFINE TGListItem := Char}
76{$DEFINE TGList := TListCharBase}
77{$DEFINE INTERFACE}
78{$I 'GenericList.inc'}
79
80// TListObject<Integer, TObject>
81{$DEFINE TGListObjectIndex := Integer}
82{$DEFINE TGListObjectItem := TObject}
83{$DEFINE TGListObjectList := TListObjectList}
84{$DEFINE TGListObject := TListObject}
85{$DEFINE INTERFACE}
86{$I 'GenericListObject.inc'}
87
88
89{ TListChar }
90
91// TListByte<Integer, Char>
92TListChar = class(TListCharBase)
93 procedure UpperCase;
94 procedure LowerCase;
95 procedure Trim;
96 procedure TrimLeft;
97 procedure TrimRight;
98end;
99
100// TListMethodBase<Integer, TMethod>
101{$DEFINE TGListIndex := Integer}
102{$DEFINE TGListItem := TMethod}
103{$DEFINE TGList := TListMethodBase}
104{$DEFINE INTERFACE}
105{$I 'GenericList.inc'}
106
107// TListMethod<Integer, TMethod>
108TListMethod = class(TListMethodBase)
109 procedure CallAll;
110end;
111
112// TListNotifyEventBase<Integer, TNotifyEvent>
113{$DEFINE TGListIndex := Integer}
114{$DEFINE TGListItem := TNotifyEvent}
115{$DEFINE TGList := TListNotifyEventBase}
116{$DEFINE INTERFACE}
117{$I 'GenericList.inc'}
118
119// TListNotifyEvent<Integer, TNotifyEvent>
120TListNotifyEvent = class(TListNotifyEventBase)
121 procedure CallAll(Sender: TObject);
122end;
123
124
125TBaseEvent = procedure of object;
126
127// TListSimpleEventBase<Integer, TBaseEvent>
128{$DEFINE TGListIndex := Integer}
129{$DEFINE TGListItem := TBaseEvent}
130{$DEFINE TGList := TListSimpleEventBase}
131{$DEFINE INTERFACE}
132{$I 'GenericList.inc'}
133
134// TListSimpleEvent<Integer, TSimpleEvent>
135TListSimpleEvent = class(TListSimpleEventBase)
136 procedure CallAll;
137end;
138
139
140// TFileListByte<Integer, Byte>
141{$DEFINE TGFileListIndex := Integer}
142{$DEFINE TGFileListItem := Byte}
143{$DEFINE TGFileListList := TFileListListByte}
144{$DEFINE TGFileList := TFileListByte}
145{$DEFINE INTERFACE}
146{$I 'GenericFileList.inc'}
147
148function StrToStr(Value: string): string;
149
150
151
152
153
154implementation
155
156{$DEFINE IMPLEMENTATION_USES}
157{$I 'GenericList.inc'}
158
159// TListInteger<Integer, Integer>
160{$DEFINE TGListIndex := Integer}
161{$DEFINE TGListItem := Integer}
162{$DEFINE TGList := TListInteger}
163{$DEFINE IMPLEMENTATION}
164{$I 'GenericList.inc'}
165
166// TListSmallInt<Integer, SmallInt>
167{$DEFINE TGListIndex := Integer}
168{$DEFINE TGListItem := SmallInt}
169{$DEFINE TGList := TListSmallInt}
170{$DEFINE IMPLEMENTATION}
171{$I 'GenericList.inc'}
172
173// TListBoolean<Integer, Boolean>
174{$DEFINE TGListIndex := Integer}
175{$DEFINE TGListItem := Boolean}
176{$DEFINE TGList := TListBoolean}
177{$DEFINE IMPLEMENTATION}
178{$I 'GenericList.inc'}
179
180// TListDouble<Integer, Double>
181{$DEFINE TGListIndex := Integer}
182{$DEFINE TGListItem := Double}
183{$DEFINE TGList := TListDouble}
184{$DEFINE IMPLEMENTATION}
185{$I 'GenericList.inc'}
186
187// TListPointer<Integer, Pointer>
188{$DEFINE TGListIndex := Integer}
189{$DEFINE TGListItem := Pointer}
190{$DEFINE TGList := TListPointer}
191{$DEFINE IMPLEMENTATION}
192{$I 'GenericList.inc'}
193
194// TListString<Integer, string>
195{$DEFINE TGListStringIndex := Integer}
196{$DEFINE TGListStringItem := string}
197{$DEFINE TGListString := TListString}
198{$DEFINE IMPLEMENTATION}
199{$I 'GenericListString.inc'}
200
201// TListByte<Integer, Byte>
202{$DEFINE TGListIndex := Integer}
203{$DEFINE TGListItem := Byte}
204{$DEFINE TGList := TListByteBase}
205{$DEFINE IMPLEMENTATION}
206{$I 'GenericList.inc'}
207
208// TListByte<Integer, Char>
209{$DEFINE TGListIndex := Integer}
210{$DEFINE TGListItem := Char}
211{$DEFINE TGList := TListCharBase}
212{$DEFINE IMPLEMENTATION}
213{$I 'GenericList.inc'}
214
215// TListObject<Integer, TObject>
216{$DEFINE TGListObjectIndex := Integer}
217{$DEFINE TGListObjectItem := TObject}
218{$DEFINE TGListObjectList := TListObjectList}
219{$DEFINE TGListObject := TListObject}
220{$DEFINE IMPLEMENTATION}
221{$I 'GenericListObject.inc'}
222
223// TListMethod<Integer, TMethod>
224{$DEFINE TGListIndex := Integer}
225{$DEFINE TGListItem := TMethod}
226{$DEFINE TGList := TListMethodBase}
227{$DEFINE IMPLEMENTATION}
228{$I 'GenericList.inc'}
229
230// TListNotifyEventBase<Integer, TNotifyEvent>
231{$DEFINE TGListIndex := Integer}
232{$DEFINE TGListItem := TNotifyEvent}
233{$DEFINE TGList := TListNotifyEventBase}
234{$DEFINE IMPLEMENTATION}
235{$I 'GenericList.inc'}
236
237// TListSimpleEventBase<Integer, TBaseEvent>
238{$DEFINE TGListIndex := Integer}
239{$DEFINE TGListItem := TBaseEvent}
240{$DEFINE TGList := TListSimpleEventBase}
241{$DEFINE IMPLEMENTATION}
242{$I 'GenericList.inc'}
243
244// TFileListByte<Integer, Byte>
245{$DEFINE TGFileListIndex := Integer}
246{$DEFINE TGFileListItem := Byte}
247{$DEFINE TGFileListList := TFileListListByte}
248{$DEFINE TGFileList := TFileListByte}
249{$DEFINE IMPLEMENTATION}
250{$I 'GenericFileList.inc'}
251
252
253function StrToStr(Value: string): string;
254begin
255 Result := Value;
256end;
257
258{ TListSimpleEvent }
259
260procedure TListSimpleEvent.CallAll;
261var
262 I: TGListIndex;
263begin
264 I := 0;
265 while (I < Count) do begin
266 TBaseEvent(Items[I])();
267 I := I + 1;
268 end;
269end;
270
271
272{ TListChar }
273
274procedure TListChar.UpperCase;
275var
276 I: TGListIndex;
277begin
278 for I := 0 to Count - 1 do
279 if (FItems[I] in ['a'..'z']) then
280 FItems[I] := Char(Byte(FItems[I]) - 32);
281end;
282
283procedure TListChar.LowerCase;
284var
285 I: TGListIndex;
286begin
287 for I := 0 to Count - 1 do
288 if (FItems[I] in ['A'..'Z']) then
289 FItems[I] := Char(Byte(FItems[I]) + 32);
290end;
291
292procedure TListChar.Trim;
293begin
294 TrimLeft;
295 TrimRight;
296end;
297
298procedure TListChar.TrimLeft;
299var
300 I: TGListIndex;
301begin
302 I := 0;
303 while (I < Count) and (FItems[I] = ' ') do
304 I := I + 1;
305 if I < Count then
306 DeleteItems(0, I);
307end;
308
309procedure TListChar.TrimRight;
310var
311 I: TGListIndex;
312begin
313 I := Count - 1;
314 while (I >= 0) and (FItems[I] = ' ') do
315 I := I - 1;
316 if I >= 0 then
317 DeleteItems(I + 1, Count - I - 1);
318end;
319
320procedure TListMethod.CallAll;
321var
322 I: TGListIndex;
323begin
324 I := 0;
325 while (I < Count) do begin
326 Items[I];
327 I := I + 1;
328 end;
329end;
330
331procedure TListNotifyEvent.CallAll(Sender: TObject);
332var
333 I: TGListIndex;
334begin
335 I := 0;
336 while (I < Count) do begin
337 TNotifyEvent(Items[I])(Sender);
338 I := I + 1;
339 end;
340end;
341
342{ TListByte }
343
344procedure TListByte.WriteToStream(Stream: TStream);
345var
346 I: Integer;
347begin
348 Stream.Position := 0;
349 I := 0;
350 while I < Count do begin
351 Stream.WriteByte(Items[I]);
352 I := I + 1;
353 end;
354end;
355
356procedure TListByte.WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
357var
358 I: Integer;
359begin
360 I := ItemIndex;
361 while I < ItemCount do begin
362 Stream.WriteByte(Items[I]);
363 I := I + 1;
364 end;
365end;
366
367procedure TListByte.ReplaceStream(Stream: TStream);
368var
369 I: Integer;
370begin
371 Stream.Position := 0;
372 I := 0;
373 while I < Count do begin
374 Items[I] := Stream.ReadByte;
375 I := I + 1;
376 end;
377end;
378
379procedure TListByte.ReplaceStreamPart(Stream: TStream; ItemIndex,
380 ItemCount: Integer);
381var
382 I: Integer;
383begin
384 I := ItemIndex;
385 while I < ItemCount do begin
386 Items[I] := Stream.ReadByte;
387 I := I + 1;
388 end;
389end;
390
391procedure TListByte.AddStream(Stream: TStream);
392var
393 I: Integer;
394begin
395 Stream.Position := 0;
396 I := Count;
397 Count := Count + Stream.Size;
398 while I < Count do begin
399 Items[I] := Stream.ReadByte;
400 I := I + 1;
401 end;
402end;
403
404procedure TListByte.AddStreamPart(Stream: TStream; ItemCount: Integer);
405var
406 I: Integer;
407begin
408 I := Count;
409 Count := Count + ItemCount;
410 while I < Count do begin
411 Items[I] := Stream.ReadByte;
412 I := I + 1;
413 end;
414end;
415
416procedure TListByte.WriteBuffer(var Buffer; Count: Integer);
417begin
418
419end;
420
421procedure TListByte.ReadBuffer(var Buffer; Count: Integer);
422begin
423
424end;
425
426
427end.
Note: See TracBrowser for help on using the repository browser.