RTL custom interface types as records
This commit is contained in:
@@ -28,15 +28,11 @@ type
|
||||
RecCount: Integer;
|
||||
end;
|
||||
|
||||
// Converts a TScalarBatch into a stream of IScalarRecord events using the cursor pattern.
|
||||
// NOTE: This uses a zero-copy approach. Consumers must process data synchronously or copy it.
|
||||
TScalarBatchUnpacker = class(TMycConverter<TScalarBatch, IScalarRecord>)
|
||||
private
|
||||
FDef: IScalarRecordDefinition;
|
||||
protected
|
||||
function Consume(const Value: TScalarBatch): TState; override;
|
||||
public
|
||||
constructor Create(const ADef: IScalarRecordDefinition);
|
||||
IBroker = interface
|
||||
function GetEquity: Double;
|
||||
procedure Buy(Count: Integer);
|
||||
procedure Sell(Count: Integer);
|
||||
property Equity: Double read GetEquity;
|
||||
end;
|
||||
|
||||
IScalarBatchLoader = interface
|
||||
@@ -220,39 +216,6 @@ begin
|
||||
Result := FDef.IndexOf(Key);
|
||||
end;
|
||||
|
||||
{ TScalarBatchUnpacker }
|
||||
|
||||
constructor TScalarBatchUnpacker.Create(const ADef: IScalarRecordDefinition);
|
||||
begin
|
||||
inherited Create;
|
||||
FDef := ADef;
|
||||
end;
|
||||
|
||||
function TScalarBatchUnpacker.Consume(const Value: TScalarBatch): TState;
|
||||
begin
|
||||
if (Length(Value.Data) > 0) and (Value.RecCount > 0) then
|
||||
begin
|
||||
var Stride := Length(Value.Data) div Value.RecCount;
|
||||
var pCursor: TScalar.PValue := @Value.Data[0];
|
||||
|
||||
// Initialize reused View object (Cursor Pattern)
|
||||
// This object implements IScalarRecord and is updated for each tick.
|
||||
var ViewObj := TScalarRecordView.Create(FDef);
|
||||
var View := ViewObj as IScalarRecord;
|
||||
|
||||
for var i := 0 to Value.RecCount - 1 do
|
||||
begin
|
||||
ViewObj.SetData(pCursor);
|
||||
|
||||
// Broadcast to all listeners
|
||||
Broadcast(View);
|
||||
|
||||
Inc(pCursor, Stride);
|
||||
end;
|
||||
end;
|
||||
Result := TState.Null;
|
||||
end;
|
||||
|
||||
{ TScalarBatchLoader.TDataFile }
|
||||
|
||||
constructor TScalarBatchLoader.TDataFile.Create(const APath, ASymbol, AExtension: String; AYear, AMonth: Integer; const ABasename: String);
|
||||
|
||||
Reference in New Issue
Block a user