| 1 | unit SpecializedList;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | {$MACRO ON}
|
|---|
| 12 |
|
|---|
| 13 | // TListInteger<Integer, Integer>
|
|---|
| 14 | {$DEFINE TGListIndex := Integer}
|
|---|
| 15 | {$DEFINE TGListItem := Integer}
|
|---|
| 16 | {$DEFINE TGList := TListInteger}
|
|---|
| 17 | {$DEFINE INTERFACE}
|
|---|
| 18 | {$I 'GenericList.inc'}
|
|---|
| 19 |
|
|---|
| 20 | // TListBoolean<Integer, Boolean>
|
|---|
| 21 | {$DEFINE TGListIndex := Integer}
|
|---|
| 22 | {$DEFINE TGListItem := Boolean}
|
|---|
| 23 | {$DEFINE TGList := TListBoolean}
|
|---|
| 24 | {$DEFINE INTERFACE}
|
|---|
| 25 | {$I 'GenericList.inc'}
|
|---|
| 26 |
|
|---|
| 27 | // TListSmallInt<Integer, SmallInt>
|
|---|
| 28 | {$DEFINE TGListIndex := Integer}
|
|---|
| 29 | {$DEFINE TGListItem := SmallInt}
|
|---|
| 30 | {$DEFINE TGList := TListSmallInt}
|
|---|
| 31 | {$DEFINE INTERFACE}
|
|---|
| 32 | {$I 'GenericList.inc'}
|
|---|
| 33 |
|
|---|
| 34 | // TListDouble<Integer, Double>
|
|---|
| 35 | {$DEFINE TGListIndex := Integer}
|
|---|
| 36 | {$DEFINE TGListItem := Double}
|
|---|
| 37 | {$DEFINE TGList := TListDouble}
|
|---|
| 38 | {$DEFINE INTERFACE}
|
|---|
| 39 | {$INCLUDE '..\Generic\GenericList.inc'}
|
|---|
| 40 |
|
|---|
| 41 | // TListPointer<Integer, Pointer>
|
|---|
| 42 | {$DEFINE TGListIndex := Integer}
|
|---|
| 43 | {$DEFINE TGListItem := Pointer}
|
|---|
| 44 | {$DEFINE TGList := TListPointer}
|
|---|
| 45 | {$DEFINE INTERFACE}
|
|---|
| 46 | {$I 'GenericList.inc'}
|
|---|
| 47 |
|
|---|
| 48 | // TListString<Integer, string>
|
|---|
| 49 | {$DEFINE TGListStringIndex := Integer}
|
|---|
| 50 | {$DEFINE TGListStringItem := string}
|
|---|
| 51 | {$DEFINE TGListString := TListString}
|
|---|
| 52 | {$DEFINE INTERFACE}
|
|---|
| 53 | {$I 'GenericListString.inc'}
|
|---|
| 54 |
|
|---|
| 55 | // TListByte<Integer, Byte>
|
|---|
| 56 | {$DEFINE TGListIndex := Integer}
|
|---|
| 57 | {$DEFINE TGListItem := Byte}
|
|---|
| 58 | {$DEFINE TGList := TListByteBase}
|
|---|
| 59 | {$DEFINE INTERFACE}
|
|---|
| 60 | {$I 'GenericList.inc'}
|
|---|
| 61 |
|
|---|
| 62 | TListByte = class(TListByteBase)
|
|---|
| 63 | procedure WriteToStream(Stream: TStream);
|
|---|
| 64 | procedure WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
|
|---|
| 65 | procedure ReplaceStream(Stream: TStream);
|
|---|
| 66 | procedure ReplaceStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
|
|---|
| 67 | procedure AddStream(Stream: TStream);
|
|---|
| 68 | procedure AddStreamPart(Stream: TStream; ItemCount: TGListIndex);
|
|---|
| 69 | end;
|
|---|
| 70 |
|
|---|
| 71 | // TListChar<Integer, Char>
|
|---|
| 72 | {$DEFINE TGListIndex := Integer}
|
|---|
| 73 | {$DEFINE TGListItem := Char}
|
|---|
| 74 | {$DEFINE TGList := TListCharBase}
|
|---|
| 75 | {$DEFINE INTERFACE}
|
|---|
| 76 | {$I 'GenericList.inc'}
|
|---|
| 77 |
|
|---|
| 78 | // TListObject<Integer, TObject>
|
|---|
| 79 | {$DEFINE TGListObjectIndex := Integer}
|
|---|
| 80 | {$DEFINE TGListObjectItem := TObject}
|
|---|
| 81 | {$DEFINE TGListObjectList := TListObjectList}
|
|---|
| 82 | {$DEFINE TGListObject := TListObject}
|
|---|
| 83 | {$DEFINE INTERFACE}
|
|---|
| 84 | {$I 'GenericListObject.inc'}
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | { TListChar }
|
|---|
| 88 |
|
|---|
| 89 | // TListByte<Integer, Char>
|
|---|
| 90 | TListChar = class(TListCharBase)
|
|---|
| 91 | procedure UpperCase;
|
|---|
| 92 | procedure LowerCase;
|
|---|
| 93 | procedure Trim;
|
|---|
| 94 | procedure TrimLeft;
|
|---|
| 95 | procedure TrimRight;
|
|---|
| 96 | end;
|
|---|
| 97 |
|
|---|
| 98 | // TListMethodBase<Integer, TMethod>
|
|---|
| 99 | {$DEFINE TGListIndex := Integer}
|
|---|
| 100 | {$DEFINE TGListItem := TMethod}
|
|---|
| 101 | {$DEFINE TGList := TListMethodBase}
|
|---|
| 102 | {$DEFINE INTERFACE}
|
|---|
| 103 | {$I 'GenericList.inc'}
|
|---|
| 104 |
|
|---|
| 105 | // TListMethod<Integer, TMethod>
|
|---|
| 106 | TListMethod = class(TListMethodBase)
|
|---|
| 107 | procedure CallAll;
|
|---|
| 108 | end;
|
|---|
| 109 |
|
|---|
| 110 | // TListNotifyEventBase<Integer, TNotifyEvent>
|
|---|
| 111 | {$DEFINE TGListIndex := Integer}
|
|---|
| 112 | {$DEFINE TGListItem := TNotifyEvent}
|
|---|
| 113 | {$DEFINE TGList := TListNotifyEventBase}
|
|---|
| 114 | {$DEFINE INTERFACE}
|
|---|
| 115 | {$I 'GenericList.inc'}
|
|---|
| 116 |
|
|---|
| 117 | // TListNotifyEvent<Integer, TNotifyEvent>
|
|---|
| 118 | TListNotifyEvent = class(TListNotifyEventBase)
|
|---|
| 119 | procedure CallAll(Sender: TObject);
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | TBaseEvent = procedure of object;
|
|---|
| 124 |
|
|---|
| 125 | // TListSimpleEventBase<Integer, TBaseEvent>
|
|---|
| 126 | {$DEFINE TGListIndex := Integer}
|
|---|
| 127 | {$DEFINE TGListItem := TBaseEvent}
|
|---|
| 128 | {$DEFINE TGList := TListSimpleEventBase}
|
|---|
| 129 | {$DEFINE INTERFACE}
|
|---|
| 130 | {$I 'GenericList.inc'}
|
|---|
| 131 |
|
|---|
| 132 | // TListSimpleEvent<Integer, TSimpleEvent>
|
|---|
| 133 | TListSimpleEvent = class(TListSimpleEventBase)
|
|---|
| 134 | procedure CallAll;
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | // TFileListByte<Integer, Byte>
|
|---|
| 139 | {$DEFINE TGFileListIndex := Integer}
|
|---|
| 140 | {$DEFINE TGFileListItem := Byte}
|
|---|
| 141 | {$DEFINE TGFileListList := TFileListListByte}
|
|---|
| 142 | {$DEFINE TGFileList := TFileListByte}
|
|---|
| 143 | {$DEFINE INTERFACE}
|
|---|
| 144 | {$I 'GenericFileList.inc'}
|
|---|
| 145 |
|
|---|
| 146 | function StrToStr(Value: string): string;
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | implementation
|
|---|
| 153 |
|
|---|
| 154 | {$DEFINE IMPLEMENTATION_USES}
|
|---|
| 155 | {$I 'GenericList.inc'}
|
|---|
| 156 |
|
|---|
| 157 | // TListInteger<Integer, Integer>
|
|---|
| 158 | {$DEFINE TGListIndex := Integer}
|
|---|
| 159 | {$DEFINE TGListItem := Integer}
|
|---|
| 160 | {$DEFINE TGList := TListInteger}
|
|---|
| 161 | {$DEFINE IMPLEMENTATION}
|
|---|
| 162 | {$I 'GenericList.inc'}
|
|---|
| 163 |
|
|---|
| 164 | // TListSmallInt<Integer, SmallInt>
|
|---|
| 165 | {$DEFINE TGListIndex := Integer}
|
|---|
| 166 | {$DEFINE TGListItem := SmallInt}
|
|---|
| 167 | {$DEFINE TGList := TListSmallInt}
|
|---|
| 168 | {$DEFINE IMPLEMENTATION}
|
|---|
| 169 | {$I 'GenericList.inc'}
|
|---|
| 170 |
|
|---|
| 171 | // TListBoolean<Integer, Boolean>
|
|---|
| 172 | {$DEFINE TGListIndex := Integer}
|
|---|
| 173 | {$DEFINE TGListItem := Boolean}
|
|---|
| 174 | {$DEFINE TGList := TListBoolean}
|
|---|
| 175 | {$DEFINE IMPLEMENTATION}
|
|---|
| 176 | {$I 'GenericList.inc'}
|
|---|
| 177 |
|
|---|
| 178 | // TListDouble<Integer, Double>
|
|---|
| 179 | {$DEFINE TGListIndex := Integer}
|
|---|
| 180 | {$DEFINE TGListItem := Double}
|
|---|
| 181 | {$DEFINE TGList := TListDouble}
|
|---|
| 182 | {$DEFINE IMPLEMENTATION}
|
|---|
| 183 | {$I 'GenericList.inc'}
|
|---|
| 184 |
|
|---|
| 185 | // TListPointer<Integer, Pointer>
|
|---|
| 186 | {$DEFINE TGListIndex := Integer}
|
|---|
| 187 | {$DEFINE TGListItem := Pointer}
|
|---|
| 188 | {$DEFINE TGList := TListPointer}
|
|---|
| 189 | {$DEFINE IMPLEMENTATION}
|
|---|
| 190 | {$I 'GenericList.inc'}
|
|---|
| 191 |
|
|---|
| 192 | // TListString<Integer, string>
|
|---|
| 193 | {$DEFINE TGListStringIndex := Integer}
|
|---|
| 194 | {$DEFINE TGListStringItem := string}
|
|---|
| 195 | {$DEFINE TGListString := TListString}
|
|---|
| 196 | {$DEFINE IMPLEMENTATION}
|
|---|
| 197 | {$I 'GenericListString.inc'}
|
|---|
| 198 |
|
|---|
| 199 | // TListByte<Integer, Byte>
|
|---|
| 200 | {$DEFINE TGListIndex := Integer}
|
|---|
| 201 | {$DEFINE TGListItem := Byte}
|
|---|
| 202 | {$DEFINE TGList := TListByteBase}
|
|---|
| 203 | {$DEFINE IMPLEMENTATION}
|
|---|
| 204 | {$I 'GenericList.inc'}
|
|---|
| 205 |
|
|---|
| 206 | // TListByte<Integer, Char>
|
|---|
| 207 | {$DEFINE TGListIndex := Integer}
|
|---|
| 208 | {$DEFINE TGListItem := Char}
|
|---|
| 209 | {$DEFINE TGList := TListCharBase}
|
|---|
| 210 | {$DEFINE IMPLEMENTATION}
|
|---|
| 211 | {$I 'GenericList.inc'}
|
|---|
| 212 |
|
|---|
| 213 | // TListObject<Integer, TObject>
|
|---|
| 214 | {$DEFINE TGListObjectIndex := Integer}
|
|---|
| 215 | {$DEFINE TGListObjectItem := TObject}
|
|---|
| 216 | {$DEFINE TGListObjectList := TListObjectList}
|
|---|
| 217 | {$DEFINE TGListObject := TListObject}
|
|---|
| 218 | {$DEFINE IMPLEMENTATION}
|
|---|
| 219 | {$I 'GenericListObject.inc'}
|
|---|
| 220 |
|
|---|
| 221 | // TListMethod<Integer, TMethod>
|
|---|
| 222 | {$DEFINE TGListIndex := Integer}
|
|---|
| 223 | {$DEFINE TGListItem := TMethod}
|
|---|
| 224 | {$DEFINE TGList := TListMethodBase}
|
|---|
| 225 | {$DEFINE IMPLEMENTATION}
|
|---|
| 226 | {$I 'GenericList.inc'}
|
|---|
| 227 |
|
|---|
| 228 | // TListNotifyEventBase<Integer, TNotifyEvent>
|
|---|
| 229 | {$DEFINE TGListIndex := Integer}
|
|---|
| 230 | {$DEFINE TGListItem := TNotifyEvent}
|
|---|
| 231 | {$DEFINE TGList := TListNotifyEventBase}
|
|---|
| 232 | {$DEFINE IMPLEMENTATION}
|
|---|
| 233 | {$I 'GenericList.inc'}
|
|---|
| 234 |
|
|---|
| 235 | // TListSimpleEventBase<Integer, TBaseEvent>
|
|---|
| 236 | {$DEFINE TGListIndex := Integer}
|
|---|
| 237 | {$DEFINE TGListItem := TBaseEvent}
|
|---|
| 238 | {$DEFINE TGList := TListSimpleEventBase}
|
|---|
| 239 | {$DEFINE IMPLEMENTATION}
|
|---|
| 240 | {$I 'GenericList.inc'}
|
|---|
| 241 |
|
|---|
| 242 | // TFileListByte<Integer, Byte>
|
|---|
| 243 | {$DEFINE TGFileListIndex := Integer}
|
|---|
| 244 | {$DEFINE TGFileListItem := Byte}
|
|---|
| 245 | {$DEFINE TGFileListList := TFileListListByte}
|
|---|
| 246 | {$DEFINE TGFileList := TFileListByte}
|
|---|
| 247 | {$DEFINE IMPLEMENTATION}
|
|---|
| 248 | {$I 'GenericFileList.inc'}
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 | function StrToStr(Value: string): string;
|
|---|
| 252 | begin
|
|---|
| 253 | Result := Value;
|
|---|
| 254 | end;
|
|---|
| 255 |
|
|---|
| 256 | { TListSimpleEvent }
|
|---|
| 257 |
|
|---|
| 258 | procedure TListSimpleEvent.CallAll;
|
|---|
| 259 | var
|
|---|
| 260 | I: TGListIndex;
|
|---|
| 261 | begin
|
|---|
| 262 | I := 0;
|
|---|
| 263 | while (I < Count) do begin
|
|---|
| 264 | TBaseEvent(Items[I])();
|
|---|
| 265 | I := I + 1;
|
|---|
| 266 | end;
|
|---|
| 267 | end;
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 | { TListChar }
|
|---|
| 271 |
|
|---|
| 272 | procedure TListChar.UpperCase;
|
|---|
| 273 | var
|
|---|
| 274 | I: TGListIndex;
|
|---|
| 275 | begin
|
|---|
| 276 | for I := 0 to Count - 1 do
|
|---|
| 277 | if (FItems[I] in ['a'..'z']) then
|
|---|
| 278 | FItems[I] := Char(Byte(FItems[I]) - 32);
|
|---|
| 279 | end;
|
|---|
| 280 |
|
|---|
| 281 | procedure TListChar.LowerCase;
|
|---|
| 282 | var
|
|---|
| 283 | I: TGListIndex;
|
|---|
| 284 | begin
|
|---|
| 285 | for I := 0 to Count - 1 do
|
|---|
| 286 | if (FItems[I] in ['A'..'Z']) then
|
|---|
| 287 | FItems[I] := Char(Byte(FItems[I]) + 32);
|
|---|
| 288 | end;
|
|---|
| 289 |
|
|---|
| 290 | procedure TListChar.Trim;
|
|---|
| 291 | begin
|
|---|
| 292 | TrimLeft;
|
|---|
| 293 | TrimRight;
|
|---|
| 294 | end;
|
|---|
| 295 |
|
|---|
| 296 | procedure TListChar.TrimLeft;
|
|---|
| 297 | var
|
|---|
| 298 | I: TGListIndex;
|
|---|
| 299 | begin
|
|---|
| 300 | I := 0;
|
|---|
| 301 | while (I < Count) and (FItems[I] = ' ') do
|
|---|
| 302 | I := I + 1;
|
|---|
| 303 | if I < Count then
|
|---|
| 304 | DeleteItems(0, I);
|
|---|
| 305 | end;
|
|---|
| 306 |
|
|---|
| 307 | procedure TListChar.TrimRight;
|
|---|
| 308 | var
|
|---|
| 309 | I: TGListIndex;
|
|---|
| 310 | begin
|
|---|
| 311 | I := Count - 1;
|
|---|
| 312 | while (I >= 0) and (FItems[I] = ' ') do
|
|---|
| 313 | I := I - 1;
|
|---|
| 314 | if I >= 0 then
|
|---|
| 315 | DeleteItems(I + 1, Count - I - 1);
|
|---|
| 316 | end;
|
|---|
| 317 |
|
|---|
| 318 | procedure TListMethod.CallAll;
|
|---|
| 319 | var
|
|---|
| 320 | I: TGListIndex;
|
|---|
| 321 | begin
|
|---|
| 322 | I := 0;
|
|---|
| 323 | while (I < Count) do begin
|
|---|
| 324 | Items[I];
|
|---|
| 325 | I := I + 1;
|
|---|
| 326 | end;
|
|---|
| 327 | end;
|
|---|
| 328 |
|
|---|
| 329 | procedure TListNotifyEvent.CallAll(Sender: TObject);
|
|---|
| 330 | var
|
|---|
| 331 | I: TGListIndex;
|
|---|
| 332 | begin
|
|---|
| 333 | I := Count - 1;
|
|---|
| 334 | while (I >= 0) do begin
|
|---|
| 335 | TNotifyEvent(Items[I])(Sender);
|
|---|
| 336 | I := I - 1;
|
|---|
| 337 | end;
|
|---|
| 338 | end;
|
|---|
| 339 |
|
|---|
| 340 | { TListByte }
|
|---|
| 341 |
|
|---|
| 342 | procedure TListByte.WriteToStream(Stream: TStream);
|
|---|
| 343 | var
|
|---|
| 344 | I: Integer;
|
|---|
| 345 | begin
|
|---|
| 346 | Stream.Position := 0;
|
|---|
| 347 | I := 0;
|
|---|
| 348 | while I < Count do begin
|
|---|
| 349 | Stream.WriteByte(Items[I]);
|
|---|
| 350 | I := I + 1;
|
|---|
| 351 | end;
|
|---|
| 352 | end;
|
|---|
| 353 |
|
|---|
| 354 | procedure TListByte.WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
|
|---|
| 355 | var
|
|---|
| 356 | I: Integer;
|
|---|
| 357 | begin
|
|---|
| 358 | I := ItemIndex;
|
|---|
| 359 | while I < ItemCount do begin
|
|---|
| 360 | Stream.WriteByte(Items[I]);
|
|---|
| 361 | I := I + 1;
|
|---|
| 362 | end;
|
|---|
| 363 | end;
|
|---|
| 364 |
|
|---|
| 365 | procedure TListByte.ReplaceStream(Stream: TStream);
|
|---|
| 366 | var
|
|---|
| 367 | I: Integer;
|
|---|
| 368 | begin
|
|---|
| 369 | Stream.Position := 0;
|
|---|
| 370 | I := 0;
|
|---|
| 371 | while I < Count do begin
|
|---|
| 372 | Items[I] := Stream.ReadByte;
|
|---|
| 373 | I := I + 1;
|
|---|
| 374 | end;
|
|---|
| 375 | end;
|
|---|
| 376 |
|
|---|
| 377 | procedure TListByte.ReplaceStreamPart(Stream: TStream; ItemIndex,
|
|---|
| 378 | ItemCount: Integer);
|
|---|
| 379 | var
|
|---|
| 380 | I: Integer;
|
|---|
| 381 | begin
|
|---|
| 382 | I := ItemIndex;
|
|---|
| 383 | while I < ItemCount do begin
|
|---|
| 384 | Items[I] := Stream.ReadByte;
|
|---|
| 385 | I := I + 1;
|
|---|
| 386 | end;
|
|---|
| 387 | end;
|
|---|
| 388 |
|
|---|
| 389 | procedure TListByte.AddStream(Stream: TStream);
|
|---|
| 390 | var
|
|---|
| 391 | I: Integer;
|
|---|
| 392 | begin
|
|---|
| 393 | Stream.Position := 0;
|
|---|
| 394 | I := Count;
|
|---|
| 395 | Count := Count + Stream.Size;
|
|---|
| 396 | while I < Count do begin
|
|---|
| 397 | Items[I] := Stream.ReadByte;
|
|---|
| 398 | I := I + 1;
|
|---|
| 399 | end;
|
|---|
| 400 | end;
|
|---|
| 401 |
|
|---|
| 402 | procedure TListByte.AddStreamPart(Stream: TStream; ItemCount: Integer);
|
|---|
| 403 | var
|
|---|
| 404 | I: Integer;
|
|---|
| 405 | begin
|
|---|
| 406 | I := Count;
|
|---|
| 407 | Count := Count + ItemCount;
|
|---|
| 408 | while I < Count do begin
|
|---|
| 409 | Items[I] := Stream.ReadByte;
|
|---|
| 410 | I := I + 1;
|
|---|
| 411 | end;
|
|---|
| 412 | end;
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 | end.
|
|---|