Changeset 233 for CoolStreaming/UStreamHelper.pas
- Timestamp:
- Apr 14, 2011, 12:51:20 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/UStreamHelper.pas
r172 r233 6 6 7 7 uses 8 Classes, DateUtils, syncobjs , UMicroThreading;8 Classes, DateUtils, syncobjs; 9 9 10 10 type … … 19 19 FEndianness: TEndianness; 20 20 SwapData: Boolean; 21 function GetItem(Index: Integer): Byte; 21 22 procedure SetEndianness(const AValue: TEndianness); 23 procedure SetItem(Index: Integer; const AValue: Byte); 22 24 public 23 25 procedure WriteByte(Data: Byte); … … 50 52 constructor Create; overload; 51 53 constructor Create(AStream: TStream); overload; 54 procedure Clear; 52 55 destructor Destroy; override; 53 56 function GetSize: Int64; override; … … 58 61 property Endianness: TEndianness read FEndianness write SetEndianness; 59 62 property Stream: TStream read FStream write FStream; 60 end; 61 62 { TThreadStreamHelper } 63 64 TThreadStreamHelper = class(TStreamHelper) 65 Lock: TMicroThreadCriticalSection; 66 procedure Clear; 67 constructor Create; 68 destructor Destroy; override; 63 property Items[Index: Integer]: Byte read GetItem write SetItem; default; 69 64 end; 70 65 … … 195 190 end; 196 191 192 procedure TStreamHelper.Clear; 193 begin 194 Stream.Size := 0; 195 end; 196 197 197 destructor TStreamHelper.Destroy; 198 198 begin … … 273 273 end; 274 274 275 function TStreamHelper.GetItem(Index: Integer): Byte; 276 begin 277 Position := Index; 278 Result := ReadByte; 279 end; 280 281 procedure TStreamHelper.SetItem(Index: Integer; const AValue: Byte); 282 begin 283 Position := Index; 284 WriteByte(AValue); 285 end; 286 275 287 procedure TStreamHelper.WriteAnsiString(Data: string); 276 288 var … … 348 360 end; 349 361 350 { TThreadStreamHelper }351 352 procedure TThreadStreamHelper.Clear;353 begin354 try355 Lock.Acquire;356 Size := 0;357 finally358 Lock.Release;359 end;360 end;361 362 constructor TThreadStreamHelper.Create;363 begin364 inherited Create;365 Lock := TMicroThreadCriticalSection.Create;366 end;367 368 destructor TThreadStreamHelper.Destroy;369 begin370 Lock.Free;371 inherited Destroy;372 end;373 362 374 363 end.
Note:
See TracChangeset
for help on using the changeset viewer.