Data Types
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
unit Myc.Data.Types;
|
||||
|
||||
interface
|
||||
|
||||
type
|
||||
IDataType = interface
|
||||
function GetName: String;
|
||||
property Name: String read GetName;
|
||||
end;
|
||||
|
||||
IDataValue = interface
|
||||
function GetDataType: IDataType;
|
||||
property DataType: IDataType read GetDataType;
|
||||
end;
|
||||
|
||||
IDataOrdinalValue = interface(IDataValue)
|
||||
['{DF512FD0-D513-4B96-9687-C80624E475A4}']
|
||||
function GetValue: Int64;
|
||||
property Value: Int64 read GetValue;
|
||||
end;
|
||||
|
||||
IDataOrdinalType = interface(IDataType)
|
||||
['{BE97F145-3634-4F56-9783-FD2C3DD485CA}']
|
||||
function CreateValue(Init: Int64): IDataOrdinalValue;
|
||||
end;
|
||||
|
||||
IDataFloatValue = interface(IDataValue)
|
||||
['{A6E1E8B5-B8E5-4F4B-9B2E-8E8E9F8F8B8E}']
|
||||
function GetValue: Double;
|
||||
property Value: Double read GetValue;
|
||||
end;
|
||||
|
||||
IDataFloatType = interface(IDataType)
|
||||
['{B7E2E9B6-B9E6-4F5B-9C3E-9E9E0F9F9C9F}']
|
||||
function CreateValue(Init: Double): IDataFloatValue;
|
||||
end;
|
||||
|
||||
IDataRecordValue = interface(IDataValue)
|
||||
['{53B63A49-720D-4E3E-8EE5-3EA45BA93E58}']
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
property Items[Idx: Integer]: IDataValue read GetItem; default;
|
||||
end;
|
||||
|
||||
TRecordField = record
|
||||
Name: string;
|
||||
DataType: IDataType;
|
||||
public
|
||||
constructor Create(const AName: string; const ADataType: IDataType);
|
||||
end;
|
||||
|
||||
IDataRecordType = interface(IDataType)
|
||||
['{7A266BA0-B1AF-416B-941F-A730D6EDA333}']
|
||||
function GetFieldCount: Integer;
|
||||
function GetField(Idx: Integer): TRecordField;
|
||||
function IndexOf(const AName: string): Integer;
|
||||
function CreateValue(const AItems: array of IDataValue): IDataRecordValue;
|
||||
property FieldCount: Integer read GetFieldCount;
|
||||
property Fields[Idx: Integer]: TRecordField read GetField; default;
|
||||
end;
|
||||
|
||||
IDataTupleValue = interface(IDataValue)
|
||||
['{E1D5B0D1-8A1C-4B7E-9F2D-3A4B5C6D7E8F}']
|
||||
function GetItemCount: Integer;
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
property ItemCount: Integer read GetItemCount;
|
||||
property Items[Idx: Integer]: IDataValue read GetItem; default;
|
||||
end;
|
||||
|
||||
IDataTupleType = interface(IDataType)
|
||||
['{9442043E-99AC-4464-99E4-75F1BE1F3118}']
|
||||
end;
|
||||
|
||||
IDataArrayValue = interface(IDataValue)
|
||||
['{1F3A4B5C-6D7E-4F1A-8B9C-0D1E2F3A4B5C}']
|
||||
function GetElementCount: Integer;
|
||||
function GetItem(Idx: Integer): IDataValue;
|
||||
property ElementCount: Integer read GetElementCount;
|
||||
property Items[Idx: Integer]: IDataValue read GetItem; default;
|
||||
end;
|
||||
|
||||
IDataArrayType = interface(IDataType)
|
||||
['{7E8F9A0B-C1D2-4E3F-A4B5-C6D7E8F9A0B1}']
|
||||
function GetElementType: IDataType;
|
||||
function CreateValue(const AItems: array of IDataValue): IDataArrayValue;
|
||||
property ElementType: IDataType read GetElementType;
|
||||
end;
|
||||
|
||||
TDataType = record
|
||||
private
|
||||
FDataType: IDataType;
|
||||
function GetName: String; inline;
|
||||
public
|
||||
constructor Create(const ADataType: IDataType);
|
||||
|
||||
class operator Implicit(const A: IDataType): TDataType; overload;
|
||||
class operator Implicit(const A: TDataType): IDataType; overload;
|
||||
|
||||
property DataType: IDataType read FDataType;
|
||||
property Name: String read GetName;
|
||||
end;
|
||||
|
||||
TDataValue = record
|
||||
private
|
||||
FDataValue: IDataValue;
|
||||
function GetDataType: IDataType; inline;
|
||||
public
|
||||
constructor Create(const ADataValue: IDataValue);
|
||||
|
||||
class operator Implicit(const A: IDataValue): TDataValue; overload;
|
||||
class operator Implicit(const A: TDataValue): IDataValue; overload;
|
||||
|
||||
property DataValue: IDataValue read FDataValue;
|
||||
property DataType: IDataType read GetDataType;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TRecordField }
|
||||
|
||||
constructor TRecordField.Create(const AName: string; const ADataType: IDataType);
|
||||
begin
|
||||
Name := AName;
|
||||
DataType := ADataType;
|
||||
end;
|
||||
|
||||
{ TDataType }
|
||||
|
||||
constructor TDataType.Create(const ADataType: IDataType);
|
||||
begin
|
||||
FDataType := ADataType;
|
||||
end;
|
||||
|
||||
function TDataType.GetName: String;
|
||||
begin
|
||||
if Assigned(FDataType) then
|
||||
Result := FDataType.Name
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
class operator TDataType.Implicit(const A: TDataType): IDataType;
|
||||
begin
|
||||
Result := A.FDataType;
|
||||
end;
|
||||
|
||||
class operator TDataType.Implicit(const A: IDataType): TDataType;
|
||||
begin
|
||||
Result.FDataType := A;
|
||||
end;
|
||||
|
||||
{ TDataValue }
|
||||
|
||||
constructor TDataValue.Create(const ADataValue: IDataValue);
|
||||
begin
|
||||
FDataValue := ADataValue;
|
||||
end;
|
||||
|
||||
function TDataValue.GetDataType: IDataType;
|
||||
begin
|
||||
if Assigned(FDataValue) then
|
||||
Result := FDataValue.DataType
|
||||
else
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const A: TDataValue): IDataValue;
|
||||
begin
|
||||
Result := A.FDataValue;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const A: IDataValue): TDataValue;
|
||||
begin
|
||||
Result.FDataValue := A;
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user