This commit is contained in:
Michael Schimmel
2026-01-04 17:06:59 +01:00
parent 8914d59607
commit a4afae6f39
10 changed files with 655 additions and 211 deletions
+33 -5
View File
@@ -75,10 +75,9 @@ type
class operator Implicit(const AValue: TDataValue): TScalar; overload; inline;
class operator Implicit(const AValue: String): TDataValue; overload; inline;
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
class operator Implicit(const AValue: ITuple<TDataValue>): TDataValue; overload; inline;
class operator Implicit(const AValue: IKeywordMapping<TScalar>): TDataValue; overload; inline;
class operator Implicit(const AValue: IKeywordMapping<TDataValue>): TDataValue; overload; inline;
class operator Implicit(const AValue: IWriteableScalarRecordSeries): TDataValue; overload; inline;
class operator Implicit(const AValue: ISeries): TDataValue; overload; inline;
class operator Implicit(const AValue: IStream): TDataValue; overload; inline;
@@ -102,6 +101,7 @@ type
function AsScalar: TScalar; inline;
function AsMethod: TFunc; inline;
function AsText: String; inline;
function AsTuple: ITuple<TDataValue>; inline;
function AsRecordSeries: IWriteableScalarRecordSeries; inline;
function AsScalarRecord: IKeywordMapping<TScalar>; inline;
function AsRecord: IKeywordMapping<TDataValue>; inline;
@@ -364,6 +364,13 @@ begin
Result := (FInterface as TVal<String>).Value;
end;
function TDataValue.AsTuple: ITuple<TDataValue>;
begin
if (FKind <> vkTuple) then
raise EInvalidCast.Create('Cannot read value as Tuple.');
Result := ITuple<TDataValue>(FInterface);
end;
function TDataValue.ToString: String;
var
sb: TStringBuilder;
@@ -371,6 +378,7 @@ var
first: Boolean;
i: Integer;
begin
first := True;
case FKind of
vkScalar: Result := FScalar.ToString;
vkText: Result := '"' + AsText + '"';
@@ -379,13 +387,29 @@ begin
var series := AsSeries;
Result := Format('<series[%d]>', [series.Count]);
end;
vkTuple:
begin
var tuple := AsTuple;
sb := TStringBuilder.Create;
try
for i := 0 to tuple.Count - 1 do
begin
if not first then
sb.Append(',');
sb.Append(tuple[i].Kind.ToString);
first := False;
end;
Result := Format('<tuple[%s]>', [sb.ToString]);
finally
sb.Free;
end;
end;
vkRecordSeries:
begin
var series := AsRecordSeries;
sb := TStringBuilder.Create;
try
sb.Append('{');
first := True;
for i := 0 to series.Def.Count - 1 do
begin
if not first then
@@ -405,7 +429,6 @@ begin
sb := TStringBuilder.Create;
try
sb.Append('{');
first := True;
for i := 0 to rec.Count - 1 do
begin
if not first then
@@ -425,7 +448,6 @@ begin
sb := TStringBuilder.Create;
try
sb.Append('{');
first := True;
for i := 0 to rec.Count - 1 do
begin
if not first then
@@ -479,6 +501,12 @@ begin
Result.FInterface := AValue;
end;
class operator TDataValue.Implicit(const AValue: ITuple<TDataValue>): TDataValue;
begin
Result.FKind := vkTuple;
Result.FInterface := AValue;
end;
{ TMapSeries }
constructor TMapSeries.Create(const ASourceSeries: ISeries; const AMapperFunc: TDataValue.TFunc);