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
+19 -19
View File
@@ -8,7 +8,7 @@ uses
Myc.Data.Types;
type
TDataEnumType = class(TInterfacedObject, IDataEnumType)
TImplDataEnumType = class(TInterfacedObject, IDataEnumType)
private
FName: string;
FIdentifiers: TArray<string>;
@@ -31,7 +31,7 @@ uses
System.Rtti;
type
TDataEnumValue = class(TInterfacedObject, IDataEnumValue)
TImplDataEnumValue = class(TInterfacedObject, IDataEnumValue)
private
FDataType: IDataEnumType;
FValue: Integer;
@@ -43,9 +43,9 @@ type
constructor Create(const ADataType: IDataEnumType; const AValue: Integer);
end;
{ TDataEnumType }
{ TImplDataEnumType }
constructor TDataEnumType.Create(const AName: string; const AIdentifiers: array of string);
constructor TImplDataEnumType.Create(const AName: string; const AIdentifiers: array of string);
var
i: Integer;
begin
@@ -62,46 +62,46 @@ begin
end;
end;
destructor TDataEnumType.Destroy;
destructor TImplDataEnumType.Destroy;
begin
FIdentifierMap.Free;
inherited;
end;
function TDataEnumType.GetName: String;
function TImplDataEnumType.GetName: String;
begin
Result := FName;
end;
function TDataEnumType.GetKind: TDataKind;
function TImplDataEnumType.GetKind: TDataKind;
begin
Result := dkEnum;
end;
function TDataEnumType.GetIdentifier(Idx: Integer): string;
function TImplDataEnumType.GetIdentifier(Idx: Integer): string;
begin
Result := FIdentifiers[Idx];
end;
function TDataEnumType.GetIdentifierCount: Integer;
function TImplDataEnumType.GetIdentifierCount: Integer;
begin
Result := Length(FIdentifiers);
end;
function TDataEnumType.IndexOf(const AIdentifier: string): Integer;
function TImplDataEnumType.IndexOf(const AIdentifier: string): Integer;
begin
if not FIdentifierMap.TryGetValue(AIdentifier, Result) then
Result := -1;
end;
function TDataEnumType.CreateValue(const AValue: Integer): IDataEnumValue;
function TImplDataEnumType.CreateValue(const AValue: Integer): IDataEnumValue;
begin
if (AValue < 0) or (AValue >= Length(FIdentifiers)) then
raise EArgumentException.Create('Invalid enum value');
Result := TDataEnumValue.Create(Self, AValue);
Result := TImplDataEnumValue.Create(Self, AValue);
end;
function TDataEnumType.CreateValue(const AIdentifier: string): IDataEnumValue;
function TImplDataEnumType.CreateValue(const AIdentifier: string): IDataEnumValue;
var
idx: Integer;
begin
@@ -111,30 +111,30 @@ begin
Result := CreateValue(idx);
end;
{ TDataEnumValue }
{ TImplDataEnumValue }
constructor TDataEnumValue.Create(const ADataType: IDataEnumType; const AValue: Integer);
constructor TImplDataEnumValue.Create(const ADataType: IDataEnumType; const AValue: Integer);
begin
FDataType := ADataType;
FValue := AValue;
end;
function TDataEnumValue.GetDataType: IDataType;
function TImplDataEnumValue.GetDataType: IDataType;
begin
Result := FDataType;
end;
function TDataEnumValue.GetAsString: string;
function TImplDataEnumValue.GetAsString: string;
begin
Result := FDataType.Identifiers[FValue];
end;
function TDataEnumValue.GetValue: Integer;
function TImplDataEnumValue.GetValue: Integer;
begin
Result := FValue;
end;
function TDataEnumValue.AsTValue: TValue;
function TImplDataEnumValue.AsTValue: TValue;
begin
Result := TValue.From<Integer>(FValue);
end;