Changeset 323 for Generics/NativeGenerics/Units/GenericStream.pas
- Timestamp:
- Feb 8, 2012, 9:52:27 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Units/GenericStream.pas
r322 r323 9 9 10 10 type 11 TG Stream<TItem> = class11 TGAbstractStream<TItem> = class 12 12 public 13 13 type … … 21 21 function GetPosition: TIndex; 22 22 public 23 procedure Assign(Source: TG Stream<TItem>); virtual;23 procedure Assign(Source: TGAbstractStream<TItem>); virtual; 24 24 procedure Write(Item: TItem); virtual; abstract; 25 25 procedure WriteArray(Item: array of TItem); virtual; abstract; … … 36 36 end; 37 37 38 TG MemoryStream<TItem> = class(TGStream<TItem>)38 TGStream<TItem> = class(TGAbstractStream<TItem>) 39 39 private 40 40 FList: TGList<TItem>; 41 41 FPosition: TIndex; 42 42 public 43 procedure Assign(Source: TG Stream<TItem>); override;43 procedure Assign(Source: TGAbstractStream<TItem>); override; 44 44 procedure Write(Item: TItem); override; 45 45 procedure WriteArray(Values: array of TItem); override; … … 62 62 { TGStream } 63 63 64 procedure TG Stream<TItem>.Assign(Source: TGStream<TItem>);64 procedure TGAbstractStream<TItem>.Assign(Source: TGAbstractStream<TItem>); 65 65 begin 66 66 end; 67 67 68 procedure TG Stream<TItem>.SetPosition(AValue: TIndex);68 procedure TGAbstractStream<TItem>.SetPosition(AValue: TIndex); 69 69 begin 70 70 Seek(AValue, soBeginning); 71 71 end; 72 72 73 function TG Stream<TItem>.GetPosition: TIndex;73 function TGAbstractStream<TItem>.GetPosition: TIndex; 74 74 begin 75 75 Result := Seek(0, soCurrent); 76 76 end; 77 77 78 procedure TG Stream<TItem>.SetSize(AValue: TIndex);78 procedure TGAbstractStream<TItem>.SetSize(AValue: TIndex); 79 79 var 80 80 StreamSize: TIndex; … … 94 94 end; 95 95 96 function TG Stream<TItem>.GetSize: TIndex;96 function TGAbstractStream<TItem>.GetSize: TIndex; 97 97 var 98 98 OldPosition: Integer; … … 103 103 end; 104 104 105 constructor TG Stream<TItem>.Create;105 constructor TGAbstractStream<TItem>.Create; 106 106 begin 107 107 inherited; 108 108 end; 109 109 110 { T MemoryStreamByte}110 { TGStream } 111 111 112 procedure TG MemoryStream<TItem>.Assign(Source: TGStream<TItem>);112 procedure TGStream<TItem>.Assign(Source: TGAbstractStream<TItem>); 113 113 begin 114 114 inherited; 115 if Source is TG MemoryStream<TItem> then begin116 FList.Assign(TG MemoryStream<TItem>(Source).FList);117 FPosition := TG MemoryStream<TItem>(Source).FPosition;115 if Source is TGStream<TItem> then begin 116 FList.Assign(TGStream<TItem>(Source).FList); 117 FPosition := TGStream<TItem>(Source).FPosition; 118 118 end; 119 119 end; 120 120 121 procedure TG MemoryStream<TItem>.Write(Item: TItem);121 procedure TGStream<TItem>.Write(Item: TItem); 122 122 begin 123 123 if FList.Count < (FPosition + 1) then … … 127 127 end; 128 128 129 procedure TG MemoryStream<TItem>.WriteArray(Values: array of TItem);129 procedure TGStream<TItem>.WriteArray(Values: array of TItem); 130 130 begin 131 131 if FList.Count < (FPosition + Length(Values)) then … … 135 135 end; 136 136 137 procedure TG MemoryStream<TItem>.WriteList(List: TGList<TItem>);137 procedure TGStream<TItem>.WriteList(List: TGList<TItem>); 138 138 begin 139 139 FList.ReplaceList(FPosition, List); 140 140 end; 141 141 142 function TG MemoryStream<TItem>.Read: TItem;142 function TGStream<TItem>.Read: TItem; 143 143 begin 144 144 Result := FList[FPosition]; … … 146 146 end; 147 147 148 function TG MemoryStream<TItem>.ReadArray(Count: TIndex): TItemArray;148 function TGStream<TItem>.ReadArray(Count: TIndex): TItemArray; 149 149 begin 150 150 Result := FList.GetArray(FPosition, Count); 151 151 end; 152 152 153 function TG MemoryStream<TItem>.ReadList(List: TGList<TItem>; Count: TIndex): TIndex;153 function TGStream<TItem>.ReadList(List: TGList<TItem>; Count: TIndex): TIndex; 154 154 begin 155 155 if (FPosition + Count) > FList.Count then … … 159 159 end; 160 160 161 function TG MemoryStream<TItem>.Insert(Count: TIndex): TIndex;161 function TGStream<TItem>.Insert(Count: TIndex): TIndex; 162 162 begin 163 163 FList.InsertCount(FPosition, Count); … … 165 165 end; 166 166 167 function TG MemoryStream<TItem>.Remove(Count: TIndex): TIndex;167 function TGStream<TItem>.Remove(Count: TIndex): TIndex; 168 168 begin 169 169 Result := FList.Count - FPosition; … … 172 172 end; 173 173 174 function TG MemoryStream<TItem>.Seek(Offset: TIndex; Origin: TSeekOrigin): TIndex;174 function TGStream<TItem>.Seek(Offset: TIndex; Origin: TSeekOrigin): TIndex; 175 175 begin 176 176 case Origin of … … 184 184 end; 185 185 186 constructor TG MemoryStream<TItem>.Create;186 constructor TGStream<TItem>.Create; 187 187 begin 188 188 inherited; … … 190 190 end; 191 191 192 destructor TG MemoryStream<TItem>.Destroy;192 destructor TGStream<TItem>.Destroy; 193 193 begin 194 194 FList.Free;
Note:
See TracChangeset
for help on using the changeset viewer.