|
|
|
@@ -82,6 +82,7 @@ type |
|
|
|
PListItem = ^TListItem; |
|
|
|
|
|
|
|
public type |
|
|
|
TItemEvent = procedure(aSender: TObject; const aIndex: Integer; const aItem: T) of object; |
|
|
|
TEnumerator = class(TObject) |
|
|
|
private |
|
|
|
fReverse: Boolean; |
|
|
|
@@ -117,6 +118,7 @@ type |
|
|
|
|
|
|
|
function GetEnumerator: TEnumerator; |
|
|
|
function GetReverseEnumerator: TEnumerator; |
|
|
|
procedure ForEach(const aEvent: TItemEvent); |
|
|
|
procedure Clear; |
|
|
|
|
|
|
|
constructor Create(const aOwnsObjects: Boolean = true); |
|
|
|
@@ -180,12 +182,15 @@ type |
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
generic TutlHashSetBase<T> = class(specialize TutlListBase<T>) |
|
|
|
public type |
|
|
|
THashItemEvent = procedure(aSender: TObject; const aItem: T) of object; |
|
|
|
IComparer = specialize IutlComparer<T>; |
|
|
|
private |
|
|
|
fComparer: IComparer; |
|
|
|
protected |
|
|
|
function SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; |
|
|
|
public |
|
|
|
procedure ForEach(const aEvent: THashItemEvent); |
|
|
|
|
|
|
|
constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); |
|
|
|
destructor Destroy; override; |
|
|
|
end; |
|
|
|
@@ -224,6 +229,8 @@ type |
|
|
|
|
|
|
|
generic TutlMapBase<TKey, TValue> = class(TObject) |
|
|
|
public type |
|
|
|
TKeyValuePairEvent = procedure(aSender: TObject; const aKey: TKey; const aValue: TValue) of object; |
|
|
|
|
|
|
|
IComparer = specialize IutlComparer<TKey>; |
|
|
|
TKeyValuePair = packed record |
|
|
|
Key: TKey; |
|
|
|
@@ -316,6 +323,7 @@ type |
|
|
|
procedure DeleteAt(const aIndex: Integer); |
|
|
|
procedure Clear; |
|
|
|
|
|
|
|
procedure ForEach(const aEvent: TKeyValuePairEvent); |
|
|
|
function GetEnumerator: TValueEnumerator; |
|
|
|
function GetReverseEnumerator: TValueEnumerator; |
|
|
|
|
|
|
|
@@ -895,6 +903,15 @@ begin |
|
|
|
result := TEnumerator.Create(fList, true); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
procedure TutlListBase.ForEach(const aEvent: TItemEvent); |
|
|
|
var i: Integer; |
|
|
|
begin |
|
|
|
if not Assigned(aEvent) then |
|
|
|
for i := 0 to fList.Count-1 do |
|
|
|
aEvent(self, i, PListItem(fList[i])^.data); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
procedure TutlListBase.Clear; |
|
|
|
begin |
|
|
|
@@ -1131,6 +1148,15 @@ begin |
|
|
|
end; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
procedure TutlHashSetBase.ForEach(const aEvent: THashItemEvent); |
|
|
|
var item: T; |
|
|
|
begin |
|
|
|
if Assigned(aEvent) then |
|
|
|
for item in self do |
|
|
|
aEvent(self, item); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
constructor TutlHashSetBase.Create(aComparer: IComparer; const aOwnsObjects: Boolean); |
|
|
|
begin |
|
|
|
@@ -1450,6 +1476,15 @@ begin |
|
|
|
fHashSetRef.Clear; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
procedure TutlMapBase.ForEach(const aEvent: TKeyValuePairEvent); |
|
|
|
var kvp: TKeyValuePair; |
|
|
|
begin |
|
|
|
if Assigned(aEvent) then |
|
|
|
for kvp in fHashSetRef do |
|
|
|
aEvent(self, kvp.Key, kvp.Value); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlMapBase.GetEnumerator: TValueEnumerator; |
|
|
|
begin |
|
|
|
@@ -1747,7 +1782,8 @@ class function TutlEnumHelper.TryToEnum(aStr: String; out aValue: T): Boolean; |
|
|
|
var |
|
|
|
a: T; |
|
|
|
begin |
|
|
|
Result:= false; |
|
|
|
a := T(0); |
|
|
|
Result := false; |
|
|
|
if Length(aStr) = 0 then |
|
|
|
exit; |
|
|
|
|
|
|
|
@@ -1757,7 +1793,7 @@ begin |
|
|
|
Result:= IOResult <> 106; |
|
|
|
{$Pop} |
|
|
|
if Result then |
|
|
|
aValue:= a; |
|
|
|
aValue := a; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|