Ignore:
Timestamp:
Jan 9, 2012, 2:22:31 PM (13 years ago)
Author:
chronos
Message:
  • Modified: TGStream is now implemented. TMemoryStreamByte have additional methods usable for byte streams.
  • Added: Few other missing methods in TGList.
File:
1 edited

Legend:

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

    r226 r312  
    11{$IFDEF INTERFACE}
    22
    3 TGStreamDataEvent = procedure (Item: TGStreamItem) of object;
     3TGStreamItemArray = array of TGStreamItem;
    44
    5 // TGStream<TStreamItem> = class
     5// TGStream<TGStreamIndex, TGStreamItem> = class
    66TGStream = class
    7   FOnData: TGStreamDataEvent;
    8   procedure Write(Item: TStreamItem);
    9   property OnData: TGStreamDataEvent read FOnData write FOnData;
     7  procedure SetSize(AValue: TGStreamIndex);
     8  function GetSize: TGStreamIndex;
     9  procedure SetPosition(AValue: TGStreamIndex);
     10  function GetPosition: TGStreamIndex;
     11public
     12  procedure Assign(Source: TGStream); virtual;
     13  procedure Write(Item: TGStreamItem); virtual; abstract;
     14  procedure WriteArray(Item: array of TGStreamItem); virtual; abstract;
     15  function Read: TGStreamItem; virtual; abstract;
     16  function ReadArray(Count: TGStreamIndex): TGStreamItemArray; virtual; abstract;
     17  function Insert(Count: TGStreamIndex): TGStreamIndex; virtual; abstract;
     18  function Remove(Count: TGStreamIndex): TGStreamIndex; virtual; abstract;
     19  function Seek(Offset: TGStreamIndex; Origin: TSeekOrigin = soCurrent):
     20    TGStreamIndex; virtual; abstract;
     21  constructor Create; virtual;
     22  property Position: TGStreamIndex read GetPosition write SetPosition;
     23  property Size: TGStreamIndex read GetSize write SetSize;
    1024end;
    1125
     
    1529{$IFDEF IMPLEMENTATION}
    1630
    17 procedure TGStream.Write(Item: TGStreamItem);
     31procedure TGStream.Assign(Source: TGStream);
    1832begin
    19   if Assigned(FOnData) then
    20     FOnData(Item);
    2133end;
    2234
     35procedure TGStream.SetPosition(AValue: TGStreamIndex);
     36begin
     37  Seek(AValue, soBegin);
     38end;
     39
     40function TGStream.GetPosition: TGStreamIndex;
     41begin
     42  Result := Seek(0, soCurrent);
     43end;
     44
     45procedure TGStream.SetSize(AValue: TGStreamIndex);
     46var
     47  StreamSize: TGStreamIndex;
     48  OldPosition: TGStreamIndex;
     49begin
     50  OldPosition := Seek(0, soCurrent);
     51  StreamSize := Size;
     52  if AValue > StreamSize then begin
     53    Seek(StreamSize, soBegin);
     54    Insert(AValue - StreamSize);
     55  end else
     56  if AValue < StreamSize then begin
     57    Seek(AValue, soBegin);
     58    Remove(StreamSize - AValue);
     59  end;
     60  Position := OldPosition;
     61end;
     62
     63function TGStream.GetSize: TGStreamIndex;
     64var
     65  OldPosition: Integer;
     66begin
     67  OldPosition := Position;
     68  Result := Seek(0, soEnd);
     69  Position := OldPosition;
     70end;
     71
     72constructor TGStream.Create;
     73begin
     74  inherited;
     75end;
    2376
    2477{$UNDEF IMPLEMENTATION}
Note: See TracChangeset for help on using the changeset viewer.