Keyword mapping refactoring
This commit is contained in:
@@ -143,6 +143,7 @@ type
|
||||
// A field definition for a scalar record.
|
||||
TScalarRecordField = TPair<IKeyword, TScalar.TKind>;
|
||||
IScalarRecordDefinition = IKeywordMapping<TScalar.TKind>;
|
||||
IScalarRecord = IKeywordMapping<TScalar>;
|
||||
TScalarRecordRegistry = TKeywordMappingRegistry<TScalar.TKind>;
|
||||
|
||||
// A record of scalar values, based on a definition.
|
||||
@@ -804,7 +805,7 @@ end;
|
||||
|
||||
constructor TScalarRecord.Create(const ADef: IScalarRecordDefinition; const AFields: TArray<TScalar.TValue>);
|
||||
begin
|
||||
Assert(Length(ADef.Fields) = Length(AFields), 'Field definition and value count must match.');
|
||||
Assert(ADef.Count = Length(AFields), 'Field definition and value count must match.');
|
||||
FDef := ADef;
|
||||
FFields := AFields;
|
||||
end;
|
||||
@@ -827,17 +828,17 @@ begin
|
||||
if idx < 0 then
|
||||
raise EArgumentException.CreateFmt('Field ":%s" not found in record definition.', [Key.Name]);
|
||||
|
||||
Result.Create(FDef.Fields[idx].Value, FFields[idx]);
|
||||
Result.Create(FDef[idx].Value, FFields[idx]);
|
||||
end;
|
||||
|
||||
{ TScalarRecordSeries }
|
||||
|
||||
constructor TScalarRecordSeries.Create(const ADef: IScalarRecordDefinition);
|
||||
begin
|
||||
Assert(Length(ADef.Fields) > 0);
|
||||
Assert(ADef.Count > 0);
|
||||
FDef := ADef;
|
||||
FTotalCount := 0;
|
||||
SetLength(FFields, Length(FDef.Fields));
|
||||
SetLength(FFields, FDef.Count);
|
||||
for var i := 0 to High(FFields) do
|
||||
FFields[i] := TMemberSeries.Create(Self, i);
|
||||
end;
|
||||
@@ -851,7 +852,7 @@ end;
|
||||
|
||||
procedure TScalarRecordSeries.Add(const Item: TScalarRecord; Lookback: Int64 = -1);
|
||||
begin
|
||||
FArray.Add(Item.Fields, Length(FDef.Fields) * Lookback);
|
||||
FArray.Add(Item.Fields, FDef.Count * Integer(Lookback));
|
||||
inc(FTotalCount);
|
||||
end;
|
||||
|
||||
@@ -862,7 +863,7 @@ type
|
||||
var
|
||||
len: Integer;
|
||||
begin
|
||||
len := Length(FDef.Fields);
|
||||
len := FDef.Count;
|
||||
// Use Slice to pass the raw data as an open array without copying.
|
||||
FArray.Add(Slice(PValueArr(@Data)^, len), len * Integer(Lookback));
|
||||
inc(FTotalCount);
|
||||
@@ -879,7 +880,7 @@ end;
|
||||
|
||||
function TScalarRecordSeries.GetCount: Int64;
|
||||
begin
|
||||
Result := FArray.Count div Length(FDef.Fields);
|
||||
Result := FArray.Count div FDef.Count;
|
||||
end;
|
||||
|
||||
function TScalarRecordSeries.GetDef: IScalarRecordDefinition;
|
||||
@@ -889,7 +890,7 @@ end;
|
||||
|
||||
function TScalarRecordSeries.GetItemRef(Idx: Integer): TChunkArray<TScalar.TValue>.PT;
|
||||
begin
|
||||
var len := Length(FDef.Fields);
|
||||
var len := FDef.Count;
|
||||
Result := FArray.ItemRef[(FArray.Count - len) - (Idx * len)];
|
||||
end;
|
||||
|
||||
@@ -958,7 +959,7 @@ end;
|
||||
constructor TScalarRecordSeries.TMemberSeries.Create(ARecordSeries: TScalarRecordSeries; AElementIdx: Integer);
|
||||
begin
|
||||
inherited Create(ARecordSeries);
|
||||
FKind := ARecordSeries.FDef.Fields[AElementIdx].Value;
|
||||
FKind := ARecordSeries.FDef[AElementIdx].Value;
|
||||
FOffset := sizeof(TScalar.TValue) * AElementIdx;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user