Data POD
This commit is contained in:
+24
-11
@@ -27,7 +27,6 @@ type
|
|||||||
);
|
);
|
||||||
|
|
||||||
TScalarBytes = array[0..15] of Byte;
|
TScalarBytes = array[0..15] of Byte;
|
||||||
|
|
||||||
TScalarPChar = array[0..7] of Char;
|
TScalarPChar = array[0..7] of Char;
|
||||||
TScalarString = String[15];
|
TScalarString = String[15];
|
||||||
|
|
||||||
@@ -186,9 +185,11 @@ type
|
|||||||
|
|
||||||
function GetDef: TScalarRecordDefinition; inline;
|
function GetDef: TScalarRecordDefinition; inline;
|
||||||
function GetFields: TArray<TScalarValue>; inline;
|
function GetFields: TArray<TScalarValue>; inline;
|
||||||
|
function GetItems(const Name: String): TScalar;
|
||||||
|
|
||||||
property Def: TScalarRecordDefinition read GetDef;
|
property Def: TScalarRecordDefinition read GetDef;
|
||||||
property Fields: TArray<TScalarValue> read GetFields;
|
property Fields: TArray<TScalarValue> read GetFields;
|
||||||
|
property Items[const Name: String]: TScalar read GetItems; default;
|
||||||
|
|
||||||
strict private
|
strict private
|
||||||
FDef: TScalarRecordDefinition;
|
FDef: TScalarRecordDefinition;
|
||||||
@@ -222,17 +223,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class function TScalarValue.FromBytes(const AValue: TScalarBytes): TScalarValue;
|
class function TScalarValue.FromBytes(const AValue: TScalarBytes): TScalarValue;
|
||||||
var
|
|
||||||
len: Integer;
|
|
||||||
begin
|
begin
|
||||||
FillChar(Result.FBytes, SizeOf(Result.FBytes), 0);
|
Result.FBytes := AValue;
|
||||||
len := Length(AValue);
|
|
||||||
if (len > 0) then
|
|
||||||
begin
|
|
||||||
if (len > SizeOf(Result.FBytes)) then
|
|
||||||
len := SizeOf(Result.FBytes);
|
|
||||||
Move(AValue[0], Result.FBytes[0], len);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TScalarValue.FromChar(AValue: Char): TScalarValue;
|
class function TScalarValue.FromChar(AValue: Char): TScalarValue;
|
||||||
@@ -538,6 +530,27 @@ begin
|
|||||||
Result := FFields;
|
Result := FFields;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TScalarRecord.GetItems(const Name: String): TScalar;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
fieldDef: TScalarRecordField;
|
||||||
|
begin
|
||||||
|
// Find the index of the field by name (case-insensitive)
|
||||||
|
for i := 0 to Length(FDef.Fields) - 1 do
|
||||||
|
begin
|
||||||
|
fieldDef := FDef.Fields[i];
|
||||||
|
if (CompareText(fieldDef.Name, Name) = 0) then
|
||||||
|
begin
|
||||||
|
// Found it. Construct the TScalar result from the kind and value.
|
||||||
|
Result.Create(fieldDef.Kind, FFields[i]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// If we get here, the field was not found.
|
||||||
|
raise EArgumentException.CreateFmt('Field "%s" not found in record definition.', [Name]);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TScalarSeries }
|
{ TScalarSeries }
|
||||||
|
|
||||||
constructor TScalarSeries.Create(AKind: TScalarKind; const AItems: TSeries<TScalarValue>);
|
constructor TScalarSeries.Create(AKind: TScalarKind; const AItems: TSeries<TScalarValue>);
|
||||||
|
|||||||
Reference in New Issue
Block a user