Changeset 304


Ignore:
Timestamp:
Dec 19, 2011, 9:19:00 AM (13 years ago)
Author:
chronos
Message:
  • Added: Handling of TStream by TListByte.
Location:
Generics/TemplateGenerics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericList.inc

    r270 r304  
    2929    procedure AddArray(Values: array of TGListItem);
    3030    procedure AddList(List: TGList);
     31    procedure AddListPart(List: TGList; ItemIndex, ItemCount: TGListIndex);
    3132    procedure Assign(Source: TGList); virtual;
    3233    constructor Create; virtual;
     
    4243    function GetArray: TGListItemArray;
    4344    function Implode(Separator: string; Converter: TGListToStringConverter): string;
    44     function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex; virtual;
     45    function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex;
    4546    function IndexOfList(List: TGList; Start: TGListIndex = 0): TGListIndex;
    4647    procedure Insert(Index: TGListIndex; Item: TGListItem);
     
    5152    function Remove(Item: TGListItem): TGListIndex;
    5253    procedure Reverse;
    53     procedure Replace(Index: TGListIndex; Source: TGList);
     54    procedure ReplaceList(Index: TGListIndex; Source: TGList);
     55    procedure ReplaceListPart(Index: TGListIndex; Source: TGList;
     56      SourceIndex, SourceCount: TGListIndex);
    5457    procedure Sort(Compare: TGListSortCompare);
    5558    procedure SetArray(Values: array of TGListItem);
     
    8083end;
    8184
    82 procedure TGList.Replace(Index: TGListIndex; Source: TGList);
     85procedure TGList.ReplaceList(Index: TGListIndex; Source: TGList);
    8386var
    8487  I: TGListIndex;
     
    8790  while I < Source.Count do begin
    8891    Items[Index + I] := Source[I];
     92    I := I + 1;
     93  end;
     94end;
     95
     96procedure TGList.ReplaceListPart(Index: TGListIndex; Source: TGList;
     97  SourceIndex, SourceCount: TGListIndex);
     98var
     99  I: TGListIndex;
     100begin
     101  I := 0;
     102  while I < SourceCount do begin
     103    Items[Index + I] := Source[SourceIndex + I];
    89104    I := I + 1;
    90105  end;
     
    374389    I := 0;
    375390    while I < Count do begin
    376       if not CompareMem(@FItems[I], @List.FItems[I], SizeOf(TGListItem)) then begin
     391      if not CompareMem(Addr(FItems[I]), Addr(List.FItems[I]), SizeOf(TGListItem)) then begin
    377392        Result := False;
    378393        Break;
     
    469484var
    470485  I: TGListIndex;
    471 begin
    472   I := 0;
    473   while I < List.Count do begin
    474     Add(List[I]);
    475     I := I + 1;
     486  J: TGListIndex;
     487begin
     488  I := Count;
     489  J := 0;
     490  Count := Count + List.Count;
     491  while I < Count do begin
     492    Items[I] := List[J];
     493    I := I + 1;
     494    J := J + 1;
     495  end;
     496end;
     497
     498procedure TGList.AddListPart(List: TGList; ItemIndex, ItemCount: TGListIndex);
     499var
     500  I: TGListIndex;
     501  J: TGListIndex;
     502begin
     503  I := Count;
     504  J := ItemIndex;
     505  Count := Count + ItemCount;
     506  while I < Count do begin
     507    Items[I] := List[J];
     508    I := I + 1;
     509    J := J + 1;
    476510  end;
    477511end;
  • Generics/TemplateGenerics/Specialized/SpecializedList.pas

    r232 r304  
    9090TListByte = class(TListByteBase)
    9191  procedure WriteToStream(Stream: TStream);
     92  procedure WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
     93  procedure ReplaceStream(Stream: TStream);
     94  procedure ReplaceStreamPart(Stream: TStream; ItemIndex, ItemCount: TGListIndex);
     95  procedure AddStream(Stream: TStream);
     96  procedure AddStreamPart(Stream: TStream; ItemCount: TGListIndex);
    9297end;
    9398
     
    338343end;
    339344
     345{ TListByte }
     346
    340347procedure TListByte.WriteToStream(Stream: TStream);
    341348var
    342349  I: Integer;
    343350begin
     351  Stream.Position := 0;
    344352  I := 0;
    345   while I < Count do
     353  while I < Count do begin
    346354    Stream.WriteByte(Items[I]);
    347 end;
    348 
     355    I := I + 1;
     356  end;
     357end;
     358
     359procedure TListByte.WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
     360var
     361  I: Integer;
     362begin
     363  I := ItemIndex;
     364  while I < ItemCount do begin
     365    Stream.WriteByte(Items[I]);
     366    I := I + 1;
     367  end;
     368end;
     369
     370procedure TListByte.ReplaceStream(Stream: TStream);
     371var
     372  I: Integer;
     373begin
     374  Stream.Position := 0;
     375  I := 0;
     376  while I < Count do begin
     377    Items[I] := Stream.ReadByte;
     378    I := I + 1;
     379  end;
     380end;
     381
     382procedure TListByte.ReplaceStreamPart(Stream: TStream; ItemIndex,
     383  ItemCount: Integer);
     384var
     385  I: Integer;
     386begin
     387  I := ItemIndex;
     388  while I < ItemCount do begin
     389    Items[I] := Stream.ReadByte;
     390    I := I + 1;
     391  end;
     392end;
     393
     394procedure TListByte.AddStream(Stream: TStream);
     395var
     396  I: Integer;
     397begin
     398  Stream.Position := 0;
     399  I := Count;
     400  Count := Count + Stream.Size;
     401  while I < Count do begin
     402    Items[I] := Stream.ReadByte;
     403    I := I + 1;
     404  end;
     405end;
     406
     407procedure TListByte.AddStreamPart(Stream: TStream; ItemCount: Integer);
     408var
     409  I: Integer;
     410begin
     411  I := Count;
     412  Count := Count + ItemCount;
     413  while I < Count do begin
     414    Items[I] := Stream.ReadByte;
     415    I := I + 1;
     416  end;
     417end;
    349418
    350419end.
Note: See TracChangeset for help on using the changeset viewer.