source: trunk/Packages/TemplateGenerics/Generic/GenericQueue.inc

Last change on this file was 6, checked in by chronos, 10 years ago
  • Added: Now opened projects are remembered between application restarts.
  • Added: Show basic list of files in selected project.
  • Added: Packages Common and TemplateGenerics.
File size: 1.7 KB
Line 
1{$IFDEF INTERFACE}
2
3{$DEFINE TGListIndex := TGQueueIndex}
4{$DEFINE TGListItem := TGQueueItem}
5{$DEFINE TGList := TGQueueList}
6{$DEFINE INTERFACE}
7{$I 'GenericList.inc'}
8
9 // TGQueue<TQueueIndex, TQueueItem> = class(TGList)
10 TGQueue = class
11 private
12 FList: TGList;
13 function GetCount: TGQueueIndex;
14 public
15 procedure Enqueue(Value: TGQueueItem);
16 procedure EnqueueArray(Values: array of TGQueueItem);
17 procedure EnqueueList(List: TGList);
18 function Dequeue: TGQueueItem;
19 function Peek: TGQueueItem;
20 constructor Create;
21 destructor Destroy; override;
22 property List: TGList read FList;
23 property Count: TGQueueIndex read GetCount;
24 end;
25
26{$UNDEF INTERFACE}
27{$ENDIF}
28
29{$IFDEF IMPLEMENTATION_USES}
30
31 {$DEFINE IMPLEMENTATION_USES}
32 {$I 'GenericList.inc'}
33
34{$UNDEF IMPLEMENTATION_USES}
35{$ENDIF}
36
37{$IFDEF IMPLEMENTATION}
38
39{$DEFINE TGListIndex := TGQueueIndex}
40{$DEFINE TGListItem := TGQueueItem}
41{$DEFINE TGList := TGQueueList}
42{$DEFINE IMPLEMENTATION}
43{$I 'GenericList.inc'}
44
45{ TGQueue }
46
47procedure TGQueue.Enqueue(Value: TGQueueItem);
48begin
49 FList.Add(Value);
50end;
51
52procedure TGQueue.EnqueueArray(Values: array of TGQueueItem);
53begin
54 FList.AddArray(Values);
55end;
56
57procedure TGQueue.EnqueueList(List: TGList);
58begin
59 FList.AddList(List);
60end;
61
62function TGQueue.Peek: TGQueueItem;
63begin
64 Result := FList.First;
65end;
66
67constructor TGQueue.Create;
68begin
69 FList := TGList.Create;
70end;
71
72destructor TGQueue.Destroy;
73begin
74 FList.Free;
75 inherited Destroy;
76end;
77
78function TGQueue.Dequeue: TGQueueItem;
79begin
80 Result := FList.Extract(FList.First);
81end;
82
83function TGQueue.GetCount: TGQueueIndex;
84begin
85 Result := FList.Count;
86end;
87
88{$UNDEF IMPLEMENTATION}
89{$ENDIF}
Note: See TracBrowser for help on using the repository browser.