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

Last change on this file was 1, checked in by chronos, 8 years ago
  • Imported initial version.
File size: 2.2 KB
Line 
1{$IFDEF INTERFACE}
2
3
4// TGStream<TGStreamIndex, TGStreamItem> = class
5TGStream = class
6public
7 type
8 TItemArray = array of TGStreamItem;
9private
10procedure SetSize(AValue: TGStreamIndex);
11 function GetSize: TGStreamIndex;
12 procedure SetPosition(AValue: TGStreamIndex);
13 function GetPosition: TGStreamIndex;
14public
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;
29end;
30
31{$UNDEF INTERFACE}
32{$ENDIF}
33
34{$IFDEF IMPLEMENTATION}
35
36procedure TGStream.Assign(Source: TGStream);
37begin
38end;
39
40procedure TGStream.SetPosition(AValue: TGStreamIndex);
41begin
42 Seek(AValue, soBegin);
43end;
44
45function TGStream.GetPosition: TGStreamIndex;
46begin
47 Result := Seek(0, soCurrent);
48end;
49
50procedure TGStream.SetSize(AValue: TGStreamIndex);
51var
52 StreamSize: TGStreamIndex;
53 OldPosition: TGStreamIndex;
54begin
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;
66end;
67
68function TGStream.GetSize: TGStreamIndex;
69var
70 OldPosition: Integer;
71begin
72 OldPosition := Position;
73 Result := Seek(0, soEnd);
74 Position := OldPosition;
75end;
76
77constructor TGStream.Create;
78begin
79 inherited;
80end;
81
82{$UNDEF IMPLEMENTATION}
83{$ENDIF}
Note: See TracBrowser for help on using the repository browser.