Type System

This commit is contained in:
Michael Schimmel
2025-08-26 11:06:35 +02:00
parent e4681e2bf7
commit 5adbe67d0b
15 changed files with 1426 additions and 612 deletions
+26 -26
View File
@@ -7,7 +7,7 @@ uses
Myc.Data.Types;
type
TDataTextType = class(TInterfacedObject, IDataType, IDataTextType)
TImplDataTextType = class(TInterfacedObject, IDataType, IDataTextType)
strict private
class var
FSingleton: IDataTextType;
@@ -25,7 +25,7 @@ uses
System.Rtti;
type
TDataTextValue = class(TInterfacedObject, IDataValue, IDataTextValue)
TImplDataTextValue = class(TInterfacedObject, IDataValue, IDataTextValue)
private
FValue: string;
function GetDataType: IDataType;
@@ -37,7 +37,7 @@ type
end;
// Singleton implementation for the empty string value.
TDataTextValueEmpty = class(TInterfacedObject, IDataValue, IDataTextValue)
TImplDataTextValueEmpty = class(TInterfacedObject, IDataValue, IDataTextValue)
strict private
class var
FSingleton: IDataTextValue;
@@ -52,84 +52,84 @@ type
class property Singleton: IDataTextValue read FSingleton;
end;
{ TDataTextType }
{ TImplDataTextType }
class constructor TDataTextType.CreateClass;
class constructor TImplDataTextType.CreateClass;
begin
FSingleton := TDataTextType.Create;
FSingleton := TImplDataTextType.Create;
end;
function TDataTextType.CreateValue(const AValue: string): IDataTextValue;
function TImplDataTextType.CreateValue(const AValue: string): IDataTextValue;
begin
// Use the singleton for empty strings.
if (AValue = '') then
Result := TDataTextValueEmpty.Singleton
Result := TImplDataTextValueEmpty.Singleton
else
Result := TDataTextValue.Create(AValue);
Result := TImplDataTextValue.Create(AValue);
end;
function TDataTextType.GetName: String;
function TImplDataTextType.GetName: String;
begin
Result := 'Text';
end;
function TDataTextType.GetKind: TDataKind;
function TImplDataTextType.GetKind: TDataKind;
begin
Result := dkText;
end;
{ TDataTextValue }
{ TImplDataTextValue }
constructor TDataTextValue.Create(const AValue: string);
constructor TImplDataTextValue.Create(const AValue: string);
begin
inherited Create;
FValue := AValue;
end;
function TDataTextValue.GetDataType: IDataType;
function TImplDataTextValue.GetDataType: IDataType;
begin
Result := TDataTextType.Singleton;
Result := TImplDataTextType.Singleton;
end;
function TDataTextValue.GetAsString: string;
function TImplDataTextValue.GetAsString: string;
begin
Result := FValue;
end;
function TDataTextValue.GetValue: string;
function TImplDataTextValue.GetValue: string;
begin
Result := FValue;
end;
function TDataTextValue.AsTValue: TValue;
function TImplDataTextValue.AsTValue: TValue;
begin
Result := TValue.From<string>(FValue);
end;
{ TDataTextValueEmpty }
{ TImplDataTextValueEmpty }
class constructor TDataTextValueEmpty.CreateClass;
class constructor TImplDataTextValueEmpty.CreateClass;
begin
FSingleton := TDataTextValueEmpty.Create;
FSingleton := TImplDataTextValueEmpty.Create;
FEmptyTValue := TValue.From<string>('');
end;
function TDataTextValueEmpty.GetAsString: string;
function TImplDataTextValueEmpty.GetAsString: string;
begin
Result := '';
end;
function TDataTextValueEmpty.GetDataType: IDataType;
function TImplDataTextValueEmpty.GetDataType: IDataType;
begin
Result := TDataTextType.Singleton;
Result := TImplDataTextType.Singleton;
end;
function TDataTextValueEmpty.GetValue: string;
function TImplDataTextValueEmpty.GetValue: string;
begin
Result := '';
end;
function TDataTextValueEmpty.AsTValue: TValue;
function TImplDataTextValueEmpty.AsTValue: TValue;
begin
Result := FEmptyTValue;
end;