ソースを参照

* [Generics] auto create map entry if not existing

master
Bergmann89 10年前
親
コミット
35524b6152
1個のファイルの変更、9行の追加、3行の削除
  1. +9
    -3
      uutlGenerics.pas

+ 9
- 3
uutlGenerics.pas ファイルの表示

@@ -299,6 +299,7 @@ type
end;

private
fAutoCreate: Boolean;
fHashSetRef: THashSet;
fKeyWrapper: TKeyWrapper;
fKeyValuePairWrapper: TKeyValuePairWrapper;
@@ -315,6 +316,7 @@ type
property Keys: TKeyWrapper read fKeyWrapper;
property KeyValuePairs: TKeyValuePairWrapper read fKeyValuePairWrapper;
property Count: Integer read GetCount;
property AutoCreate: Boolean read fAutoCreate write fAutoCreate;

procedure Add(const aKey: TKey; const aValue: TValue);
function IndexOf(const aKey: TKey): Integer;
@@ -1410,9 +1412,12 @@ begin
kvp.Key := aKey;
kvp.Value := aValue;
i := fHashSetRef.IndexOf(kvp);
if (i < 0) then
raise EutlMap.Create('key not found');
fHashSetRef[i] := kvp;
if (i < 0) then begin
if not fAutoCreate then
raise EutlMap.Create('key not found');
fHashSetRef.Add(kvp);
end else
fHashSetRef[i] := kvp;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1501,6 +1506,7 @@ end;
constructor TutlMapBase.Create(const aHashSet: THashSet);
begin
inherited Create;
fAutoCreate := false;
fHashSetRef := aHashSet;
fKeyWrapper := TKeyWrapper.Create(fHashSetRef);
fKeyValuePairWrapper := TKeyValuePairWrapper.Create(fHashSetRef);


読み込み中…
キャンセル
保存