Data POD
This commit is contained in:
@@ -7,27 +7,27 @@ interface
|
||||
type
|
||||
TScale = 0..7;
|
||||
|
||||
TDecimal64 = record
|
||||
TDecimal = record
|
||||
strict private
|
||||
FValue: Int64;
|
||||
public
|
||||
constructor Create(AValue: Int64; AScale: TScale); overload;
|
||||
constructor Create(const AValue: TDecimal64; ANewScale: TScale); overload;
|
||||
constructor Create(const AValue: TDecimal; ANewScale: TScale); overload;
|
||||
|
||||
class operator Add(const A, B: TDecimal64): TDecimal64;
|
||||
class operator Subtract(const A, B: TDecimal64): TDecimal64;
|
||||
class operator Multiply(const A, B: TDecimal64): TDecimal64;
|
||||
class operator Divide(const A, B: TDecimal64): TDecimal64;
|
||||
class operator Add(const A, B: TDecimal): TDecimal;
|
||||
class operator Subtract(const A, B: TDecimal): TDecimal;
|
||||
class operator Multiply(const A, B: TDecimal): TDecimal;
|
||||
class operator Divide(const A, B: TDecimal): TDecimal;
|
||||
|
||||
class operator Equal(const A, B: TDecimal64): Boolean;
|
||||
class operator NotEqual(const A, B: TDecimal64): Boolean;
|
||||
class operator Equal(const A, B: TDecimal): Boolean;
|
||||
class operator NotEqual(const A, B: TDecimal): Boolean;
|
||||
|
||||
class operator Implicit(const A: Int64): TDecimal64;
|
||||
class operator Explicit(const A: TDecimal64): Int64;
|
||||
class operator Explicit(const A: TDecimal64): Double;
|
||||
class operator Implicit(const A: Int64): TDecimal;
|
||||
class operator Explicit(const A: TDecimal): Int64;
|
||||
class operator Explicit(const A: TDecimal): Double;
|
||||
|
||||
class function MinValue(AScale: TScale): TDecimal64; static;
|
||||
class function MaxValue(AScale: TScale): TDecimal64; static;
|
||||
class function MinValue(AScale: TScale): TDecimal; static;
|
||||
class function MaxValue(AScale: TScale): TDecimal; static;
|
||||
|
||||
function GetValue: Int64;
|
||||
function GetScale: TScale;
|
||||
@@ -52,14 +52,14 @@ const
|
||||
// Use a lookup table for powers of 10 for performance
|
||||
PowersOf10: array[TScale] of Int64 = (1, 10, 100, 1000, 10000, 100000, 1000000, 10000000);
|
||||
|
||||
{ TDecimal64 }
|
||||
{ TDecimal }
|
||||
|
||||
constructor TDecimal64.Create(AValue: Int64; AScale: TScale);
|
||||
constructor TDecimal.Create(AValue: Int64; AScale: TScale);
|
||||
begin
|
||||
FValue := (Int64(AScale) shl VALUE_BITS) or (AValue and ((1 shl VALUE_BITS) - 1));
|
||||
end;
|
||||
|
||||
constructor TDecimal64.Create(const AValue: TDecimal64; ANewScale: TScale);
|
||||
constructor TDecimal.Create(const AValue: TDecimal; ANewScale: TScale);
|
||||
var
|
||||
oldScale: TScale;
|
||||
newValue: Int64;
|
||||
@@ -99,7 +99,7 @@ begin
|
||||
FValue := (Int64(ANewScale) shl VALUE_BITS) or (newValue and ((1 shl VALUE_BITS) - 1));
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Add(const A, B: TDecimal64): TDecimal64;
|
||||
class operator TDecimal.Add(const A, B: TDecimal): TDecimal;
|
||||
var
|
||||
scale: TScale;
|
||||
resultValue: Int64;
|
||||
@@ -109,10 +109,10 @@ begin
|
||||
raise EArgumentException.Create('Operands must have the same scale.');
|
||||
|
||||
resultValue := A.GetValue + B.GetValue;
|
||||
Result := TDecimal64.Create(resultValue, A.GetScale);
|
||||
Result := TDecimal.Create(resultValue, A.GetScale);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Subtract(const A, B: TDecimal64): TDecimal64;
|
||||
class operator TDecimal.Subtract(const A, B: TDecimal): TDecimal;
|
||||
var
|
||||
scale: TScale;
|
||||
resultValue: Int64;
|
||||
@@ -122,10 +122,10 @@ begin
|
||||
raise EArgumentException.Create('Operands must have the same scale.');
|
||||
|
||||
resultValue := A.GetValue - B.GetValue;
|
||||
Result := TDecimal64.Create(resultValue, scale);
|
||||
Result := TDecimal.Create(resultValue, scale);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Multiply(const A, B: TDecimal64): TDecimal64;
|
||||
class operator TDecimal.Multiply(const A, B: TDecimal): TDecimal;
|
||||
var
|
||||
scale: TScale;
|
||||
resultValue: Int64;
|
||||
@@ -135,10 +135,10 @@ begin
|
||||
raise EArgumentException.Create('Operands must have the same scale.');
|
||||
|
||||
resultValue := Trunc(A.GetValue * B.GetValue / PowersOf10[scale]);
|
||||
Result := TDecimal64.Create(resultValue, scale);
|
||||
Result := TDecimal.Create(resultValue, scale);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Divide(const A, B: TDecimal64): TDecimal64;
|
||||
class operator TDecimal.Divide(const A, B: TDecimal): TDecimal;
|
||||
var
|
||||
scale: TScale;
|
||||
resultValue: Int64;
|
||||
@@ -152,10 +152,10 @@ begin
|
||||
|
||||
// Correctly scale the dividend to preserve precision
|
||||
resultValue := Trunc(A.GetValue * PowersOf10[scale] / B.GetValue);
|
||||
Result := TDecimal64.Create(resultValue, scale);
|
||||
Result := TDecimal.Create(resultValue, scale);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Equal(const A, B: TDecimal64): Boolean;
|
||||
class operator TDecimal.Equal(const A, B: TDecimal): Boolean;
|
||||
begin
|
||||
if A.GetScale <> B.GetScale then
|
||||
Result := False
|
||||
@@ -163,38 +163,38 @@ begin
|
||||
Result := (A.GetValue = B.GetValue);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.NotEqual(const A, B: TDecimal64): Boolean;
|
||||
class operator TDecimal.NotEqual(const A, B: TDecimal): Boolean;
|
||||
begin
|
||||
Result := not (A = B);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Implicit(const A: Int64): TDecimal64;
|
||||
class operator TDecimal.Implicit(const A: Int64): TDecimal;
|
||||
begin
|
||||
// Correctly create a TDecimal64 with scale 0
|
||||
Result := TDecimal64.Create(A, 0);
|
||||
// Correctly create a TDecimal with scale 0
|
||||
Result := TDecimal.Create(A, 0);
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Explicit(const A: TDecimal64): Int64;
|
||||
class operator TDecimal.Explicit(const A: TDecimal): Int64;
|
||||
begin
|
||||
Result := A.GetValue;
|
||||
end;
|
||||
|
||||
class operator TDecimal64.Explicit(const A: TDecimal64): Double;
|
||||
class operator TDecimal.Explicit(const A: TDecimal): Double;
|
||||
begin
|
||||
Result := A.GetValue / PowersOf10[A.GetScale];
|
||||
end;
|
||||
|
||||
class function TDecimal64.MaxValue(AScale: TScale): TDecimal64;
|
||||
class function TDecimal.MaxValue(AScale: TScale): TDecimal;
|
||||
begin
|
||||
Result := TDecimal64.Create(MAX_VALUE_61BIT, AScale);
|
||||
Result := TDecimal.Create(MAX_VALUE_61BIT, AScale);
|
||||
end;
|
||||
|
||||
class function TDecimal64.MinValue(AScale: TScale): TDecimal64;
|
||||
class function TDecimal.MinValue(AScale: TScale): TDecimal;
|
||||
begin
|
||||
Result := TDecimal64.Create(MIN_VALUE_61BIT, AScale);
|
||||
Result := TDecimal.Create(MIN_VALUE_61BIT, AScale);
|
||||
end;
|
||||
|
||||
function TDecimal64.GetValue: Int64;
|
||||
function TDecimal.GetValue: Int64;
|
||||
var
|
||||
value: Int64;
|
||||
begin
|
||||
@@ -206,12 +206,12 @@ begin
|
||||
Result := value;
|
||||
end;
|
||||
|
||||
function TDecimal64.GetScale: TScale;
|
||||
function TDecimal.GetScale: TScale;
|
||||
begin
|
||||
Result := TScale((FValue shr VALUE_BITS) and SCALE_MASK);
|
||||
end;
|
||||
|
||||
function TDecimal64.GetRawValue: Int64;
|
||||
function TDecimal.GetRawValue: Int64;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
+521
-24
@@ -3,62 +3,559 @@ unit Myc.Data.POD;
|
||||
interface
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
Myc.Data.Decimal,
|
||||
Myc.Data.Series;
|
||||
|
||||
type
|
||||
// POD: Plain old data (that fits into a 64 bit register)
|
||||
// POD: Plain old data (...that fits into 128 bits)
|
||||
|
||||
TScalarKind = (skInteger, skInt64, skUInt64, skSingle, skDouble, skTimestamp, skBoolean, skChar, skString, skBytes);
|
||||
TScalarKind = (
|
||||
skInteger,
|
||||
skInt64,
|
||||
skUInt64,
|
||||
skSingle,
|
||||
skDouble,
|
||||
skDateTime,
|
||||
skTimestamp,
|
||||
skBoolean,
|
||||
skChar,
|
||||
skPChar,
|
||||
skString,
|
||||
skBytes,
|
||||
skDecimal
|
||||
);
|
||||
|
||||
TScalarBytes = array[0..15] of Byte;
|
||||
|
||||
TScalarPChar = array[0..7] of Char;
|
||||
TScalarString = String[15];
|
||||
|
||||
TScalarValue = record
|
||||
public
|
||||
// Factory methods for creating a TScalarValue without a kind.
|
||||
class function FromInteger(AValue: Integer): TScalarValue; static; inline;
|
||||
class function FromInt64(AValue: Int64): TScalarValue; static; inline;
|
||||
class function FromUInt64(AValue: UInt64): TScalarValue; static; inline;
|
||||
class function FromSingle(AValue: Single): TScalarValue; static; inline;
|
||||
class function FromDouble(AValue: Double): TScalarValue; static; inline;
|
||||
class function FromDateTime(AValue: TDateTime): TScalarValue; static; inline;
|
||||
class function FromTimestamp(AValue: TTimestamp): TScalarValue; static; inline;
|
||||
class function FromBoolean(AValue: Boolean): TScalarValue; static; inline;
|
||||
class function FromChar(AValue: Char): TScalarValue; static; inline;
|
||||
class function FromPChar(const AValue: String): TScalarValue; overload; static; inline;
|
||||
class function FromPChar(const AValue: TScalarPChar): TScalarValue; overload; static; inline;
|
||||
class function FromString(const AValue: String): TScalarValue; overload; static; inline;
|
||||
class function FromString(const AValue: TScalarString): TScalarValue; overload; static; inline;
|
||||
class function FromBytes(const AValue: TScalarBytes): TScalarValue; static; inline;
|
||||
class function FromDecimal(AValue: TDecimal): TScalarValue; static; inline;
|
||||
|
||||
function GetAsInteger: Integer; inline;
|
||||
function GetAsInt64: Int64; inline;
|
||||
function GetAsUInt64: UInt64; inline;
|
||||
function GetAsSingle: Single; inline;
|
||||
function GetAsDouble: Double; inline;
|
||||
function GetAsDateTime: TDateTime; inline;
|
||||
function GetAsTimestamp: TTimestamp; inline;
|
||||
function GetAsBoolean: Boolean; inline;
|
||||
function GetAsChar: Char; inline;
|
||||
function GetAsPChar: PChar; inline;
|
||||
function GetAsString: ShortString; inline;
|
||||
function GetAsBytes: TScalarBytes; inline;
|
||||
function GetAsDecimal: TDecimal; inline;
|
||||
|
||||
property AsInteger: Integer read GetAsInteger;
|
||||
property AsInt64: Int64 read GetAsInt64;
|
||||
property AsUInt64: UInt64 read GetAsUInt64;
|
||||
property AsSingle: Single read GetAsSingle;
|
||||
property AsDouble: Double read GetAsDouble;
|
||||
property AsDateTime: TDateTime read GetAsDateTime;
|
||||
property AsTimestamp: TTimestamp read GetAsTimestamp;
|
||||
property AsBoolean: Boolean read GetAsBoolean;
|
||||
property AsChar: Char read GetAsChar;
|
||||
property AsPChar: PChar read GetAsPChar;
|
||||
property AsString: ShortString read GetAsString;
|
||||
property AsBytes: TScalarBytes read GetAsBytes;
|
||||
property AsDecimal: TDecimal read GetAsDecimal;
|
||||
|
||||
strict private
|
||||
case TScalarKind of
|
||||
skInteger: (AsInteger: Integer);
|
||||
skInt64: (AsInt64: Int64);
|
||||
skUInt64: (AsUInt64: UInt64);
|
||||
skSingle: (AsSingle: Single);
|
||||
skDouble: (AsDouble: Double);
|
||||
skTimestamp: (AsTimeStamp: TDateTime);
|
||||
skBoolean: (AsBoolean: Boolean);
|
||||
skChar: (AsChar: Char);
|
||||
skString: (AsString: String[15]);
|
||||
skBytes: (AsBytes: array[0..15] of Byte);
|
||||
skInteger: (FInteger: Integer);
|
||||
skInt64: (FInt64: Int64);
|
||||
skUInt64: (FUInt64: UInt64);
|
||||
skSingle: (FSingle: Single);
|
||||
skDouble: (FDouble: Double);
|
||||
skDateTime: (FDateTime: TDateTime);
|
||||
skTimestamp: (FTimestamp: TTimestamp);
|
||||
skBoolean: (FBoolean: Boolean);
|
||||
skChar: (FChar: Char);
|
||||
skPChar: (FPChar: TScalarPChar);
|
||||
skString: (FString: String[15]);
|
||||
skBytes: (FBytes: TScalarBytes);
|
||||
skDecimal: (FDecimal: TDecimal);
|
||||
end;
|
||||
|
||||
// A scalar value with a type identifier.
|
||||
TScalar = record
|
||||
Kind: TScalarKind;
|
||||
Value: TScalarValue;
|
||||
public
|
||||
// Creates a new scalar from a kind and a value.
|
||||
constructor Create(AKind: TScalarKind; const AValue: TScalarValue);
|
||||
|
||||
// Factory methods for specific scalar types.
|
||||
class function FromInteger(AValue: Integer): TScalar; static; inline;
|
||||
class function FromInt64(AValue: Int64): TScalar; static; inline;
|
||||
class function FromUInt64(AValue: UInt64): TScalar; static; inline;
|
||||
class function FromSingle(AValue: Single): TScalar; static; inline;
|
||||
class function FromDouble(AValue: Double): TScalar; static; inline;
|
||||
class function FromDateTime(AValue: TDateTime): TScalar; static; inline;
|
||||
class function FromTimestamp(AValue: TTimestamp): TScalar; static; inline;
|
||||
class function FromBoolean(AValue: Boolean): TScalar; static; inline;
|
||||
class function FromChar(AValue: Char): TScalar; static; inline;
|
||||
class function FromPChar(const AValue: TScalarPChar): TScalar; static; inline;
|
||||
class function FromString(const AValue: String): TScalar; static; inline;
|
||||
class function FromBytes(const AValue: TScalarBytes): TScalar; static; inline;
|
||||
class function FromDecimal(AValue: TDecimal): TScalar; static; inline;
|
||||
|
||||
function GetKind: TScalarKind; inline;
|
||||
function GetValue: TScalarValue; inline;
|
||||
|
||||
property Kind: TScalarKind read GetKind;
|
||||
property Value: TScalarValue read GetValue;
|
||||
|
||||
strict private
|
||||
FKind: TScalarKind;
|
||||
FValue: TScalarValue;
|
||||
end;
|
||||
|
||||
// Basic data structures using the scalar type (these ar not POD of course)
|
||||
// Basic data structures using the scalar type (these are not POD of course)
|
||||
|
||||
// An array of scalar values of the same kind.
|
||||
TScalarArray = record
|
||||
Kind: TScalarKind;
|
||||
Items: TArray<TScalarValue>;
|
||||
public
|
||||
// Creates a new scalar array.
|
||||
constructor Create(AKind: TScalarKind; const AItems: TArray<TScalarValue>);
|
||||
|
||||
function GetKind: TScalarKind; inline;
|
||||
function GetItems: TArray<TScalarValue>; inline;
|
||||
|
||||
property Kind: TScalarKind read GetKind;
|
||||
property Items: TArray<TScalarValue> read GetItems;
|
||||
|
||||
strict private
|
||||
FKind: TScalarKind;
|
||||
FItems: TArray<TScalarValue>;
|
||||
end;
|
||||
|
||||
TScalarTuple = TArray<TScalar>;
|
||||
|
||||
// A field definition for a scalar record.
|
||||
TScalarRecordField = record
|
||||
Name: String;
|
||||
Kind: TScalarKind;
|
||||
public
|
||||
// Creates a new record field definition.
|
||||
constructor Create(const AName: String; AKind: TScalarKind);
|
||||
|
||||
function GetName: String; inline;
|
||||
function GetKind: TScalarKind; inline;
|
||||
|
||||
property Name: String read GetName;
|
||||
property Kind: TScalarKind read GetKind;
|
||||
|
||||
strict private
|
||||
FName: String;
|
||||
FKind: TScalarKind;
|
||||
end;
|
||||
|
||||
// A collection of field definitions that describe a scalar record.
|
||||
TScalarRecordDefinition = record
|
||||
Fields: TArray<TScalarRecordField>;
|
||||
public
|
||||
// Creates a new record definition.
|
||||
constructor Create(const AFields: TArray<TScalarRecordField>);
|
||||
|
||||
function GetFields: TArray<TScalarRecordField>; inline;
|
||||
property Fields: TArray<TScalarRecordField> read GetFields;
|
||||
|
||||
strict private
|
||||
FFields: TArray<TScalarRecordField>;
|
||||
end;
|
||||
|
||||
// A record of scalar values, based on a definition.
|
||||
TScalarRecord = record
|
||||
Def: TScalarRecordDefinition;
|
||||
Fields: TArray<TScalarValue>;
|
||||
public
|
||||
// Creates a new scalar record.
|
||||
constructor Create(const ADef: TScalarRecordDefinition; const AFields: TArray<TScalarValue>);
|
||||
|
||||
function GetDef: TScalarRecordDefinition; inline;
|
||||
function GetFields: TArray<TScalarValue>; inline;
|
||||
|
||||
property Def: TScalarRecordDefinition read GetDef;
|
||||
property Fields: TArray<TScalarValue> read GetFields;
|
||||
|
||||
strict private
|
||||
FDef: TScalarRecordDefinition;
|
||||
FFields: TArray<TScalarValue>;
|
||||
end;
|
||||
|
||||
// A time series of scalar values of the same kind.
|
||||
TScalarSeries = record
|
||||
Kind: TScalarKind;
|
||||
Items: TSeries<TScalarValue>;
|
||||
public
|
||||
// Creates a new scalar series.
|
||||
constructor Create(AKind: TScalarKind; const AItems: TSeries<TScalarValue>);
|
||||
|
||||
function GetKind: TScalarKind; inline;
|
||||
function GetItems: TSeries<TScalarValue>; inline;
|
||||
|
||||
property Kind: TScalarKind read GetKind;
|
||||
property Items: TSeries<TScalarValue> read GetItems;
|
||||
|
||||
strict private
|
||||
FKind: TScalarKind;
|
||||
FItems: TSeries<TScalarValue>;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TScalarValue }
|
||||
|
||||
class function TScalarValue.FromBoolean(AValue: Boolean): TScalarValue;
|
||||
begin
|
||||
Result.FBoolean := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromBytes(const AValue: TScalarBytes): TScalarValue;
|
||||
var
|
||||
len: Integer;
|
||||
begin
|
||||
FillChar(Result.FBytes, SizeOf(Result.FBytes), 0);
|
||||
len := Length(AValue);
|
||||
if (len > 0) then
|
||||
begin
|
||||
if (len > SizeOf(Result.FBytes)) then
|
||||
len := SizeOf(Result.FBytes);
|
||||
Move(AValue[0], Result.FBytes[0], len);
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromChar(AValue: Char): TScalarValue;
|
||||
begin
|
||||
Result.FChar := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromDateTime(AValue: TDateTime): TScalarValue;
|
||||
begin
|
||||
Result.FDateTime := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromDecimal(AValue: TDecimal): TScalarValue;
|
||||
begin
|
||||
Result.FDecimal := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromDouble(AValue: Double): TScalarValue;
|
||||
begin
|
||||
Result.FDouble := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromInt64(AValue: Int64): TScalarValue;
|
||||
begin
|
||||
Result.FInt64 := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromInteger(AValue: Integer): TScalarValue;
|
||||
begin
|
||||
Result.FInteger := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromPChar(const AValue: String): TScalarValue;
|
||||
var
|
||||
len, i: Integer;
|
||||
begin
|
||||
FillChar(Result.FPChar, SizeOf(Result.FPChar), #0);
|
||||
len := Length(AValue);
|
||||
if (len > 0) then
|
||||
begin
|
||||
if (len > Length(Result.FPChar)) then
|
||||
len := Length(Result.FPChar);
|
||||
for i := 0 to len - 1 do
|
||||
Result.FPChar[i] := AValue[i + 1];
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromPChar(const AValue: TScalarPChar): TScalarValue;
|
||||
begin
|
||||
Result.FPChar := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromSingle(AValue: Single): TScalarValue;
|
||||
begin
|
||||
Result.FSingle := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromString(const AValue: String): TScalarValue;
|
||||
begin
|
||||
Result.FString := ShortString(AValue);
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromString(const AValue: TScalarString): TScalarValue;
|
||||
begin
|
||||
Result.FString := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromTimestamp(AValue: TTimestamp): TScalarValue;
|
||||
begin
|
||||
Result.FTimestamp := AValue;
|
||||
end;
|
||||
|
||||
class function TScalarValue.FromUInt64(AValue: UInt64): TScalarValue;
|
||||
begin
|
||||
Result.FUInt64 := AValue;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsBoolean: Boolean;
|
||||
begin
|
||||
Result := FBoolean;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsBytes: TScalarBytes;
|
||||
begin
|
||||
Result := FBytes;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsChar: Char;
|
||||
begin
|
||||
Result := FChar;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsDateTime: TDateTime;
|
||||
begin
|
||||
Result := FDateTime;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsDecimal: TDecimal;
|
||||
begin
|
||||
Result := FDecimal;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsDouble: Double;
|
||||
begin
|
||||
Result := FDouble;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsInt64: Int64;
|
||||
begin
|
||||
Result := FInt64;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsInteger: Integer;
|
||||
begin
|
||||
Result := FInteger;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsPChar: PChar;
|
||||
begin
|
||||
Result := @FPChar;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsSingle: Single;
|
||||
begin
|
||||
Result := FSingle;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsString: ShortString;
|
||||
begin
|
||||
Result := FString;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsTimestamp: TTimestamp;
|
||||
begin
|
||||
Result := FTimestamp;
|
||||
end;
|
||||
|
||||
function TScalarValue.GetAsUInt64: UInt64;
|
||||
begin
|
||||
Result := FUInt64;
|
||||
end;
|
||||
|
||||
{ TScalar }
|
||||
|
||||
constructor TScalar.Create(AKind: TScalarKind; const AValue: TScalarValue);
|
||||
begin
|
||||
FKind := AKind;
|
||||
FValue := AValue;
|
||||
end;
|
||||
|
||||
class function TScalar.FromBoolean(AValue: Boolean): TScalar;
|
||||
begin
|
||||
Result.FKind := skBoolean;
|
||||
Result.FValue := TScalarValue.FromBoolean(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromBytes(const AValue: TScalarBytes): TScalar;
|
||||
begin
|
||||
Result.FKind := skBytes;
|
||||
Result.FValue := TScalarValue.FromBytes(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromChar(AValue: Char): TScalar;
|
||||
begin
|
||||
Result.FKind := skChar;
|
||||
Result.FValue := TScalarValue.FromChar(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromDateTime(AValue: TDateTime): TScalar;
|
||||
begin
|
||||
Result.FKind := skDateTime;
|
||||
Result.FValue := TScalarValue.FromDateTime(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromDecimal(AValue: TDecimal): TScalar;
|
||||
begin
|
||||
Result.FKind := skDecimal;
|
||||
Result.FValue := TScalarValue.FromDecimal(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromDouble(AValue: Double): TScalar;
|
||||
begin
|
||||
Result.FKind := skDouble;
|
||||
Result.FValue := TScalarValue.FromDouble(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromInt64(AValue: Int64): TScalar;
|
||||
begin
|
||||
Result.FKind := skInt64;
|
||||
Result.FValue := TScalarValue.FromInt64(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromInteger(AValue: Integer): TScalar;
|
||||
begin
|
||||
Result.FKind := skInteger;
|
||||
Result.FValue := TScalarValue.FromInteger(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromPChar(const AValue: TScalarPChar): TScalar;
|
||||
begin
|
||||
Result.FKind := skPChar;
|
||||
Result.FValue := TScalarValue.FromPChar(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromSingle(AValue: Single): TScalar;
|
||||
begin
|
||||
Result.FKind := skSingle;
|
||||
Result.FValue := TScalarValue.FromSingle(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromString(const AValue: String): TScalar;
|
||||
begin
|
||||
Result.FKind := skString;
|
||||
Result.FValue := TScalarValue.FromString(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromTimestamp(AValue: TTimestamp): TScalar;
|
||||
begin
|
||||
Result.FKind := skTimestamp;
|
||||
Result.FValue := TScalarValue.FromTimestamp(AValue);
|
||||
end;
|
||||
|
||||
class function TScalar.FromUInt64(AValue: UInt64): TScalar;
|
||||
begin
|
||||
Result.FKind := skUInt64;
|
||||
Result.FValue := TScalarValue.FromUInt64(AValue);
|
||||
end;
|
||||
|
||||
function TScalar.GetKind: TScalarKind;
|
||||
begin
|
||||
Result := FKind;
|
||||
end;
|
||||
|
||||
function TScalar.GetValue: TScalarValue;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TScalarArray }
|
||||
|
||||
constructor TScalarArray.Create(AKind: TScalarKind; const AItems: TArray<TScalarValue>);
|
||||
begin
|
||||
FKind := AKind;
|
||||
FItems := AItems;
|
||||
end;
|
||||
|
||||
function TScalarArray.GetKind: TScalarKind;
|
||||
begin
|
||||
Result := FKind;
|
||||
end;
|
||||
|
||||
function TScalarArray.GetItems: TArray<TScalarValue>;
|
||||
begin
|
||||
Result := FItems;
|
||||
end;
|
||||
|
||||
{ TScalarRecordField }
|
||||
|
||||
constructor TScalarRecordField.Create(const AName: String; AKind: TScalarKind);
|
||||
begin
|
||||
FName := AName;
|
||||
FKind := AKind;
|
||||
end;
|
||||
|
||||
function TScalarRecordField.GetName: String;
|
||||
begin
|
||||
Result := FName;
|
||||
end;
|
||||
|
||||
function TScalarRecordField.GetKind: TScalarKind;
|
||||
begin
|
||||
Result := FKind;
|
||||
end;
|
||||
|
||||
{ TScalarRecordDefinition }
|
||||
|
||||
constructor TScalarRecordDefinition.Create(const AFields: TArray<TScalarRecordField>);
|
||||
begin
|
||||
FFields := AFields;
|
||||
end;
|
||||
|
||||
function TScalarRecordDefinition.GetFields: TArray<TScalarRecordField>;
|
||||
begin
|
||||
Result := FFields;
|
||||
end;
|
||||
|
||||
{ TScalarRecord }
|
||||
|
||||
constructor TScalarRecord.Create(const ADef: TScalarRecordDefinition; const AFields: TArray<TScalarValue>);
|
||||
begin
|
||||
Assert(Length(ADef.Fields) = Length(AFields), 'Field definition and value count must match.');
|
||||
FDef := ADef;
|
||||
FFields := AFields;
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetDef: TScalarRecordDefinition;
|
||||
begin
|
||||
Result := FDef;
|
||||
end;
|
||||
|
||||
function TScalarRecord.GetFields: TArray<TScalarValue>;
|
||||
begin
|
||||
Result := FFields;
|
||||
end;
|
||||
|
||||
{ TScalarSeries }
|
||||
|
||||
constructor TScalarSeries.Create(AKind: TScalarKind; const AItems: TSeries<TScalarValue>);
|
||||
begin
|
||||
FKind := AKind;
|
||||
FItems := AItems;
|
||||
end;
|
||||
|
||||
function TScalarSeries.GetKind: TScalarKind;
|
||||
begin
|
||||
Result := FKind;
|
||||
end;
|
||||
|
||||
function TScalarSeries.GetItems: TSeries<TScalarValue>;
|
||||
begin
|
||||
Result := FItems;
|
||||
end;
|
||||
|
||||
initialization
|
||||
Assert(sizeof(TScalarValue) = 16);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user