-
Notifications
You must be signed in to change notification settings - Fork 2
/
StringSuperList.pas
241 lines (199 loc) · 6.19 KB
/
StringSuperList.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
{*
StringSuperList.pas
-------------------
Begin: 2005/09/01
Last revision: $Date: 2009-08-26 16:54:47 $ $Author: rhupalo $
Version number: $Revision: 1.5 $
Code Documentation Tags: Begin 2009-08-26, Last Revision: 2009-08-26
Project: APHI General Purpose Delphi Library
Website: http://www.naadsm.org/opensource/delphi
Author: Aaron Reeves <Aaron.Reeves@colostate.edu>
--------------------------------------------------
Copyright (C) 2005 - 2009 Animal Population Health Institute, Colorado State University
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
}
(*
Documentation generation tags begin with {* or ///
Replacing these with (* or // foils the documentation generator
*)
unit StringSuperList;
interface
uses
Contnrs,
Classes
;
type
/// A list for holding stringlists
TStringSuperList = class( TObjectList )
protected
_currentIndex: integer; /// Index of current string list
function getCurrentIndex(): integer;
function getIsEmpty(): boolean;
procedure setObject( index: integer; item: TStringList );
function getObject( index: integer ): TStringList;
public
constructor create();
destructor destroy(); override;
function first(): TStringList;
function last(): TStringList;
function next(): TStringList;
function current(): TStringList;
function at( index: integer ): TStringList;
function append( dm: TStringList ): integer;
procedure insert( index: integer; dm: TStringList );
/// Returns the stringlist at position index or adds one at this position
property objects[ index: integer]: TStringList read getObject write setObject; default;
/// Returns the current position (index) in the list
property currentPosition: integer read getCurrentIndex;
/// Returns true if the super list contains no lists, else false
property isEmpty: boolean read getIsEmpty;
end
;
implementation
//-----------------------------------------------------------------------------
// Construction/destruction
//-----------------------------------------------------------------------------
/// Creates an empty super list
constructor TStringSuperList.create();
begin
inherited create( true );
end
;
/// Deletes the super list and releases resources
destructor TStringSuperList.destroy();
begin
inherited destroy();
end
;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Typical list functions
//-----------------------------------------------------------------------------
{*
Returns the stringlist index at the current position in the super list
@return Index of current stringlist
}
function TStringSuperList.getCurrentIndex(): integer;
begin
result := _currentIndex;
end
;
{*
To check whether the super list contains any stringlists
@return True if the super list is empty esle false
}
function TStringSuperList.getIsEmpty(): boolean;
begin
result := (0 = self.Count );
end
;
{*
Adds a stringlist to the super list
@param dm The stringlist to add
@return The index of the new item
}
function TStringSuperList.append( dm: TStringList ): integer;
begin
result := inherited Add( dm );
end
;
{*
Inserts item at position index in the super list
@param index Postion at which item should be inserted
@param item Stringlist to insert
}
procedure TStringSuperList.setObject( index: integer; item: TStringList );
begin
inherited SetItem( index, item );
end
;
{*
Returns stringlist at position index in the super list
@param index of stringlist to be retrieved
@return Stringlist object at position index
}
function TStringSuperList.getObject( index: integer ): TStringList;
begin
result := inherited GetItem( index ) as TStringList;
end
;
{*
Returns stringlist at position index in the super list
@param index of stringlist to be retrieved
@return Stringlist object at position index
}
function TStringSuperList.at( index: integer ): TStringList;
begin
result := inherited GetItem( index ) as TStringList;
end
;
{*
Inserts dm at position index in the super list
@param index Postion at which item should be inserted
@param item Stringlist to insert
}
procedure TStringSuperList.insert(index: integer; dm: TStringList);
begin
inherited Insert(index, dm);
end
;
{*
Returns stringlist at the first position in the super list
@return Stringlist object at index 0
}
function TStringSuperList.first() : TStringList;
begin
_currentIndex := 0;
if( self.Count = 0 ) then
result := nil
else
result := getObject( _currentIndex )
;
end
;
{*
Returns stringlist at the last position in the super list
@return Stringlist object at bottom of super list
}
function TStringSuperList.last() : TStringList;
begin
if( self.Count = 0 ) then result := nil
else
begin
_currentIndex := self.Count - 1;
result := getObject( _currentIndex );
end
;
end
;
{*
Returns stringlist at the next position in the super list
@return Stringlist object at position current + 1
}
function TStringSuperList.next() : TStringList;
begin
_currentIndex := _currentIndex + 1;
if( _currentIndex > (self.Count - 1) ) then
result := nil
else
result := getObject( _currentIndex )
;
end
;
{*
Returns stringlist at the current position in the super list
@return Current stringlist object
}
function TStringSuperList.current() : TStringList;
begin
if( _currentIndex > (self.Count - 1) ) then
result := nil
else
result := getObject( _currentIndex )
;
end
;
//-----------------------------------------------------------------------------
end.