Generic indicator factory
This commit is contained in:
@@ -86,7 +86,8 @@ type
|
||||
function GetRawData: Pointer; inline;
|
||||
|
||||
public
|
||||
constructor Create(const ALayout: TLayout);
|
||||
constructor Create(const ALayout: TLayout); overload;
|
||||
constructor Create(const ALayout: TLayout; const ABuffer: TBytes); overload;
|
||||
|
||||
class operator Finalize(var Dest: TDataRecord);
|
||||
class operator Assign(var Dest: TDataRecord; const [ref] Src: TDataRecord);
|
||||
@@ -120,13 +121,17 @@ const
|
||||
|
||||
{ TDataRecord }
|
||||
|
||||
constructor TDataRecord.Create(const ALayout: TLayout);
|
||||
constructor TDataRecord.Create(const ALayout: TLayout; const ABuffer: TBytes);
|
||||
begin
|
||||
FLayout := ALayout;
|
||||
FBuffer := ABuffer;
|
||||
end;
|
||||
|
||||
SetLength(FBuffer, FLayout.Size);
|
||||
for var i := 0 to High(FLayout.Fields) do
|
||||
FLayout.Fields[i].InitField(FBuffer);
|
||||
constructor TDataRecord.Create(const ALayout: TLayout);
|
||||
begin
|
||||
var buf: TBytes;
|
||||
SetLength(buf, ALayout.Size);
|
||||
Create(ALayout, buf);
|
||||
end;
|
||||
|
||||
procedure TDataRecord.CopyFrom<T>(const Src: T);
|
||||
@@ -154,12 +159,19 @@ end;
|
||||
|
||||
class function TDataRecord.FromRecord<T>: TDataRecord;
|
||||
begin
|
||||
Result.Create(TLayout.FromRecord<T>);
|
||||
var layout := TLayout.FromRecord<T>;
|
||||
var buf: TBytes;
|
||||
|
||||
SetLength(buf, layout.Size);
|
||||
for var i := 0 to High(layout.Fields) do
|
||||
layout.Fields[i].InitField(buf);
|
||||
|
||||
Result.Create(layout, buf);
|
||||
end;
|
||||
|
||||
class function TDataRecord.FromRecord<T>(const Src: T): TDataRecord;
|
||||
begin
|
||||
Result.Create(TLayout.FromRecord<T>);
|
||||
Result := FromRecord<T>;
|
||||
Result.CopyFrom<T>(Src);
|
||||
end;
|
||||
|
||||
@@ -226,7 +238,9 @@ begin
|
||||
if Dest.FLayout.FFields <> Src.FLayout.FFields then
|
||||
begin
|
||||
Finalize(Dest);
|
||||
Dest.Create(Src.Layout);
|
||||
var buf: TBytes;
|
||||
SetLength(buf, Length(Dest.FBuffer));
|
||||
Dest.Create(Src.Layout, buf);
|
||||
end;
|
||||
|
||||
for var i := 0 to High(Dest.Layout.Fields) do
|
||||
|
||||
Reference in New Issue
Block a user