* Patch from Silvio Clecio to add a TryGetValue method to TFPGMap (bug ID 29397)

git-svn-id: trunk@32942 -
This commit is contained in:
michael 2016-01-15 07:48:49 +00:00
parent b96d3cc517
commit 64c324caaf

View File

@ -305,6 +305,7 @@ type
function Add(const AKey: TKey; const AData: TData): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
function Add(const AKey: TKey): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
function Find(const AKey: TKey; out Index: Integer): Boolean; {$ifdef CLASSESINLINE} inline; {$endif}
function TryGetValue(const AKey: TKey; out AData: TData): Boolean; {$ifdef CLASSESINLINE} inline; {$endif}
function IndexOf(const AKey: TKey): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
function IndexOfData(const AData: TData): Integer;
procedure InsertKey(Index: Integer; const AKey: TKey);
@ -1481,6 +1482,17 @@ begin
Result := inherited Find(@AKey, Index);
end;
function TFPGMap.TryGetValue(const AKey: TKey; out AData: TData): Boolean;
var
I: Integer;
begin
Result := inherited Find(@AKey, I);
if Result then
AData := TData(inherited GetData(I)^)
else
AData := Default(TData);
end;
function TFPGMap.IndexOf(const AKey: TKey): Integer;
begin
Result := inherited IndexOf(@AKey);