Changeset 312 for Generics/TemplateGenerics/Generic/GenericStream.inc
- Timestamp:
- Jan 9, 2012, 2:22:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/GenericStream.inc
r226 r312 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 function Read: TGStreamItem; virtual; abstract; 16 function ReadArray(Count: TGStreamIndex): TGStreamItemArray; virtual; abstract; 17 function Insert(Count: TGStreamIndex): TGStreamIndex; virtual; abstract; 18 function Remove(Count: TGStreamIndex): TGStreamIndex; virtual; abstract; 19 function Seek(Offset: TGStreamIndex; Origin: TSeekOrigin = soCurrent): 20 TGStreamIndex; virtual; abstract; 21 constructor Create; virtual; 22 property Position: TGStreamIndex read GetPosition write SetPosition; 23 property Size: TGStreamIndex read GetSize write SetSize; 10 24 end; 11 25 … … 15 29 {$IFDEF IMPLEMENTATION} 16 30 17 procedure TGStream. Write(Item: TGStreamItem);31 procedure TGStream.Assign(Source: TGStream); 18 32 begin 19 if Assigned(FOnData) then20 FOnData(Item);21 33 end; 22 34 35 procedure TGStream.SetPosition(AValue: TGStreamIndex); 36 begin 37 Seek(AValue, soBegin); 38 end; 39 40 function TGStream.GetPosition: TGStreamIndex; 41 begin 42 Result := Seek(0, soCurrent); 43 end; 44 45 procedure TGStream.SetSize(AValue: TGStreamIndex); 46 var 47 StreamSize: TGStreamIndex; 48 OldPosition: TGStreamIndex; 49 begin 50 OldPosition := Seek(0, soCurrent); 51 StreamSize := Size; 52 if AValue > StreamSize then begin 53 Seek(StreamSize, soBegin); 54 Insert(AValue - StreamSize); 55 end else 56 if AValue < StreamSize then begin 57 Seek(AValue, soBegin); 58 Remove(StreamSize - AValue); 59 end; 60 Position := OldPosition; 61 end; 62 63 function TGStream.GetSize: TGStreamIndex; 64 var 65 OldPosition: Integer; 66 begin 67 OldPosition := Position; 68 Result := Seek(0, soEnd); 69 Position := OldPosition; 70 end; 71 72 constructor TGStream.Create; 73 begin 74 inherited; 75 end; 23 76 24 77 {$UNDEF IMPLEMENTATION}
Note:
See TracChangeset
for help on using the changeset viewer.