Data Types
This commit is contained in:
@@ -7,7 +7,7 @@ uses
|
||||
Myc.Data.Types;
|
||||
|
||||
type
|
||||
TImplDataTextType = class(TInterfacedObject, IDataType, IDataTextType)
|
||||
TDataTextType = class(TInterfacedObject, IDataType, IDataTextType)
|
||||
strict private
|
||||
class var
|
||||
FSingleton: IDataTextType;
|
||||
@@ -19,7 +19,10 @@ type
|
||||
class property Singleton: IDataTextType read FSingleton;
|
||||
end;
|
||||
|
||||
TImplDataTextValue = class(TInterfacedObject, IDataValue, IDataTextValue)
|
||||
implementation
|
||||
|
||||
type
|
||||
TDataTextValue = class(TInterfacedObject, IDataValue, IDataTextValue)
|
||||
private
|
||||
FValue: string;
|
||||
function GetDataType: IDataType;
|
||||
@@ -29,51 +32,89 @@ type
|
||||
constructor Create(const AValue: string);
|
||||
end;
|
||||
|
||||
implementation
|
||||
// Singleton implementation for the empty string value.
|
||||
TDataTextValueEmpty = class(TInterfacedObject, IDataValue, IDataTextValue)
|
||||
strict private
|
||||
class var
|
||||
FSingleton: IDataTextValue;
|
||||
class constructor CreateClass;
|
||||
private
|
||||
function GetDataType: IDataType;
|
||||
function GetAsString: string;
|
||||
function GetValue: string;
|
||||
public
|
||||
class property Singleton: IDataTextValue read FSingleton;
|
||||
end;
|
||||
|
||||
{ TImplDataTextType }
|
||||
{ TDataTextType }
|
||||
|
||||
class constructor TImplDataTextType.CreateClass;
|
||||
class constructor TDataTextType.CreateClass;
|
||||
begin
|
||||
FSingleton := TImplDataTextType.Create;
|
||||
FSingleton := TDataTextType.Create;
|
||||
end;
|
||||
|
||||
function TImplDataTextType.CreateValue(const AValue: string): IDataTextValue;
|
||||
function TDataTextType.CreateValue(const AValue: string): IDataTextValue;
|
||||
begin
|
||||
Result := TImplDataTextValue.Create(AValue);
|
||||
// Use the singleton for empty strings.
|
||||
if (AValue = '') then
|
||||
Result := TDataTextValueEmpty.Singleton
|
||||
else
|
||||
Result := TDataTextValue.Create(AValue);
|
||||
end;
|
||||
|
||||
function TImplDataTextType.GetName: String;
|
||||
function TDataTextType.GetName: String;
|
||||
begin
|
||||
Result := 'Text';
|
||||
end;
|
||||
|
||||
function TImplDataTextType.GetKind: TDataKind;
|
||||
function TDataTextType.GetKind: TDataKind;
|
||||
begin
|
||||
Result := dkText;
|
||||
end;
|
||||
|
||||
{ TImplDataTextValue }
|
||||
{ TDataTextValue }
|
||||
|
||||
constructor TImplDataTextValue.Create(const AValue: string);
|
||||
constructor TDataTextValue.Create(const AValue: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FValue := AValue;
|
||||
end;
|
||||
|
||||
function TImplDataTextValue.GetDataType: IDataType;
|
||||
function TDataTextValue.GetDataType: IDataType;
|
||||
begin
|
||||
Result := TImplDataTextType.Singleton;
|
||||
Result := TDataTextType.Singleton;
|
||||
end;
|
||||
|
||||
function TImplDataTextValue.GetAsString: string;
|
||||
function TDataTextValue.GetAsString: string;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
function TImplDataTextValue.GetValue: string;
|
||||
function TDataTextValue.GetValue: string;
|
||||
begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
{ TDataTextValueEmpty }
|
||||
|
||||
class constructor TDataTextValueEmpty.CreateClass;
|
||||
begin
|
||||
FSingleton := TDataTextValueEmpty.Create;
|
||||
end;
|
||||
|
||||
function TDataTextValueEmpty.GetAsString: string;
|
||||
begin
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
function TDataTextValueEmpty.GetDataType: IDataType;
|
||||
begin
|
||||
Result := TDataTextType.Singleton;
|
||||
end;
|
||||
|
||||
function TDataTextValueEmpty.GetValue: string;
|
||||
begin
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user