Browse Source

* self enumerators for hashmap and vector

git-svn-id: trunk@42909 -
marco 6 years ago
parent
commit
534d7b0943
2 changed files with 13 additions and 0 deletions
  1. 7 0
      packages/fcl-stl/src/ghashmap.pp
  2. 6 0
      packages/fcl-stl/src/gvector.pp

+ 7 - 0
packages/fcl-stl/src/ghashmap.pp

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

+ 6 - 0
packages/fcl-stl/src/gvector.pp

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