Changeset 90 for trunk/Packages/TemplateGenerics/Generic/GenericStream.inc
- Timestamp:
- Sep 7, 2012, 6:45:53 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/TemplateGenerics/Generic/GenericStream.inc
r84 r90 1 1 {$IFDEF INTERFACE} 2 2 3 TGStream DataEvent = procedure (Item: TGStreamItem) of object;3 TGStreamItemArray = array of TGStreamItem; 4 4 5 // TGStream<T StreamItem> = class5 // TGStream<TGStreamIndex, TGStreamItem> = class 6 6 TGStream = class 7 FOnData: TGStreamDataEvent; 8 procedure Write(Item: TStreamItem); 9 property OnData: TGStreamDataEvent read FOnData write FOnData; 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; 10 26 end; 11 27 … … 15 31 {$IFDEF IMPLEMENTATION} 16 32 17 procedure TGStream. Write(Item: TGStreamItem);33 procedure TGStream.Assign(Source: TGStream); 18 34 begin 19 if Assigned(FOnData) then20 FOnData(Item);21 35 end; 22 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; 23 78 24 79 {$UNDEF IMPLEMENTATION}
Note:
See TracChangeset
for help on using the changeset viewer.