Data Types next
This commit is contained in:
@@ -6,53 +6,6 @@ uses
|
||||
System.SysUtils,
|
||||
Myc.Data.Types;
|
||||
|
||||
type
|
||||
// An interface helper for the singleton IDataTupleType.
|
||||
TTupleType = record
|
||||
private
|
||||
FTupleType: IDataTupleType;
|
||||
function GetName: String; inline;
|
||||
public
|
||||
constructor Create(const ATupleType: IDataTupleType);
|
||||
class operator Implicit(const A: IDataTupleType): TTupleType; overload;
|
||||
class operator Implicit(const A: TTupleType): IDataTupleType; overload;
|
||||
property Name: String read GetName;
|
||||
end;
|
||||
|
||||
// An interface helper for IDataTupleValue.
|
||||
TTupleValue = record
|
||||
private
|
||||
FTupleValue: IDataTupleValue;
|
||||
function GetItem(Idx: Integer): TDataValue; inline;
|
||||
function GetItemCount: Integer; inline;
|
||||
public
|
||||
constructor Create(const ATupleValue: IDataTupleValue);
|
||||
|
||||
class operator Implicit(const A: IDataTupleValue): TTupleValue; overload;
|
||||
class operator Implicit(const A: TTupleValue): IDataTupleValue; overload;
|
||||
|
||||
property ItemCount: Integer read GetItemCount;
|
||||
property Items[Idx: Integer]: TDataValue read GetItem; default;
|
||||
end;
|
||||
|
||||
TDataValueHelper = record helper for TDataValue
|
||||
public
|
||||
function AsTuple: TTupleValue;
|
||||
end;
|
||||
|
||||
TDataTypeHelper = record helper for TDataType
|
||||
public
|
||||
function AsTuple: TTupleType;
|
||||
end;
|
||||
|
||||
// Public factory for creating simple, non-cached tuple values.
|
||||
TTuple = record
|
||||
public
|
||||
class function Create(const AItems: array of IDataValue): IDataTupleValue; static;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
// Implements the simple tuple data value.
|
||||
TImplDataTupleValue = class(TInterfacedObject, IDataValue, IDataTupleValue)
|
||||
@@ -73,67 +26,13 @@ type
|
||||
class constructor CreateClass;
|
||||
private
|
||||
function GetName: String;
|
||||
function GetKind: TDataKind;
|
||||
public
|
||||
function CreateValue(const AItems: array of IDataValue): IDataTupleValue;
|
||||
class property Singleton: IDataTupleType read FSingleton;
|
||||
end;
|
||||
|
||||
{ TTupleValue }
|
||||
|
||||
constructor TTupleValue.Create(const ATupleValue: IDataTupleValue);
|
||||
begin
|
||||
FTupleValue := ATupleValue;
|
||||
end;
|
||||
|
||||
function TTupleValue.GetItem(Idx: Integer): TDataValue;
|
||||
begin
|
||||
if Assigned(FTupleValue) then
|
||||
Result := FTupleValue.Items[Idx]
|
||||
else
|
||||
Result := TDataValue.Create(nil);
|
||||
end;
|
||||
|
||||
function TTupleValue.GetItemCount: Integer;
|
||||
begin
|
||||
if Assigned(FTupleValue) then
|
||||
Result := FTupleValue.ItemCount
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
class operator TTupleValue.Implicit(const A: TTupleValue): IDataTupleValue;
|
||||
begin
|
||||
Result := A.FTupleValue;
|
||||
end;
|
||||
|
||||
class operator TTupleValue.Implicit(const A: IDataTupleValue): TTupleValue;
|
||||
begin
|
||||
Result.FTupleValue := A;
|
||||
end;
|
||||
|
||||
{ TTupleType }
|
||||
|
||||
constructor TTupleType.Create(const ATupleType: IDataTupleType);
|
||||
begin
|
||||
FTupleType := ATupleType;
|
||||
end;
|
||||
|
||||
function TTupleType.GetName: String;
|
||||
begin
|
||||
if Assigned(FTupleType) then
|
||||
Result := FTupleType.Name
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
class operator TTupleType.Implicit(const A: TTupleType): IDataTupleType;
|
||||
begin
|
||||
Result := A.FTupleType;
|
||||
end;
|
||||
|
||||
class operator TTupleType.Implicit(const A: IDataTupleType): TTupleType;
|
||||
begin
|
||||
Result.FTupleType := A;
|
||||
end;
|
||||
implementation
|
||||
|
||||
{ TImplDataTupleValue }
|
||||
|
||||
@@ -169,32 +68,19 @@ begin
|
||||
FSingleton := TImplDataTupleType.Create;
|
||||
end;
|
||||
|
||||
function TImplDataTupleType.CreateValue(const AItems: array of IDataValue): IDataTupleValue;
|
||||
begin
|
||||
Result := TImplDataTupleValue.Create(AItems);
|
||||
end;
|
||||
|
||||
function TImplDataTupleType.GetName: String;
|
||||
begin
|
||||
Result := 'Tuple';
|
||||
end;
|
||||
|
||||
{ TDataValueHelper }
|
||||
|
||||
function TDataValueHelper.AsTuple: TTupleValue;
|
||||
function TImplDataTupleType.GetKind: TDataKind;
|
||||
begin
|
||||
Result := Self.DataValue as IDataTupleValue;
|
||||
end;
|
||||
|
||||
{ TDataTypeHelper }
|
||||
|
||||
function TDataTypeHelper.AsTuple: TTupleType;
|
||||
begin
|
||||
Result := Self.DataType as IDataTupleType;
|
||||
end;
|
||||
|
||||
{ TTuple }
|
||||
|
||||
class function TTuple.Create(const AItems: array of IDataValue): IDataTupleValue;
|
||||
begin
|
||||
// Create a new value instance. The instance itself knows its item count
|
||||
// and will report the singleton "Tuple" type via its DataType property.
|
||||
Result := TImplDataTupleValue.Create(AItems);
|
||||
Result := dkTuple;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user