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