-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
AuxClasses.inc
760 lines (630 loc) · 33.5 KB
/
AuxClasses.inc
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
Auxiliary classes and other class-related things
This file contains main classes template used by AuxClasses library.
Version 1.2.3 (2024-10-04)
Last change 2024-10-04
©2018-2024 František Milt
Contacts:
František Milt: frantisek.milt@gmail.com
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.AuxClasses
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
Library AuxExceptions is required only when rebasing local exception classes
(see symbol AuxClasses_UseAuxExceptions for details).
Indirect dependencies:
SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
StrRect - github.com/TheLazyTomcat/Lib.StrRect
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
{!tun_end!} // ignore this line
{===============================================================================
********************************************************************************
Declarations
********************************************************************************
===============================================================================}
{$IFDEF AC_Include_Declaration}
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)Object
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)Object - class declaration
===============================================================================}
{
Normal object only with added fields/properties that can be used by user for
any purpose, and also some methods.
}
type
{$IFDEF AC_Include_Interfaced}
TCustomInterfacedObject = class(TInterfacedObject)
{$ELSE}
TCustomObject = class(TObject)
{$ENDIF}
protected
fUserIntData: PtrInt;
fUserPtrData: Pointer;
procedure RaiseError(ExceptionClass: ExceptClass; const Method,Msg: String; const Args: array of const); overload; virtual;
procedure RaiseError(ExceptionClass: ExceptClass; const Method,Msg: String); overload; virtual;
procedure RaiseError(const Method,Msg: String; const Args: array of const); overload; virtual;
procedure RaiseError(const Method,Msg: String); overload; virtual;
procedure RaiseError(ExceptionClass: ExceptClass; const Msg: String; const Args: array of const); overload; virtual;
procedure RaiseError(ExceptionClass: ExceptClass; const Msg: String); overload; virtual;
procedure RaiseError(const Msg: String; const Args: array of const); overload; virtual;
procedure RaiseError(const Msg: String); overload; virtual;
public
constructor Create;
Function InstanceString: String; virtual;
property UserIntData: PtrInt read fUserIntData write fUserIntData;
property UserPtrData: Pointer read fUserPtrData write fUserPtrData;
property UserData: PtrInt read fUserIntData write fUserIntData;
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)RefCountedObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)RefCountedObject - class declaration
===============================================================================}
{
Reference counted object.
Note that reference counting is not automatic, you have to call methods
Acquire and Release for it to work.
When FreeOnRelease is set to true (by default set to false), then the object
is automatically freed inside of function Release when reference counter upon
entry to this function is 1 (ie. it reaches 0 in this call).
}
type
{$IFDEF AC_Include_Interfaced}
TCustomInterfacedRefCountedObject = class(TCustomInterfacedObject)
{$ELSE}
TCustomRefCountedObject = class(TCustomObject)
{$ENDIF}
protected
fReferenceCount: Int32;
fFreeOnRelease: Boolean;
Function GetReferenceCount: Int32; virtual;
public
constructor Create;
Function Acquire: Int32; virtual;
Function Release: Int32; virtual;
property ReferenceCount: Int32 read GetReferenceCount;
property FreeOnRelease: Boolean read fFreeOnRelease write fFreeOnRelease;
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)ListObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)ListObject - class declaration
===============================================================================}
{
Implements methods for advanced parametrized growing and shrinking of any
list and a few more.
Expects derived class to properly implement capacity and count properties
(both getters and setters) and LowIndex and HighIndex functions.
}
type
{$IFDEF AC_Include_Interfaced}
TCustomInterfacedListObject = class(TCustomInterfacedObject)
{$ELSE}
TCustomListObject = class(TCustomObject)
{$ENDIF}
protected
fListGrowSettings: TListGrowSettings;
Function GetCapacity: Integer; virtual; abstract;
procedure SetCapacity(Value: Integer); virtual; abstract;
Function GetCount: Integer; virtual; abstract;
procedure SetCount(Value: Integer); virtual; abstract;
procedure Grow(MinDelta: Integer = 1); virtual;
procedure Shrink; virtual;
public
constructor Create;
Function LowIndex: Integer; virtual; abstract;
Function HighIndex: Integer; virtual; abstract;
Function CheckIndex(Index: Integer): Boolean; virtual;
procedure CopyGrowSettings(Source: {$IFDEF AC_Include_Interfaced}TCustomInterfacedListObject{$ELSE}TCustomListObject{$ENDIF}); virtual;
property ListGrowSettings: TListGrowSettings read fListGrowSettings write fListGrowSettings;
property GrowInit: Integer read fListGrowSettings.GrowInit write fListGrowSettings.GrowInit;
property GrowMode: TGrowMode read fListGrowSettings.GrowMode write fListGrowSettings.GrowMode;
property GrowFactor: Double read fListGrowSettings.GrowFactor write fListGrowSettings.GrowFactor;
property GrowLimit: Integer read fListGrowSettings.GrowLimit write fListGrowSettings.GrowLimit;
property ShrinkMode: TShrinkMode read fListGrowSettings.ShrinkMode write fListGrowSettings.ShrinkMode;
property ShrinkFactor: Double read fListGrowSettings.ShrinkFactor write fListGrowSettings.ShrinkFactor;
property ShrinkLimit: Integer read fListGrowSettings.ShrinkLimit write fListGrowSettings.ShrinkLimit;
property Capacity: Integer read GetCapacity write SetCapacity;
property Count: Integer read GetCount write SetCount;
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)MultiListObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)MultiListObject - class declaration
===============================================================================}
{
Very similar to TCustom(Interfaced)ListObject, but this class can support
multiple separate lists that are selected by integer index.
}
type
{$IFDEF AC_Include_Interfaced}
TCustomInterfacedMultiListObject = class(TCustomInterfacedObject)
{$ELSE}
TCustomMultiListObject = class(TCustomObject)
{$ENDIF}
private
Function StaticClassName: String;
protected
fListGrowSettings: array of TListGrowSettings;
Function GetListCount: Integer; virtual;
procedure SetListCount(Value: Integer); virtual;
Function GetListGrowSettings(List: Integer): TListGrowSettings; virtual;
procedure SetListGrowSettings(List: Integer; Value: TListGrowSettings); virtual;
Function GetListGrowSettingsPtr(List: Integer): PListGrowSettings; virtual;
Function GetListGrowSettings_GrowInit(List: Integer): Integer; virtual;
procedure SetListGrowSettings_GrowInit(List: Integer; Value: Integer); virtual;
Function GetListGrowSettings_GrowMode(List: Integer): TGrowMode; virtual;
procedure SetListGrowSettings_GrowMode(List: Integer; Value: TGrowMode); virtual;
Function GetListGrowSettings_GrowFactor(List: Integer): Double; virtual;
procedure SetListGrowSettings_GrowFactor(List: Integer; Value: Double); virtual;
Function GetListGrowSettings_GrowLimit(List: Integer): Integer; virtual;
procedure SetListGrowSettings_GrowLimit(List: Integer; Value: Integer); virtual;
Function GetListGrowSettings_ShrinkMode(List: Integer): TShrinkMode; virtual;
procedure SetListGrowSettings_ShrinkMode(List: Integer; Value: TShrinkMode); virtual;
Function GetListGrowSettings_ShrinkFactor(List: Integer): Double; virtual;
procedure SetListGrowSettings_ShrinkFactor(List: Integer; Value: Double); virtual;
Function GetListGrowSettings_ShrinkLimit(List: Integer): Integer; virtual;
procedure SetListGrowSettings_ShrinkLimit(List: Integer; Value: Integer); virtual;
Function GetCapacity(List: Integer): Integer; virtual; abstract;
procedure SetCapacity(List,Value: Integer); virtual; abstract;
Function GetCount(List: Integer): Integer; virtual; abstract;
procedure SetCount(List,Value: Integer); virtual; abstract;
procedure Grow(List: Integer; MinDelta: Integer = 1); virtual;
procedure Shrink(List: Integer); virtual;
public
constructor Create(ListCount: Integer);
destructor Destroy; override;
Function LowList: Integer; virtual;
Function HighList: Integer; virtual;
Function CheckList(List: Integer): Boolean; virtual;
Function LowIndex(List: Integer): Integer; virtual; abstract;
Function HighIndex(List: Integer): Integer; virtual; abstract;
Function CheckIndex(List,Index: Integer): Boolean; virtual;
procedure CopyGrowSettings(Source: {$IFDEF AC_Include_Interfaced}TCustomInterfacedMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}); virtual;
property ListCount: Integer read GetListCount write SetListCount;
property ListGrowSettings[List: Integer]: TListGrowSettings read GetListGrowSettings write SetListGrowSettings;
property ListGrowSettingsPtrs[List: Integer]: PListGrowSettings read GetListGrowSettingsPtr;
property GrowInit[List: Integer]: Integer read GetListGrowSettings_GrowInit write SetListGrowSettings_GrowInit;
property GrowMode[List: Integer]: TGrowMode read GetListGrowSettings_GrowMode write SetListGrowSettings_GrowMode;
property GrowFactor[List: Integer]: Double read GetListGrowSettings_GrowFactor write SetListGrowSettings_GrowFactor;
property GrowLimit[List: Integer]: Integer read GetListGrowSettings_GrowLimit write SetListGrowSettings_GrowLimit;
property ShrinkMode[List: Integer]: TShrinkMode read GetListGrowSettings_ShrinkMode write SetListGrowSettings_ShrinkMode;
property ShrinkFactor[List: Integer]: Double read GetListGrowSettings_ShrinkFactor write SetListGrowSettings_ShrinkFactor;
property ShrinkLimit[List: Integer]: Integer read GetListGrowSettings_ShrinkLimit write SetListGrowSettings_ShrinkLimit;
property Capacity[List: Integer]: Integer read GetCapacity write SetCapacity;
property Count[List: Integer]: Integer read GetCount write SetCount;
end;
{$IFDEF AC_Include_Interfaced}
type
// shorter aliases
TCustomIObject = TCustomInterfacedObject;
TCustomIRefCountedObject = TCustomInterfacedRefCountedObject;
TCustomIListObject = TCustomInterfacedListObject;
TCustomIMultiListObject = TCustomInterfacedMultiListObject;
{$ENDIF}
{$ENDIF}
{===============================================================================
********************************************************************************
Implementations
********************************************************************************
===============================================================================}
{$IFDEF AC_Include_Implementation}
{$IFDEF AC_Include_Interfaced}
{$DEFINE AC_I_I}
{$ELSE}
{$UNDEF AC_I_I}
{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)Object
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)Object - class implementation
===============================================================================}
{-------------------------------------------------------------------------------
TCustom(Interfaced)Object - protected methods
-------------------------------------------------------------------------------}
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(ExceptionClass: ExceptClass; const Method,Msg: String; const Args: array of const);
begin
raise ExceptionClass.CreateFmt(Format('%s.%s: %s',[InstanceString,Method,Msg]),Args);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(ExceptionClass: ExceptClass; const Method,Msg: String);
begin
RaiseError(ExceptionClass,Method,Msg,[]);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(const Method,Msg: String; const Args: array of const);
begin
RaiseError(Exception,Method,Msg,Args);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(const Method,Msg: String);
begin
RaiseError(Exception,Method,Msg,[]);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(ExceptionClass: ExceptClass; const Msg: String; const Args: array of const);
begin
raise ExceptionClass.CreateFmt(Format('%s: %s',[InstanceString,Msg]),Args);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(ExceptionClass: ExceptClass; const Msg: String);
begin
RaiseError(ExceptionClass,Msg,[]);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(const Msg: String; const Args: array of const);
begin
RaiseError(Exception,Msg,Args);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.RaiseError(const Msg: String);
begin
RaiseError(Exception,Msg,[]);
end;
{-------------------------------------------------------------------------------
TCustom(Interfaced)Object - public methods
-------------------------------------------------------------------------------}
constructor {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.Create;
begin
inherited;
fUserIntData := 0;
fUserPtrData := nil;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIObject{$ELSE}TCustomObject{$ENDIF}.InstanceString: String;
begin
Result := GetInstanceString(Self);
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)RefCountedObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)RefCountedObject - class implementation
===============================================================================}
{-------------------------------------------------------------------------------
TCustom(Interfaced)RefCountedObject - protected methods
-------------------------------------------------------------------------------}
Function {$IFDEF AC_I_I}TCustomIRefCountedObject{$ELSE}TCustomRefCountedObject{$ENDIF}.GetReferenceCount: Int32;
begin
Result := InterlockedExchangeAdd(fReferenceCount,0);
end;
{-------------------------------------------------------------------------------
TCustom(Interfaced)RefCountedObject - public methods
-------------------------------------------------------------------------------}
constructor {$IFDEF AC_I_I}TCustomIRefCountedObject{$ELSE}TCustomRefCountedObject{$ENDIF}.Create;
begin
inherited Create;
fReferenceCount := 0;
fFreeOnRelease := False;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIRefCountedObject{$ELSE}TCustomRefCountedObject{$ENDIF}.Acquire: Int32;
begin
Result := InterlockedExchangeAdd(fReferenceCount,1) + 1;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIRefCountedObject{$ELSE}TCustomRefCountedObject{$ENDIF}.Release: Int32;
begin
Result := InterlockedExchangeAdd(fReferenceCount,-1) - 1;
If fFreeOnRelease and (Result <= 0) then
Self.Free;
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)ListObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)ListObject - class implementation
===============================================================================}
{-------------------------------------------------------------------------------
TCustom(Interfaced)ListObject - protected methods
-------------------------------------------------------------------------------}
procedure {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF}.Grow(MinDelta: Integer = 1);
var
Delta: Integer;
begin
If ResolveGrowDelta(Capacity,Count,MinDelta,fListGrowSettings,Delta) then
Capacity := Capacity + Delta;
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF}.Shrink;
var
NewCap: Integer;
begin
If ResolveShrinkCapacity(Capacity,Count,fListGrowSettings,NewCap) then
Capacity := NewCap;
end;
{-------------------------------------------------------------------------------
TCustom(Interfaced)ListObject - public methods
-------------------------------------------------------------------------------}
constructor {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF}.Create;
begin
inherited;
fListGrowSettings := AC_LIST_GROW_SETTINGS_DEF;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF}.CheckIndex(Index: Integer): Boolean;
begin
Result := (Index >= LowIndex) and (Index <= HighIndex);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF}.CopyGrowSettings(Source: {$IFDEF AC_I_I}TCustomIListObject{$ELSE}TCustomListObject{$ENDIF});
begin
fListGrowSettings := Source.ListGrowSettings;
end;
{===============================================================================
--------------------------------------------------------------------------------
TCustom(Interfaced)MultiListObject
--------------------------------------------------------------------------------
===============================================================================}
{===============================================================================
TCustom(Interfaced)MultiListObject - class implementation
===============================================================================}
{-------------------------------------------------------------------------------
TCustom(Interfaced)MultiListObject - private methods
-------------------------------------------------------------------------------}
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.StaticClassName: String;
begin
Result := {$IFDEF AC_I_I}'TCustomInterfacedMultiListObject'{$ELSE}'TCustomMultiListObject'{$ENDIF};
end;
{-------------------------------------------------------------------------------
TCustom(Interfaced)MultiListObject - protected methods
-------------------------------------------------------------------------------}
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListCount: Integer;
begin
Result := Length(fListGrowSettings);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListCount(Value: Integer);
var
OldCount: Integer;
i: Integer;
begin
If (Value <> Length(fListGrowSettings)) and (Value >= 0) then
begin
OldCount := Length(fListGrowSettings);
SetLength(fListGrowSettings,Value);
If Value > OldCount then
For i := OldCount to High(fListGrowSettings) do
fListGrowSettings[i] := AC_LIST_GROW_SETTINGS_DEF;
end;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings(List: Integer): TListGrowSettings;
begin
If CheckList(List) then
Result := fListGrowSettings[List]
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings(List: Integer; Value: TListGrowSettings);
begin
If CheckList(List) then
fListGrowSettings[List] := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettingsPtr(List: Integer): PListGrowSettings;
begin
If CheckList(List) then
Result := Addr(fListGrowSettings[List])
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettingsPtr: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_GrowInit(List: Integer): Integer;
begin
If CheckList(List) then
Result := fListGrowSettings[List].GrowInit
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_GrowInit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_GrowInit(List: Integer; Value: Integer);
begin
If CheckList(List) then
fListGrowSettings[List].GrowInit := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_GrowInit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_GrowMode(List: Integer): TGrowMode;
begin
If CheckList(List) then
Result := fListGrowSettings[List].GrowMode
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_GrowMode: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_GrowMode(List: Integer; Value: TGrowMode);
begin
If CheckList(List) then
fListGrowSettings[List].GrowMode := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_GrowMode: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_GrowFactor(List: Integer): Double;
begin
If CheckList(List) then
Result := fListGrowSettings[List].GrowFactor
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_GrowFactor: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_GrowFactor(List: Integer; Value: Double);
begin
If CheckList(List) then
fListGrowSettings[List].GrowFactor := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_GrowFactor: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_GrowLimit(List: Integer): Integer;
begin
If CheckList(List) then
Result := fListGrowSettings[List].GrowLimit
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_GrowLimit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_GrowLimit(List: Integer; Value: Integer);
begin
If CheckList(List) then
fListGrowSettings[List].GrowLimit := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_GrowLimit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_ShrinkMode(List: Integer): TShrinkMode;
begin
If CheckList(List) then
Result := fListGrowSettings[List].ShrinkMode
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_ShrinkMode: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_ShrinkMode(List: Integer; Value: TShrinkMode);
begin
If CheckList(List) then
fListGrowSettings[List].ShrinkMode := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_ShrinkMode: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_ShrinkFactor(List: Integer): Double;
begin
If CheckList(List) then
Result := fListGrowSettings[List].ShrinkFactor
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_ShrinkFactor: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_ShrinkFactor(List: Integer; Value: Double);
begin
If CheckList(List) then
fListGrowSettings[List].ShrinkFactor := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_ShrinkFactor: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.GetListGrowSettings_ShrinkLimit(List: Integer): Integer;
begin
If CheckList(List) then
Result := fListGrowSettings[List].ShrinkLimit
else
raise EACIndexOutOfBounds.CreateFmt('%s.GetListGrowSettings_ShrinkLimit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.SetListGrowSettings_ShrinkLimit(List: Integer; Value: Integer);
begin
If CheckList(List) then
fListGrowSettings[List].ShrinkLimit := Value
else
raise EACIndexOutOfBounds.CreateFmt('%s.SetListGrowSettings_ShrinkLimit: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.Grow(List: Integer; MinDelta: Integer = 1);
var
Delta: Integer;
begin
If CheckList(List) then
begin
If ResolveGrowDelta(Capacity[List],Count[List],MinDelta,fListGrowSettings[List],Delta) then
Capacity[List] := Capacity[List] + Delta;
end
else raise EACIndexOutOfBounds.CreateFmt('%s.Grow: List index (%d) out of bounds.',[StaticClassName,List]);
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.Shrink(List: Integer);
var
NewCap: Integer;
begin
If CheckList(List) then
begin
If ResolveShrinkCapacity(Capacity[List],Count[List],fListGrowSettings[List],NewCap) then
Capacity[List] := NewCap;
end
else raise EACIndexOutOfBounds.CreateFmt('%s.Shrink: List index (%d) out of bounds.',[StaticClassName,List]);
end;
{-------------------------------------------------------------------------------
TCustom(Interfaced)MultiListObject - public methods
-------------------------------------------------------------------------------}
constructor {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.Create(ListCount: Integer);
begin
inherited Create;
SetListCount(ListCount)
end;
//------------------------------------------------------------------------------
destructor {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.Destroy;
begin
SetLength(fListGrowSettings,0);
inherited;
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.LowList: Integer;
begin
Result := Low(fListGrowSettings);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.HighList: Integer;
begin
Result := High(fListGrowSettings);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.CheckList(List: Integer): Boolean;
begin
Result := (List >= LowList) and (List <= HighList);
end;
//------------------------------------------------------------------------------
Function {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.CheckIndex(List,Index: Integer): Boolean;
begin
Result := (Index >= LowIndex(List)) and (Index <= HighIndex(List));
end;
//------------------------------------------------------------------------------
procedure {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF}.CopyGrowSettings(Source: {$IFDEF AC_I_I}TCustomIMultiListObject{$ELSE}TCustomMultiListObject{$ENDIF});
var
i: Integer;
begin
If Self.ListCount = Source.ListCount then
begin
For i := LowList to HighList do
fListGrowSettings[i] := Source.ListGrowSettings[i];
end
else raise EACIncompatibleClass.CreateFmt('%s.CopyGrowSettings: List count mismatch (%d,%d).',[StaticClassName,Self.ListCount,Source.ListCount]);
end;
{$ENDIF}