* adds assign methods to the fgl classes based on a patch by Aleksa Todorovic, resolves #10479

git-svn-id: trunk@16429 -
This commit is contained in:
florian 2010-11-25 14:12:13 +00:00
parent e770bc597f
commit ef0899425b
3 changed files with 72 additions and 7 deletions

1
.gitattributes vendored
View File

@ -9281,6 +9281,7 @@ tests/test/tgeneric2.pp svneol=native#text/plain
tests/test/tgeneric20.pp svneol=native#text/pascal
tests/test/tgeneric21.pp svneol=native#text/pascal
tests/test/tgeneric22.pp svneol=native#text/pascal
tests/test/tgeneric23.pp svneol=native#text/pascal
tests/test/tgeneric3.pp svneol=native#text/plain
tests/test/tgeneric4.pp svneol=native#text/plain
tests/test/tgeneric5.pp svneol=native#text/plain

View File

@ -15,6 +15,8 @@
**********************************************************************}
{$mode objfpc}
{.$define CLASSESINLINE}
{ be aware, this unit is a prototype and subject to be changed heavily }
unit fgl;
@ -40,7 +42,7 @@ type
protected
FList: PByte;
FCount: Integer;
FCapacity: Integer; { list is one longer than capacity, for temp }
FCapacity: Integer; { list is one longer sgthan capacity, for temp }
FItemSize: Integer;
procedure CopyItem(Src, Dest: Pointer); virtual;
procedure Deref(Item: Pointer); virtual; overload;
@ -124,8 +126,9 @@ type
function IndexOf(const Item: T): Integer;
procedure Insert(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
function Last: T; {$ifdef CLASSESINLINE} inline; {$endif}
{$info FIXME: bug #10479: implement TFPGList<T>.Assign(TFPGList) to work somehow}
{procedure Assign(Source: TFPGList);}
{$ifndef VER2_4}
procedure Assign(Source: TFPGList);
{$endif VER2_4}
function Remove(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
procedure Sort(Compare: TCompareFunc);
property Items[Index: Integer]: T read Get write Put; default;
@ -156,8 +159,9 @@ type
function IndexOf(const Item: T): Integer;
procedure Insert(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
function Last: T; {$ifdef CLASSESINLINE} inline; {$endif}
{$info FIXME: bug #10479: implement TFPGObjectList<T>.Assign(TFPGList) to work somehow}
{procedure Assign(Source: TFPGList);}
{$ifndef VER2_4}
procedure Assign(Source: TFPGObjectList);
{$endif VER2_4}
function Remove(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
procedure Sort(Compare: TCompareFunc);
property Items[Index: Integer]: T read Get write Put; default;
@ -188,8 +192,9 @@ type
function IndexOf(const Item: T): Integer;
procedure Insert(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
function Last: T; {$ifdef CLASSESINLINE} inline; {$endif}
{$info FIXME: bug #10479: implement TFPGInterfacedObjectList<T>.Assign(TFPGList) to work somehow}
{procedure Assign(Source: TFPGList);}
{$ifndef VER2_4}
procedure Assign(Source: TFPGInterfacedObjectList);
{$endif VER2_4}
function Remove(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
procedure Sort(Compare: TCompareFunc);
property Items[Index: Integer]: T read Get write Put; default;
@ -753,6 +758,17 @@ begin
Result := T(inherited Last^);
end;
{$ifndef VER2_4}
procedure TFPGList.Assign(Source: TFPGList);
var
i: Integer;
begin
Clear;
for I := 0 to Source.Count - 1 do
Add(Source[i]);
end;
{$endif VER2_4}
function TFPGList.Remove(const Item: T): Integer;
begin
Result := IndexOf(Item);
@ -849,6 +865,17 @@ begin
Result := T(inherited Last^);
end;
{$ifndef VER2_4}
procedure TFPGObjectList.Assign(Source: TFPGObjectList);
var
i: Integer;
begin
Clear;
for I := 0 to Source.Count - 1 do
Add(Source[i]);
end;
{$endif VER2_4}
function TFPGObjectList.Remove(const Item: T): Integer;
begin
Result := IndexOf(Item);
@ -948,6 +975,17 @@ begin
Result := T(inherited Last^);
end;
{$ifndef VER2_4}
procedure TFPGInterfacedObjectList.Assign(Source: TFPGInterfacedObjectList);
var
i: Integer;
begin
Clear;
for I := 0 to Source.Count - 1 do
Add(Source[i]);
end;
{$endif VER2_4}
function TFPGInterfacedObjectList.Remove(const Item: T): Integer;
begin
Result := IndexOf(Item);

26
tests/test/tgeneric23.pp Normal file
View File

@ -0,0 +1,26 @@
{$mode objfpc}
program test;
uses
fgl;
type
TIntList = specialize TFPGList<Integer>;
var
A, B: TIntList;
i: Integer;
begin
A := TIntList.Create;
B := TIntList.Create;
for i := 0 to 9 do
A.Add(i);
B.Assign(A);
for i:= 0 to 9 do
begin
if B[i] <> i then
Halt(1);
end;
end.