Changeset 320 for Generics/NativeGenerics/Units/GenericStream.pas
- Timestamp:
- Feb 7, 2012, 2:03:20 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Units/GenericStream.pas
r313 r320 1 1 unit GenericStream; 2 2 3 {$mode Delphi}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils;8 SysUtils, Classes, GenericList; 9 9 10 10 type 11 11 TGStream<TItem> = class 12 public 13 type 14 TIndex = NativeInt; 15 TItemArray = array of TItem; 16 TSeekOrigin = (soBeginning, soCurrent, soEnd); 17 private 18 procedure SetSize(AValue: TIndex); 19 function GetSize: TIndex; 20 procedure SetPosition(AValue: TIndex); 21 function GetPosition: TIndex; 22 public 23 procedure Assign(Source: TGStream<TItem>); virtual; 24 procedure Write(Item: TItem); virtual; abstract; 25 procedure WriteArray(Item: array of TItem); virtual; abstract; 26 function Read: TItem; virtual; abstract; 27 function ReadArray(Count: TIndex): TItemArray; virtual; abstract; 28 function Insert(Count: TIndex): TIndex; virtual; abstract; 29 function Remove(Count: TIndex): TIndex; virtual; abstract; 30 function Seek(Offset: TIndex; Origin: TSeekOrigin = soCurrent): 31 TIndex; virtual; abstract; 32 constructor Create; virtual; 33 property Position: TIndex read GetPosition write SetPosition; 34 property Size: TIndex read GetSize write SetSize; 35 end; 12 36 13 end;14 37 15 38 implementation 16 39 40 41 procedure TGStream<TItem>.Assign(Source: TGStream<TItem>); 42 begin 43 end; 44 45 procedure TGStream<TItem>.SetPosition(AValue: TIndex); 46 begin 47 Seek(AValue, soBeginning); 48 end; 49 50 function TGStream<TItem>.GetPosition: TIndex; 51 begin 52 Result := Seek(0, soCurrent); 53 end; 54 55 procedure TGStream<TItem>.SetSize(AValue: TIndex); 56 var 57 StreamSize: TIndex; 58 OldPosition: TIndex; 59 begin 60 OldPosition := Seek(0, soCurrent); 61 StreamSize := Size; 62 if AValue > StreamSize then begin 63 Seek(StreamSize, soBeginning); 64 Insert(AValue - StreamSize); 65 end else 66 if AValue < StreamSize then begin 67 Seek(AValue, soBeginning); 68 Remove(StreamSize - AValue); 69 end; 70 Position := OldPosition; 71 end; 72 73 function TGStream<TItem>.GetSize: TIndex; 74 var 75 OldPosition: Integer; 76 begin 77 OldPosition := Position; 78 Result := Seek(0, soEnd); 79 Position := OldPosition; 80 end; 81 82 constructor TGStream<TItem>.Create; 83 begin 84 inherited; 85 end; 86 17 87 end. 18
Note:
See TracChangeset
for help on using the changeset viewer.