source: trunk/Packages/TemplateGenerics/Generic/GenericStream.inc

Last change on this file was 30, checked in by chronos, 12 years ago
  • Updated: Component versions.
  • Added: Missing forms.
File size: 2.2 KB
Line 
1{$IFDEF INTERFACE}
2
3TGStreamItemArray = array of TGStreamItem;
4
5// TGStream<TGStreamIndex, TGStreamItem> = class
6TGStream = class
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 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;
26end;
27
28{$UNDEF INTERFACE}
29{$ENDIF}
30
31{$IFDEF IMPLEMENTATION}
32
33procedure TGStream.Assign(Source: TGStream);
34begin
35end;
36
37procedure TGStream.SetPosition(AValue: TGStreamIndex);
38begin
39 Seek(AValue, soBegin);
40end;
41
42function TGStream.GetPosition: TGStreamIndex;
43begin
44 Result := Seek(0, soCurrent);
45end;
46
47procedure TGStream.SetSize(AValue: TGStreamIndex);
48var
49 StreamSize: TGStreamIndex;
50 OldPosition: TGStreamIndex;
51begin
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;
63end;
64
65function TGStream.GetSize: TGStreamIndex;
66var
67 OldPosition: Integer;
68begin
69 OldPosition := Position;
70 Result := Seek(0, soEnd);
71 Position := OldPosition;
72end;
73
74constructor TGStream.Create;
75begin
76 inherited;
77end;
78
79{$UNDEF IMPLEMENTATION}
80{$ENDIF}
Note: See TracBrowser for help on using the repository browser.