New type system
This commit is contained in:
@@ -34,8 +34,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SyncObjs,
|
||||
System.Rtti;
|
||||
System.SyncObjs;
|
||||
|
||||
type
|
||||
// Implements the array data value.
|
||||
@@ -45,7 +44,6 @@ type
|
||||
FItems: TArray<IDataValue>;
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function AsTValue: TValue;
|
||||
function GetElementCount: Integer;
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
public
|
||||
@@ -54,15 +52,10 @@ type
|
||||
|
||||
// Optimized implementation for an array with 0 elements.
|
||||
TImplDataArrayValue0 = class(TInterfacedObject, IDataValue, IDataArrayValue)
|
||||
strict private
|
||||
class var
|
||||
FEmptyTValue: TValue; // Singleton TValue for an empty array
|
||||
class constructor CreateClass;
|
||||
private
|
||||
FArrayType: IDataArrayType;
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function AsTValue: TValue;
|
||||
function GetElementCount: Integer;
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
public
|
||||
@@ -71,12 +64,12 @@ type
|
||||
|
||||
// Optimized implementation for an array with 1 element.
|
||||
TImplDataArrayValue1 = class(TInterfacedObject, IDataValue, IDataArrayValue)
|
||||
private
|
||||
private
|
||||
FArrayType: IDataArrayType;
|
||||
FItem0: IDataValue;
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function AsTValue: TValue;
|
||||
function GetElementCount: Integer;
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
public
|
||||
@@ -122,17 +115,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue.AsTValue: TValue;
|
||||
var
|
||||
tvalueArray: TArray<TValue>;
|
||||
i: Integer;
|
||||
begin
|
||||
SetLength(tvalueArray, Length(FItems));
|
||||
for i := 0 to High(FItems) do
|
||||
tvalueArray[i] := FItems[i].AsTValue;
|
||||
Result := TValue.From<TArray<TValue>>(tvalueArray);
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue.GetElementCount: Integer;
|
||||
begin
|
||||
Result := Length(FItems);
|
||||
@@ -145,12 +127,6 @@ end;
|
||||
|
||||
{ TImplDataArrayValue0 }
|
||||
|
||||
class constructor TImplDataArrayValue0.CreateClass;
|
||||
begin
|
||||
// Create a singleton TValue representing an empty dynamic array.
|
||||
FEmptyTValue := TValue.From<TArray<TValue>>([]);
|
||||
end;
|
||||
|
||||
constructor TImplDataArrayValue0.Create(const AArrayType: IDataArrayType);
|
||||
begin
|
||||
inherited Create;
|
||||
@@ -162,11 +138,6 @@ begin
|
||||
Result := '[]';
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue0.AsTValue: TValue;
|
||||
begin
|
||||
Result := FEmptyTValue;
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue0.GetDataType: IDataType;
|
||||
begin
|
||||
Result := FArrayType;
|
||||
@@ -196,15 +167,6 @@ begin
|
||||
Result := '[' + FItem0.AsString + ']';
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue1.AsTValue: TValue;
|
||||
var
|
||||
tvalueArray: TArray<TValue>;
|
||||
begin
|
||||
SetLength(tvalueArray, 1);
|
||||
tvalueArray[0] := FItem0.AsTValue;
|
||||
Result := TValue.From<TArray<TValue>>(tvalueArray);
|
||||
end;
|
||||
|
||||
function TImplDataArrayValue1.GetDataType: IDataType;
|
||||
begin
|
||||
Result := FArrayType;
|
||||
|
||||
Reference in New Issue
Block a user