Refactoring Keyword mapping, introducing tuples
This commit is contained in:
@@ -136,14 +136,7 @@ type
|
||||
TScalarRecordField = TPair<IKeyword, TScalar.TKind>;
|
||||
IScalarRecordDefinition = IKeywordMapping<TScalar.TKind>;
|
||||
|
||||
IScalarRecord = interface(IKeywordMapping<TScalar>)
|
||||
{$region 'private'}
|
||||
function GetDef: IScalarRecordDefinition;
|
||||
{$endregion}
|
||||
property Def: IScalarRecordDefinition read GetDef;
|
||||
end;
|
||||
|
||||
TScalarRecord = class(TInterfacedObject, IKeywordMapping<TScalar>, IScalarRecord)
|
||||
TScalarRecord = class(TInterfacedObject, IKeywordMapping<TScalar>)
|
||||
type
|
||||
TRegistry = TKeywordMappingRegistry<TScalar.TKind>;
|
||||
private
|
||||
@@ -152,12 +145,11 @@ type
|
||||
|
||||
function IndexOf(const Key: IKeyword): Integer;
|
||||
function GetCount: Integer;
|
||||
function GetDef: IScalarRecordDefinition;
|
||||
function GetItems(Idx: Integer): TPair<IKeyword, TScalar>;
|
||||
function GetItems(Idx: Integer): TScalar;
|
||||
function GetFields(const Key: IKeyword): TScalar;
|
||||
function GetKeywords(Idx: Integer): IKeyword;
|
||||
public
|
||||
constructor Create(const ADef: IScalarRecordDefinition; const AData: TArray<TScalar.TValue>);
|
||||
property Def: IScalarRecordDefinition read GetDef;
|
||||
end;
|
||||
|
||||
ISeries = interface
|
||||
@@ -228,7 +220,8 @@ type
|
||||
FFields: TArray<TMemberSeries>;
|
||||
FTotalCount: Int64;
|
||||
|
||||
function GetItems(Idx: Integer): TPair<IKeyword, ISeries>;
|
||||
function GetItems(Idx: Integer): ISeries;
|
||||
function GetKeywords(Idx: Integer): IKeyword;
|
||||
function GetCount: Integer;
|
||||
function IndexOf(const Key: IKeyword): Integer;
|
||||
|
||||
@@ -824,8 +817,8 @@ begin
|
||||
var lb := FDef.Count * Integer(Lookback);
|
||||
for var i := 0 to FDef.Count - 1 do
|
||||
begin
|
||||
Assert(Item[i].Key = FDef[i].Key, 'Mapping does not fit series definition');
|
||||
FArray.Add(Item[i].Value.Value, lb);
|
||||
Assert(Item.Keywords[i] = FDef.Keywords[i], 'Mapping does not fit series definition');
|
||||
FArray.Add(Item[i].Value, lb);
|
||||
end;
|
||||
inc(FTotalCount);
|
||||
end;
|
||||
@@ -875,10 +868,14 @@ begin
|
||||
Result := Length(FFields);
|
||||
end;
|
||||
|
||||
function TScalarRecordSeries.GetItems(Idx: Integer): TPair<IKeyword, ISeries>;
|
||||
function TScalarRecordSeries.GetItems(Idx: Integer): ISeries;
|
||||
begin
|
||||
Result.Key := FDef.Items[Idx].Key;
|
||||
Result.Value := FFields[Idx];
|
||||
Result := FFields[Idx];
|
||||
end;
|
||||
|
||||
function TScalarRecordSeries.GetKeywords(Idx: Integer): IKeyword;
|
||||
begin
|
||||
Result := FDef.Keywords[Idx];
|
||||
end;
|
||||
|
||||
function TScalarRecordSeries.IndexOf(const Key: IKeyword): Integer;
|
||||
@@ -946,7 +943,7 @@ end;
|
||||
constructor TScalarRecordSeries.TMemberSeries.Create(ARecordSeries: TScalarRecordSeries; AElementIdx: Integer);
|
||||
begin
|
||||
inherited Create(ARecordSeries);
|
||||
FKind := ARecordSeries.FDef[AElementIdx].Value;
|
||||
FKind := ARecordSeries.FDef[AElementIdx];
|
||||
FOffset := sizeof(TScalar.TValue) * AElementIdx;
|
||||
end;
|
||||
|
||||
@@ -1043,11 +1040,6 @@ begin
|
||||
Result := FDef.Count;
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetDef: IScalarRecordDefinition;
|
||||
begin
|
||||
Result := FDef;
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetFields(const Key: IKeyword): TScalar;
|
||||
var
|
||||
idx: Integer;
|
||||
@@ -1057,15 +1049,19 @@ begin
|
||||
exit(Default(TScalar));
|
||||
|
||||
// Return the raw TValue at the offset
|
||||
Result.Kind := FDef[idx].Value;
|
||||
Result.Kind := FDef[idx];
|
||||
Result.Value := FData[idx];
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetItems(Idx: Integer): TPair<IKeyword, TScalar>;
|
||||
function TScalarRecord.GetItems(Idx: Integer): TScalar;
|
||||
begin
|
||||
Result.Key := FDef[Idx].Key;
|
||||
Result.Value.Kind := FDef[idx].Value;
|
||||
Result.Value.Value := FData[idx];
|
||||
Result.Kind := FDef[idx];
|
||||
Result.Value := FData[idx];
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetKeywords(Idx: Integer): IKeyword;
|
||||
begin
|
||||
Result := FDef.Keywords[Idx];
|
||||
end;
|
||||
|
||||
function TScalarRecord.IndexOf(const Key: IKeyword): Integer;
|
||||
|
||||
Reference in New Issue
Block a user