source: Generics/NativeGenerics/Generic/GenericQueue.pas

Last change on this file was 496, checked in by chronos, 7 years ago
  • Modified: New native generics classes working under FPC 3.0 transformed from TemplateGenerics package.
File size: 1.2 KB
Line 
1unit GenericQueue;
2
3{$mode delphi}
4
5interface
6
7uses
8 GenericList;
9
10type
11 TGQueue<T> = class
12 private
13 FList: TGList<T>;
14 function GetCount: Integer;
15 public
16 procedure Enqueue(Value: T);
17 procedure EnqueueArray(Values: array of T);
18 procedure EnqueueList(List: TGList<T>);
19 function Dequeue: T;
20 function Peek: T;
21 constructor Create;
22 destructor Destroy; override;
23 property List: TGList<T> read FList;
24 property Count: Integer read GetCount;
25 end;
26
27
28implementation
29
30{ TGQueue }
31
32procedure TGQueue<T>.Enqueue(Value: T);
33begin
34 FList.Add(Value);
35end;
36
37procedure TGQueue<T>.EnqueueArray(Values: array of T);
38begin
39 FList.AddArray(Values);
40end;
41
42procedure TGQueue<T>.EnqueueList(List: TGList<T>);
43begin
44 FList.AddList(List);
45end;
46
47function TGQueue<T>.Peek: T;
48begin
49 Result := FList.First;
50end;
51
52constructor TGQueue<T>.Create;
53begin
54 FList := TGList<T>.Create;
55end;
56
57destructor TGQueue<T>.Destroy;
58begin
59 FList.Free;
60 inherited Destroy;
61end;
62
63function TGQueue<T>.Dequeue: T;
64begin
65 Result := FList.Extract(FList.First);
66end;
67
68function TGQueue<T>.GetCount: Integer;
69begin
70 Result := FList.Count;
71end;
72
73end.
Note: See TracBrowser for help on using the repository browser.