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

Last change on this file was 18, checked in by chronos, 12 years ago
  • Used external packages are now stored in uncompressed form rather in zipped files. This allow better package version synchronisation.
File size: 2.2 KB
Line 
1{$IFDEF INTERFACE}
2
3{$DEFINE TGListIndex := TGQueueIndex}
4{$DEFINE TGListItem := TGQueueItem}
5{$DEFINE TGList := TGQueueList}
6{$DEFINE TGListSortCompare := TGQueueSortCompare}
7{$DEFINE TGListToStringConverter := TGQueueToStringConverter}
8{$DEFINE TGListFromStringConverter := TGQueueFromStringConverter}
9{$DEFINE TGListItemArray := TGQueueItemArray}
10{$DEFINE INTERFACE}
11{$I 'GenericList.inc'}
12
13 // TGQueue<TQueueIndex, TQueueItem> = class(TGList)
14 TGQueue = class
15 private
16 FList: TGList;
17 function GetCount: TGQueueIndex;
18 public
19 procedure Enqueue(Value: TGQueueItem);
20 procedure EnqueueArray(Values: array of TGQueueItem);
21 procedure EnqueueList(List: TGList);
22 function Dequeue: TGQueueItem;
23 function Peek: TGQueueItem;
24 constructor Create;
25 destructor Destroy; override;
26 property List: TGList read FList;
27 property Count: TGQueueIndex read GetCount;
28 end;
29
30{$UNDEF INTERFACE}
31{$ENDIF}
32
33{$IFDEF IMPLEMENTATION_USES}
34
35 {$DEFINE IMPLEMENTATION_USES}
36 {$I 'GenericList.inc'}
37
38{$UNDEF IMPLEMENTATION_USES}
39{$ENDIF}
40
41{$IFDEF IMPLEMENTATION}
42
43{$DEFINE TGListIndex := TGQueueIndex}
44{$DEFINE TGListItem := TGQueueItem}
45{$DEFINE TGList := TGQueueList}
46{$DEFINE TGListSortCompare := TGQueueSortCompare}
47{$DEFINE TGListToStringConverter := TGQueueToStringConverter}
48{$DEFINE TGListFromStringConverter := TGQueueFromStringConverter}
49{$DEFINE TGListItemArray := TGQueueItemArray}
50{$DEFINE IMPLEMENTATION}
51{$I 'GenericList.inc'}
52
53{ TGQueue }
54
55procedure TGQueue.Enqueue(Value: TGQueueItem);
56begin
57 FList.Add(Value);
58end;
59
60procedure TGQueue.EnqueueArray(Values: array of TGQueueItem);
61begin
62 FList.AddArray(Values);
63end;
64
65procedure TGQueue.EnqueueList(List: TGList);
66begin
67 FList.AddList(List);
68end;
69
70function TGQueue.Peek: TGQueueItem;
71begin
72 Result := FList.First;
73end;
74
75constructor TGQueue.Create;
76begin
77 FList := TGList.Create;
78end;
79
80destructor TGQueue.Destroy;
81begin
82 FList.Free;
83 inherited Destroy;
84end;
85
86function TGQueue.Dequeue: TGQueueItem;
87begin
88 Result := FList.Extract(FList.First);
89end;
90
91function TGQueue.GetCount: TGQueueIndex;
92begin
93 Result := FList.Count;
94end;
95
96{$UNDEF IMPLEMENTATION}
97{$ENDIF}
Note: See TracBrowser for help on using the repository browser.