* self enumerators for hashmap and vector

git-svn-id: trunk@42909 -
This commit is contained in:
marco 2019-09-03 11:53:09 +00:00
parent fef4741eb8
commit 534d7b0943
2 changed files with 13 additions and 0 deletions

View File

@ -44,6 +44,7 @@
generic THashmapIterator<TKey, TValue, T, TTable>=class generic THashmapIterator<TKey, TValue, T, TTable>=class
public public
type PValue=^TValue; type PValue=^TValue;
TIntIterator = specialize THashmapIterator<TKey, TValue, T, TTable>;
var var
Fh,Fp:SizeUInt; Fh,Fp:SizeUInt;
FData:TTable; FData:TTable;
@ -55,6 +56,7 @@
function GetValue:TValue;inline; function GetValue:TValue;inline;
function GetMutable:PValue;inline; function GetMutable:PValue;inline;
procedure SetValue(value:TValue);inline; procedure SetValue(value:TValue);inline;
function GetEnumerator : TIntIterator; inline;
property Data:T read GetData; property Data:T read GetData;
property Key:TKey read GetKey; property Key:TKey read GetKey;
property Value:TValue read GetValue write SetValue; property Value:TValue read GetValue write SetValue;
@ -376,4 +378,9 @@ begin
((FData[Fh]).mutable[Fp])^.Value := value; ((FData[Fh]).mutable[Fp])^.Value := value;
end; end;
function THashmapIterator.getenumerator: TIntIterator;
begin
result:=self;
end;
end. end.

View File

@ -50,6 +50,7 @@ type
function GetCurrent: T; inline; function GetCurrent: T; inline;
public public
constructor Create(AVector: TVector); constructor Create(AVector: TVector);
function GetEnumerator: TVectorEnumerator; inline;
function MoveNext: Boolean; inline; function MoveNext: Boolean; inline;
property Current: T read GetCurrent; property Current: T read GetCurrent;
end; end;
@ -83,6 +84,11 @@ begin
FVector := AVector; FVector := AVector;
end; end;
function TVector.TVectorEnumerator.GetEnumerator: TVectorEnumerator;
begin
result:=self;
end;
function TVector.TVectorEnumerator.GetCurrent: T; function TVector.TVectorEnumerator.GetCurrent: T;
begin begin
Result := FVector[FPosition]; Result := FVector[FPosition];