Ignore:
Timestamp:
Apr 3, 2012, 7:35:26 AM (13 years ago)
Author:
chronos
Message:
  • Added: Update locking support for TGList.
  • Modified: Enhanced TGStream methods.
Location:
Generics/TemplateGenerics/Specialized
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Specialized/SpecializedList.pas

    r304 r342  
    9595  procedure AddStream(Stream: TStream);
    9696  procedure AddStreamPart(Stream: TStream; ItemCount: TGListIndex);
     97  procedure WriteBuffer(var Buffer; Count: Integer);
     98  procedure ReadBuffer(var Buffer; Count: Integer);
    9799end;
    98100
     
    417419end;
    418420
     421procedure TListByte.WriteBuffer(var Buffer; Count: Integer);
     422begin
     423
     424end;
     425
     426procedure TListByte.ReadBuffer(var Buffer; Count: Integer);
     427begin
     428
     429end;
     430
    419431end.
  • Generics/TemplateGenerics/Specialized/SpecializedStream.pas

    r312 r342  
    66
    77uses
    8   Classes, SysUtils, SpecializedList;
     8  Classes, SysUtils, SpecializedList, DateUtils;
    99
    1010type
     
    2929{$DEFINE TGStreamItem := Byte}
    3030{$DEFINE TGStreamList := TListStreamByte}
    31 {$DEFINE TGStream := TStreamByte}
     31{$DEFINE TGStream := TBaseStreamByte}
    3232{$DEFINE TGStreamSortCompare := TStreamByteSortCompare}
    3333{$DEFINE TGStreamToStringConverter := TStreamByteToStringConverter}
     
    4949{$I 'GenericStream.inc'}
    5050
     51  TStreamByte = class(TBaseStreamByte)
     52    function ReadBuffer(var Buffer; Count: Integer): Integer; virtual; abstract;
     53    function WriteBuffer(var Buffer; Count: Integer): Integer; virtual; abstract;
     54  end;
     55
     56  { TMemoryStreamByte }
     57
     58  TMemoryStreamByte = class(TStreamByte)
     59  private
     60    FList: TListByte;
     61    FOwnsList: Boolean;
     62    FPosition: Integer;
     63  public
     64    procedure Assign(Source: TBaseStreamByte); override;
     65    procedure Write(Item: Byte); override;
     66    procedure WriteArray(Values: array of Byte); override;
     67    procedure WriteList(List: TListByte);
     68    function WriteBuffer(var Buffer; Count: Integer): Integer; override;
     69    procedure WriteStream(Stream: TBaseStreamByte; Count: Integer); override;
     70    function Read: Byte; override;
     71    function ReadArray(Count: Integer): TStreamByteItemArray; override;
     72    function ReadList(List: TListByte; Count: Integer): Integer;
     73    function ReadBuffer(var Buffer; Count: Integer): Integer; override;
     74    function ReadStream(Stream: TBaseStreamByte; Count: Integer): Integer; override;
     75    function Insert(Count: Integer): Integer; override;
     76    function Remove(Count: Integer): Integer; override;
     77    function Seek(Offset: Integer; Origin: TSeekOrigin = soCurrent): Integer; override;
     78    constructor Create; override; overload;
     79    constructor Create(AList: TListByte); overload;
     80    destructor Destroy; override;
     81    property OwnsList: Boolean read FOwnsList write FOwnsList;
     82    property List: TListByte read FList;
     83  end;
     84
     85
     86implementation
     87
    5188{ TMemoryStreamByte }
    5289
    53 TMemoryStreamByte = class(TStreamByte)
    54 private
    55   FList: TListByte;
    56   FPosition: Integer;
    57 public
    58   procedure Assign(Source: TStreamByte); override;
    59   procedure Write(Item: Byte); override;
    60   procedure WriteArray(Values: array of Byte); override;
    61   procedure WriteList(List: TListByte);
    62   function Read: Byte; override;
    63   function ReadArray(Count: Integer): TStreamByteItemArray; override;
    64   function ReadList(List: TListByte; Count: Integer): Integer;
    65   function Insert(Count: Integer): Integer; override;
    66   function Remove(Count: Integer): Integer; override;
    67   function Seek(Offset: Integer; Origin: TSeekOrigin = soCurrent): Integer; override;
    68   constructor Create; override;
    69   destructor Destroy; override;
    70   property List: TListByte read FList;
    71 end;
    72 
    73 
    74 implementation
    75 
    76 { TMemoryStreamByte }
    77 
    78 procedure TMemoryStreamByte.Assign(Source: TStreamByte);
     90procedure TMemoryStreamByte.Assign(Source: TBaseStreamByte);
    7991begin
    8092  inherited;
     
    106118end;
    107119
     120procedure TMemoryStreamByte.WriteStream(Stream: TBaseStreamByte; Count: Integer);
     121begin
     122
     123end;
     124
     125function TMemoryStreamByte.WriteBuffer(var Buffer; Count: Integer): Integer;
     126begin
     127
     128end;
     129
    108130function TMemoryStreamByte.Read: Byte;
    109131begin
     
    125147end;
    126148
     149function TMemoryStreamByte.ReadBuffer(var Buffer; Count: Integer): Integer;
     150begin
     151
     152end;
     153
     154function TMemoryStreamByte.ReadStream(Stream: TBaseStreamByte; Count: Integer
     155  ): Integer;
     156begin
     157
     158end;
     159
    127160function TMemoryStreamByte.Insert(Count: Integer): Integer;
    128161begin
     
    154187  inherited;
    155188  FList := TListByte.Create;
     189  OwnsList := True;
     190end;
     191
     192constructor TMemoryStreamByte.Create(AList: TListByte);
     193begin
     194  inherited Create;
     195  FList := AList;
     196  OwnsList := False;
    156197end;
    157198
    158199destructor TMemoryStreamByte.Destroy;
    159200begin
    160   FList.Free;
     201  if OwnsList then FList.Free;
    161202  inherited Destroy;
    162203end;
     
    181222{$DEFINE TGStreamItem := Byte}
    182223{$DEFINE TGStreamList := TListStreamByte}
    183 {$DEFINE TGStream := TStreamByte}
     224{$DEFINE TGStream := TBaseStreamByte}
    184225{$DEFINE TGStreamSortCompare := TStreamByteSortCompare}
    185226{$DEFINE TGStreamToStringConverter := TStreamByteToStringConverter}
     
    200241{$DEFINE IMPLEMENTATION}
    201242{$I 'GenericStream.inc'}
     243
     244
     245
    202246end.
Note: See TracChangeset for help on using the changeset viewer.