Browse Source

* Expose ForeachCall functionality in new Iterate call, but keep backwards compatibiliy

git-svn-id: trunk@23144 -
michael 12 years ago
parent
commit
cecea651b2
1 changed files with 51 additions and 10 deletions
  1. 51 10
      packages/fcl-base/src/contnrs.pp

+ 51 - 10
packages/fcl-base/src/contnrs.pp

@@ -413,8 +413,9 @@ type
     Procedure AddNode(ANode : THTCustomNode); override;
     procedure SetData(const index: string; const AValue: Pointer); virtual;
     function GetData(const index: string):Pointer; virtual;
+    function ForEachCall(aMethod: TDataIteratorMethod): THTDataNode; virtual;
   Public
-    function ForEachCall(aMethod: TDataIteratorMethod): Pointer; virtual;
+    function Iterate(aMethod: TDataIteratorMethod): Pointer; virtual;
     procedure Add(const aKey: string; AItem: pointer); virtual;
     property Items[const index: string]: Pointer read GetData write SetData; default;
   end;
@@ -434,8 +435,9 @@ type
     Procedure AddNode(ANode : THTCustomNode); override;
     procedure SetData(const Index, AValue: string); virtual;
     function GetData(const index: string): String; virtual;
+    function ForEachCall(aMethod: TStringIteratorMethod): THTStringNode; virtual;
   Public
-    function ForEachCall(aMethod: TStringIteratorMethod): String; virtual;
+    function Iterate(aMethod: TStringIteratorMethod): String; virtual;
     procedure Add(const aKey,aItem: string); virtual;
     property Items[const index: string]: String read GetData write SetData; default;
   end;
@@ -464,10 +466,11 @@ type
     Procedure AddNode(ANode : THTCustomNode); override;
     procedure SetData(const Index: string; AObject : TObject); virtual;
     function GetData(const index: string): TObject; virtual;
+    function ForEachCall(aMethod: TObjectIteratorMethod): THTObjectNode; virtual;
   Public
     constructor Create(AOwnsObjects : Boolean = True);
     constructor CreateWith(AHashTableSize: Longword; aHashFunc: THashFunction; AOwnsObjects : Boolean = True);
-    function ForEachCall(aMethod: TObjectIteratorMethod): TObject; virtual;
+    function Iterate(aMethod: TObjectIteratorMethod): TObject; virtual;
     procedure Add(const aKey: string; AItem : TObject); virtual;
     property Items[const index: string]: TObject read GetData write SetData; default;
     Property OwnsObjects : Boolean Read FOwnsObjects Write FOwnsObjects;
@@ -2234,7 +2237,20 @@ begin
   Result:=THTDataNode.CreateWith(aKey);
 end;
 
-function TFPDataHashTable.ForEachCall(aMethod: TDataIteratorMethod): Pointer;
+function TFPDataHashTable.Iterate(aMethod: TDataIteratorMethod): Pointer;
+
+Var
+  N : THTDataNode;
+
+begin
+  N:=ForEachCall(AMethod);
+  if Assigned(N) then
+    Result:=N.Data
+  else
+    Result:=Nil;  
+end;
+
+function TFPDataHashTable.ForEachCall(aMethod: TDataIteratorMethod): THTDataNode;
 var
   i, j: Longword;
   continue: boolean;
@@ -2252,7 +2268,7 @@ begin
           aMethod(THTDataNode(Chain(i)[j]).Data, THTDataNode(Chain(i)[j]).Key, continue);
           if not continue then
           begin
-            Result := THTDataNode(Chain(i)[j]).Data;
+            Result := THTDataNode(Chain(i)[j]);
             Exit;
           end;
         end;
@@ -2310,13 +2326,25 @@ begin
   Result:=THTStringNode.CreateWith(aKey);
 end;
 
+function TFPStringHashTable.Iterate(aMethod: TStringIteratorMethod): String;
+
+Var
+  N : THTStringNode;
+
+begin
+  N:=ForEachCall(AMethod);
+  if Assigned(N) then
+    Result:=N.Data
+  else
+    Result:='';  
+end;
 
-function TFPStringHashTable.ForEachCall(aMethod: TStringIteratorMethod): String;
+function TFPStringHashTable.ForEachCall(aMethod: TStringIteratorMethod): THTStringNode;
 var
   i, j: Longword;
   continue: boolean;
 begin
-  Result := '';
+  Result := Nil;
   continue := true;
   if FHashTableSize>0 then
    for i := 0 to FHashTableSize-1 do
@@ -2329,7 +2357,7 @@ begin
           aMethod(THTStringNode(Chain(i)[j]).Data, THTStringNode(Chain(i)[j]).Key, continue);
           if not continue then
           begin
-            Result := THTStringNode(Chain(i)[j]).Data;
+            Result := THTStringNode(Chain(i)[j]);
             Exit;
           end;
         end;
@@ -2384,7 +2412,20 @@ begin
 end;
 
 
-function TFPObjectHashTable.ForEachCall(aMethod: TObjectIteratorMethod): TObject;
+function TFPObjectHashTable.Iterate(aMethod: TObjectIteratorMethod): TObject;
+
+Var
+  N : THTObjectNode;
+
+begin
+  N:=ForEachCall(AMethod);
+  if Assigned(N) then
+    Result:=N.Data
+  else
+    Result:=Nil;  
+end;
+
+function TFPObjectHashTable.ForEachCall(aMethod: TObjectIteratorMethod): THTObjectNode;
 var
   i, j: Longword;
   continue: boolean;
@@ -2402,7 +2443,7 @@ begin
           aMethod(THTObjectNode(Chain(i)[j]).Data, THTObjectNode(Chain(i)[j]).Key, continue);
           if not continue then
           begin
-            Result := THTObjectNode(Chain(i)[j]).Data;
+            Result := THTObjectNode(Chain(i)[j]);
             Exit;
           end;
         end;