| 1 | {$IFDEF INTERFACE} | 
|---|
| 2 |  | 
|---|
| 3 | TGStreamItemArray = array of TGStreamItem; | 
|---|
| 4 |  | 
|---|
| 5 | // TGStream<TGStreamIndex, TGStreamItem> = class | 
|---|
| 6 | TGStream = class | 
|---|
| 7 | procedure SetSize(AValue: TGStreamIndex); | 
|---|
| 8 | function GetSize: TGStreamIndex; | 
|---|
| 9 | procedure SetPosition(AValue: TGStreamIndex); | 
|---|
| 10 | function GetPosition: TGStreamIndex; | 
|---|
| 11 | public | 
|---|
| 12 | procedure Assign(Source: TGStream); virtual; | 
|---|
| 13 | procedure Write(Item: TGStreamItem); virtual; abstract; | 
|---|
| 14 | procedure WriteArray(Item: array of TGStreamItem); virtual; abstract; | 
|---|
| 15 | procedure WriteStream(Stream: TGStream; Count: TGStreamIndex); virtual; abstract; | 
|---|
| 16 | function Read: TGStreamItem; virtual; abstract; | 
|---|
| 17 | function ReadArray(Count: TGStreamIndex): TGStreamItemArray; virtual; abstract; | 
|---|
| 18 | function ReadStream(Stream: TGStream; Count: TGStreamIndex): TGStreamIndex; virtual; abstract; | 
|---|
| 19 | function Insert(Count: TGStreamIndex): TGStreamIndex; virtual; abstract; | 
|---|
| 20 | function Remove(Count: TGStreamIndex): TGStreamIndex; virtual; abstract; | 
|---|
| 21 | function Seek(Offset: TGStreamIndex; Origin: TSeekOrigin = soCurrent): | 
|---|
| 22 | TGStreamIndex; virtual; abstract; | 
|---|
| 23 | constructor Create; virtual; | 
|---|
| 24 | property Position: TGStreamIndex read GetPosition write SetPosition; | 
|---|
| 25 | property Size: TGStreamIndex read GetSize write SetSize; | 
|---|
| 26 | end; | 
|---|
| 27 |  | 
|---|
| 28 | {$UNDEF INTERFACE} | 
|---|
| 29 | {$ENDIF} | 
|---|
| 30 |  | 
|---|
| 31 | {$IFDEF IMPLEMENTATION} | 
|---|
| 32 |  | 
|---|
| 33 | procedure TGStream.Assign(Source: TGStream); | 
|---|
| 34 | begin | 
|---|
| 35 | end; | 
|---|
| 36 |  | 
|---|
| 37 | procedure TGStream.SetPosition(AValue: TGStreamIndex); | 
|---|
| 38 | begin | 
|---|
| 39 | Seek(AValue, soBegin); | 
|---|
| 40 | end; | 
|---|
| 41 |  | 
|---|
| 42 | function TGStream.GetPosition: TGStreamIndex; | 
|---|
| 43 | begin | 
|---|
| 44 | Result := Seek(0, soCurrent); | 
|---|
| 45 | end; | 
|---|
| 46 |  | 
|---|
| 47 | procedure TGStream.SetSize(AValue: TGStreamIndex); | 
|---|
| 48 | var | 
|---|
| 49 | StreamSize: TGStreamIndex; | 
|---|
| 50 | OldPosition: TGStreamIndex; | 
|---|
| 51 | begin | 
|---|
| 52 | OldPosition := Seek(0, soCurrent); | 
|---|
| 53 | StreamSize := Size; | 
|---|
| 54 | if AValue > StreamSize then begin | 
|---|
| 55 | Seek(StreamSize, soBegin); | 
|---|
| 56 | Insert(AValue - StreamSize); | 
|---|
| 57 | end else | 
|---|
| 58 | if AValue < StreamSize then begin | 
|---|
| 59 | Seek(AValue, soBegin); | 
|---|
| 60 | Remove(StreamSize - AValue); | 
|---|
| 61 | end; | 
|---|
| 62 | Position := OldPosition; | 
|---|
| 63 | end; | 
|---|
| 64 |  | 
|---|
| 65 | function TGStream.GetSize: TGStreamIndex; | 
|---|
| 66 | var | 
|---|
| 67 | OldPosition: Integer; | 
|---|
| 68 | begin | 
|---|
| 69 | OldPosition := Position; | 
|---|
| 70 | Result := Seek(0, soEnd); | 
|---|
| 71 | Position := OldPosition; | 
|---|
| 72 | end; | 
|---|
| 73 |  | 
|---|
| 74 | constructor TGStream.Create; | 
|---|
| 75 | begin | 
|---|
| 76 | inherited; | 
|---|
| 77 | end; | 
|---|
| 78 |  | 
|---|
| 79 | {$UNDEF IMPLEMENTATION} | 
|---|
| 80 | {$ENDIF} | 
|---|