Data Types
This commit is contained in:
@@ -25,7 +25,8 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.Math;
|
||||
System.Math,
|
||||
System.Rtti;
|
||||
|
||||
type
|
||||
// Implements the float data value.
|
||||
@@ -38,6 +39,7 @@ type
|
||||
// IDataValue
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function AsTValue: TValue;
|
||||
|
||||
// IDataFloatValue
|
||||
function GetValue: Double;
|
||||
@@ -45,18 +47,28 @@ type
|
||||
|
||||
// Special implementation for the value 0.0 (Singleton)
|
||||
TDataFloatValueZero = class(TInterfacedObject, IDataValue, IDataFloatValue)
|
||||
strict private
|
||||
class var
|
||||
FValue: TValue;
|
||||
class constructor CreateClass;
|
||||
public
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function GetValue: Double;
|
||||
function AsTValue: TValue;
|
||||
end;
|
||||
|
||||
// Special implementation for NaN (Not a Number) (Singleton)
|
||||
TDataFloatValueNaN = class(TInterfacedObject, IDataValue, IDataFloatValue)
|
||||
strict private
|
||||
class var
|
||||
FValue: TValue;
|
||||
class constructor CreateClass;
|
||||
public
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function GetValue: Double;
|
||||
function AsTValue: TValue;
|
||||
end;
|
||||
|
||||
{ TDataFloatValue }
|
||||
@@ -77,6 +89,11 @@ begin
|
||||
Result := FloatToStr(FValue);
|
||||
end;
|
||||
|
||||
function TDataFloatValue.AsTValue: TValue;
|
||||
begin
|
||||
Result := TValue.From<Double>(FValue);
|
||||
end;
|
||||
|
||||
function TDataFloatValue.GetValue: Double;
|
||||
begin
|
||||
Result := FValue;
|
||||
@@ -84,6 +101,11 @@ end;
|
||||
|
||||
{ TDataFloatValueZero }
|
||||
|
||||
class constructor TDataFloatValueZero.CreateClass;
|
||||
begin
|
||||
FValue := TValue.From<Double>(0.0);
|
||||
end;
|
||||
|
||||
function TDataFloatValueZero.GetAsString: string;
|
||||
begin
|
||||
Result := '0';
|
||||
@@ -99,8 +121,18 @@ begin
|
||||
Result := 0.0;
|
||||
end;
|
||||
|
||||
function TDataFloatValueZero.AsTValue: TValue;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TDataFloatValueNaN }
|
||||
|
||||
class constructor TDataFloatValueNaN.CreateClass;
|
||||
begin
|
||||
FValue := TValue.From<Double>(NaN);
|
||||
end;
|
||||
|
||||
function TDataFloatValueNaN.GetAsString: string;
|
||||
begin
|
||||
Result := 'NaN';
|
||||
@@ -116,6 +148,11 @@ begin
|
||||
Result := NaN;
|
||||
end;
|
||||
|
||||
function TDataFloatValueNaN.AsTValue: TValue;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TDataFloatType }
|
||||
|
||||
class constructor TDataFloatType.CreateClass;
|
||||
|
||||
Reference in New Issue
Block a user