⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 labraddatastructures.pas

📁 As science advances, novel experiments are becoming more and more complex, requiring a zoo of contro
💻 PAS
📖 第 1 页 / 共 3 页
字号:
          raise ELabRADIndexError.Create('Cluster does not have enough elements', Indices, a);
        // Process the next index
        inc(a);
      end;

     ntArray:
      begin
        // Does the array have its entry?
        if not assigned(TypeNode.Down) then
          raise ELabRADIndexError.Create('Array does not have any elements', Indices, a);
        // Are there enough indices given?
        if a+TypeNode.Dimensions>length(Indices) then
          raise ELabRADIndexError.Create('Multidimensional arrays cannot be partially indexed', Indices, a);
        // Resolve array pointer
        move(DataPtr^, DataPtr, 4);
        // Check and calculate element offset
        SkipCnt:=0;
        for b:=0 to TypeNode.Dimensions-1 do begin
          // Read size and skip past it
          c:=sizeof(DataPtr^);
          move(DataPtr^, Size, 4);
          inc(DataPtr, 4+c*0);
          // Is the index outside of the array?
          if Indices[b+a]>=Size then
            raise ELabRADIndexError.Create('Array does not have enough elements along dimension '+inttostr(b+1), Indices, a);
          // Calculate number of elements to skip
          SkipCnt:=SkipCnt*Size + Indices[b+a];
        end;
        // Process the next index
        inc(a, TypeNode.Dimensions);
        // Step down the type tree
        TypeNode:=TypeNode.Down;
        // Calculate new data offset
        inc(DataPtr, SkipCnt*TypeNode.DataSize);
      end;
     else
      raise ELabRADIndexError.Create('Only clusters and arrays can be indexed ', Indices, a);
    end;
  end;
  // Present element information
  Result.Node:=TypeNode;
  Result.Data:=DataPtr;
  // Did we find the element we were looking for?
  if (RequiredTypeTag<>ntAnything) and (RequiredTypeTag<>TypeNode.NodeType) then
    raise ELabRADTypeError.Create(RequiredTypeTag, TypeNode.NodeType);
end;

function TLabRADData.Flatten(Endianness: TLabRADEndianness = enLittleEndian): string;
begin
  if Endianness=enLittleEndian then begin
    Result:=LabRADFlattenLittleEndian(fTypeTree.TopNode, fDataBuffer);
   end else begin
    Result:=LabRADFlattenBigEndian(fTypeTree.TopNode, fDataBuffer);
  end;
end;

function TLabRADData.Unflatten(var BufferPtr: PByte; var Size: integer): boolean;
begin
  if not assigned(fUnflattener) then ; // BARF
  Result:=fUnflattener.Unflatten(BufferPtr, Size);
  if Result then begin
    fUnflattener.Free;
    fUnflattener:=nil;
  end;
end;

function TLabRADData.Pretty(ShowTypes: Boolean=False): string;
begin
  Result:=LabRADPrettyPrint(fDataBuffer, fTypeTree.TopNode, ShowTypes);
end;
function TLabRADData.Pretty(Index: integer; ShowTypes: Boolean=False): string;
begin
  Result:=Pretty([Index]);
end;
function TLabRADData.Pretty(Indices: array of integer; ShowTypes: Boolean=False): string;
var I: TLRDInfo;
begin
  I:=Locate(Indices);
  Result:=LabRADPrettyPrint(I.Data, I.Node, ShowTypes);
end;

function TLabRADData.TypeTag:                 string; begin Result:=fTypeTag;         end;
function TLabRADData.TypeTag(Index: integer): string; begin Result:=TypeTag([Index]); end;
function TLabRADData.TypeTag(Indices: array of integer): string;
begin
  Result:=fTypeTree.TypeTag(Locate(Indices).Node);
end;

function TLabRADData.GetType:                 TLabRADDataType; begin Result:=GetType([]     ); end;
function TLabRADData.GetType(Index: integer): TLabRADDataType; begin Result:=GetType([Index]); end;
function TLabRADData.GetType(Indices: array of integer): TLabRADDataType;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=TLabRADDataType(Info.Node.NodeType);
end;


function TLabRADData.IsEmpty: boolean;
begin
  Result:=fTypeTree.TopNode.NodeType=ntEmpty;
end;

function TLabRADData.IsError: boolean;
begin
  Result:=(length(fTypeTag)>0) and (fTypeTag[1]='E');
end;


function TLabRADData.IsBoolean:                 boolean; begin Result:=IsBoolean([]     ); end;
function TLabRADData.IsBoolean(Index: integer): boolean; begin Result:=IsBoolean([Index]); end;
function TLabRADData.IsBoolean(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntBoolean;
end;

function TLabRADData.GetBoolean:                 boolean; begin Result:=GetBoolean([]     ); end;
function TLabRADData.GetBoolean(Index: integer): boolean; begin Result:=GetBoolean([Index]); end;
function TLabRADData.GetBoolean(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntBoolean);
  Result:=Info.Data^>0;
end;

procedure TLabRADData.SetBoolean(                Value: boolean); begin SetBoolean([],      Value); end;
procedure TLabRADData.SetBoolean(Index: integer; Value: boolean); begin SetBoolean([Index], Value); end;
procedure TLabRADData.SetBoolean(Indices: array of integer; Value: boolean);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntBoolean);
  if Value then Info.Data^:=1 else Info.Data^:=0;
end;


function TLabRADData.IsInteger:                 boolean; begin Result:=IsInteger([]     ); end;
function TLabRADData.IsInteger(Index: integer): boolean; begin Result:=IsInteger([Index]); end;
function TLabRADData.IsInteger(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntInteger;
end;

function TLabRADData.GetInteger:                 integer; begin Result:=GetInteger([]     ); end;
function TLabRADData.GetInteger(Index: integer): integer; begin Result:=GetInteger([Index]); end;
function TLabRADData.GetInteger(Indices: array of integer): integer;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntInteger);
  move(Info.Data^, Result, 4);
end;

procedure TLabRADData.SetInteger(       Value: integer); begin SetInteger([],      Value); end;
procedure TLabRADData.SetInteger(Index, Value: integer); begin SetInteger([Index], Value); end;
procedure TLabRADData.SetInteger(Indices: array of integer; Value: integer);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntInteger);
  move(Value, Info.Data^, 4);
end;


function TLabRADData.IsWord:                 boolean; begin Result:=IsWord([]     ); end;
function TLabRADData.IsWord(Index: integer): boolean; begin Result:=IsWord([Index]); end;
function TLabRADData.IsWord(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntWord;
end;

function TLabRADData.GetWord:                 longword; begin Result:=GetWord([]     ); end;
function TLabRADData.GetWord(Index: integer): longword; begin Result:=GetWord([Index]); end;
function TLabRADData.GetWord(Indices: array of integer): longword;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntWord);
  move(Info.Data^, Result, 4);
end;

procedure TLabRADData.SetWord(                Value: longword); begin SetWord([],      Value); end;
procedure TLabRADData.SetWord(Index: integer; Value: longword); begin SetWord([Index], Value); end;
procedure TLabRADData.SetWord(Indices: array of integer; Value: longword);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntWord);
  move(Value, Info.Data^, 4);
end;


function TLabRADData.IsValue:                 boolean; begin Result:=IsValue([]     ); end;
function TLabRADData.IsValue(Index: integer): boolean; begin Result:=IsValue([Index]); end;
function TLabRADData.IsValue(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntValue;
end;

function TLabRADData.GetValue:                 double; begin Result:=GetValue([]     ); end;
function TLabRADData.GetValue(Index: integer): double; begin Result:=GetValue([Index]); end;
function TLabRADData.GetValue(Indices: array of integer): double;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntValue);
  move(Info.Data^, Result, 8);
end;

procedure TLabRADData.SetValue(                Value: double); begin SetValue([],      Value); end;
procedure TLabRADData.SetValue(Index: integer; Value: double); begin SetValue([Index], Value); end;
procedure TLabRADData.SetValue(Indices: array of integer; Value: double);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntValue);
  move(Value, Info.Data^, 8);
end;


function TLabRADData.IsComplex:                 boolean; begin Result:=IsComplex([]     ); end;
function TLabRADData.IsComplex(Index: integer): boolean; begin Result:=IsComplex([Index]); end;
function TLabRADData.IsComplex(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntComplex;
end;

function TLabRADData.GetComplex:                 TLabRADComplex; begin Result:=GetComplex([]     ); end;
function TLabRADData.GetComplex(Index: integer): TLabRADComplex; begin Result:=GetComplex([Index]); end;
function TLabRADData.GetComplex(Indices: array of integer): TLabRADComplex;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntComplex);
  move(Info.Data^, Result, 16);
end;

procedure TLabRADData.SetComplex(                Value: TLabRADComplex); begin SetComplex([],      Value); end;
procedure TLabRADData.SetComplex(Index: integer; Value: TLabRADComplex); begin SetComplex([Index], Value); end;
procedure TLabRADData.SetComplex(Indices: array of integer; Value: TLabRADComplex);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntComplex);
  move(Value, Info.Data^, 16);
end;

procedure TLabRADData.SetComplex(                Real, Imag: double); begin SetComplex([],      Real, Imag); end;
procedure TLabRADData.SetComplex(Index: integer; Real, Imag: double); begin SetComplex([Index], Real, Imag); end;
procedure TLabRADData.SetComplex(Indices: array of integer; Real, Imag: double);
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntComplex);
  move(Real, Info.Data^, 8);
  inc(Info.Data, 8);
  move(Imag, Info.Data^, 8);
end;


function TLabRADData.GetUnits:                 string; begin Result:=GetUnits([]);      end;
function TLabRADData.GetUnits(Index: integer): string; begin Result:=GetUnits([Index]); end;
function TLabRADData.GetUnits(Indices: array of integer): string;
begin
  Result:=Locate(Indices).Node.Units;
end;


function TLabRADData.HasUnits:                 boolean; begin Result:=HasUnits([]);      end;
function TLabRADData.HasUnits(Index: integer): boolean; begin Result:=HasUnits([Index]); end;
function TLabRADData.HasUnits(Indices: array of integer): boolean;
begin
  Result:=Locate(Indices).Node.HasUnits;
end;


function TLabRADData.IsTimeStamp:                 boolean; begin Result:=IsTimeStamp([]     ); end;
function TLabRADData.IsTimeStamp(Index: integer): boolean; begin Result:=IsTimeStamp([Index]); end;
function TLabRADData.IsTimeStamp(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntTimeStamp;
end;

function TLabRADData.GetTimeStamp:                 TDateTime; begin Result:=GetTimeStamp([]     ); end;
function TLabRADData.GetTimeStamp(Index: integer): TDateTime; begin Result:=GetTimeStamp([Index]); end;
function TLabRADData.GetTimeStamp(Indices: array of integer): TDateTime;
var Info:      TLRDInfo;
    TimeStamp: TLabRADTimeStamp;
begin
  Info:=Locate(Indices, ntTimeStamp);
  move(Info.Data^, TimeStamp, 16);
  Result:=LabRADTimeStampToDateTime(TimeStamp);
end;

procedure TLabRADData.SetTimeStamp(                Value: TDateTime); begin SetTimeStamp([],      Value); end;
procedure TLabRADData.SetTimeStamp(Index: integer; Value: TDateTime); begin SetTimeStamp([Index], Value); end;
procedure TLabRADData.SetTimeStamp(Indices: array of integer; Value: TDateTime);
var Info:      TLRDInfo;
    TimeStamp: TLabRADTimeStamp;
begin
  TimeStamp:=LabRADDateTimeToTimeStamp(Value);
  Info:=Locate(Indices, ntTimeStamp);
  move(TimeStamp, Info.Data^, 16);
end;


function TLabRADData.IsString:                 boolean; begin Result:=IsString([]     ); end;
function TLabRADData.IsString(Index: integer): boolean; begin Result:=IsString([Index]); end;
function TLabRADData.IsString(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntString;
end;

function TLabRADData.GetString:                 string; begin Result:=GetString([]     ); end;
function TLabRADData.GetString(Index: integer): string; begin Result:=GetString([Index]); end;
function TLabRADData.GetString(Indices: array of integer): string;
var Info: TLRDInfo;
    Size: integer;
begin
  Info:=Locate(Indices, ntString);
  move(Info.Data^, Info.Data, 4);
  move(Info.Data^, Size, 4);
  inc(Info.Data, 4);
  setlength(Result, Size);
  move(Info.Data^, Result[1], Size);
end;

procedure TLabRADData.SetString(                Value: string); begin SetString([],      Value); end;
procedure TLabRADData.SetString(Index: integer; Value: string); begin SetString([Index], Value); end;
procedure TLabRADData.SetString(Indices: array of integer; Value: string);
var Info: TLRDInfo;
    Data: PByte;
    Size: integer;
begin
  Info:=Locate(Indices, ntString);
  move(Info.Data^, Data, 4);
  FreeMem(Data);
  Size:=length(Value);
  GetMem(Data, 4+Size);
  move(Data, Info.Data^, 4);
  move(Size, Data^, 4);
  inc(Data, 4);
  move(Value[1], Data^, Size);
end;


function TLabRADData.IsArray:                 boolean; begin Result:=IsArray([]     ); end;
function TLabRADData.IsArray(Index: integer): boolean; begin Result:=IsArray([Index]); end;
function TLabRADData.IsArray(Indices: array of integer): boolean;
var Info: TLRDInfo;
begin
  Info:=Locate(Indices, ntAnything);
  Result:=Info.Node.NodeType=ntArray;
end;

function TLabRADData.GetArraySize:                            TLabRADSizeArray; begin Result:=GetArraySize([]     ); end;
function TLabRADData.GetArraySize(Index: integer):            TLabRADSizeArray; begin Result:=GetArraySize([Index]); end;
function TLabRADData.GetArraySize(Indices: array of integer): TLabRADSizeArray;
var Info: TLRDInfo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -