forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsppStack.pas
113 lines (84 loc) · 1.9 KB
/
IsppStack.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
{
Inno Setup Preprocessor
Copyright (C) 2001-2002 Alex Yackimoff
Inno Setup
Copyright (C) 1997-2020 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
}
unit IsppStack;
interface
uses Classes;
type
{ Borrowed from Delphi 5 Contnrs unit }
{ TOrdered class }
TOrderedList = class(TObject)
private
FList: TList;
protected
procedure PushItem(AItem: Pointer); virtual; abstract;
function PopItem: Pointer; virtual;
function PeekItem: Pointer; virtual;
property List: TList read FList;
public
constructor Create;
destructor Destroy; override;
function Count: Integer;
function AtLeast(ACount: Integer): Boolean;
procedure Push(AItem: Pointer);
function Pop: Pointer;
function Peek: Pointer;
end;
{ TStack class }
TStack = class(TOrderedList)
protected
procedure PushItem(AItem: Pointer); override;
end;
implementation
uses IsppConsts;
{ TOrderedList }
function TOrderedList.AtLeast(ACount: integer): boolean;
begin
Result := List.Count >= ACount;
end;
function TOrderedList.Peek: Pointer;
begin
Result := PeekItem;
end;
function TOrderedList.Pop: Pointer;
begin
Result := PopItem;
end;
procedure TOrderedList.Push(AItem: Pointer);
begin
PushItem(AItem);
end;
function TOrderedList.Count: Integer;
begin
Result := List.Count;
end;
constructor TOrderedList.Create;
begin
inherited Create;
FList := TList.Create;
end;
destructor TOrderedList.Destroy;
begin
List.Free;
inherited Destroy;
end;
function TOrderedList.PeekItem: Pointer;
begin
Result := List[List.Count-1];
end;
function TOrderedList.PopItem: Pointer;
begin
Result := PeekItem;
List.Delete(List.Count-1);
end;
{ TStack }
procedure TStack.PushItem(AItem: Pointer);
begin
List.Add(AItem);
end;
end.