The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



Interface of SDL_DStruct


const
  SABuffSize = 32768;                                  { size of string buffer }
{$IFDEF PAIDVERS}
  SDLVersionInfo = 'dstruct_r1050_full';
  IsLightEd = false;
{$ELSE}
  SDLVersionInfo = 'dstruct_r1050_lighted';
  IsLightEd = true;
{$ENDIF}
  release = 1050;

type
  ESDLDStructError = class(ESDLError);     { exception type to indicate errors }
  TLogicOp = (loAND, loOR, loXOR, loANDNot, loORNot, loXORNot);
  TCombination  = array[0..255] of byte;
  TCRC16Mode = (crcZModem, crcCCITT);
  TBeforeSortExchgEvent = procedure (Sender: TObject; InString: string;
  		     var OutString: string) of object;

  TSHACode = array [0..19] of Byte;             { hash code of SHA-1 algorithm }

  TBitFld = class(TComponent)
            private
              FSize     : longint;                         { size of bit field }
              FBitArray : array of byte;                           { bit field }
              procedure SetSize (s: longint);
              procedure SetBit (ix: longint; value: boolean);
              function  GetBit (ix: longint): boolean;
              procedure SetRandBitsIntern (NBits: integer);
            protected
              procedure AssignTo (Dest: TPersistent); override;
            public
              constructor Create (AOwner: TComponent); override;
              destructor  Destroy; override;
              procedure Assign(Source: TPersistent); override;
              procedure Clear;
              procedure Clone (Source: TBitFld);
              function  CountTrueBits: longint;
              function  FirstTrueBit: longint;
              procedure MakeListOfBits (var BitList: TIntArray; State: boolean);
              procedure ToggleBit (ix: longint);
              procedure CombineWith (SecondBArray: TBitFld; Operation: TLogicOp);
              procedure Invert;
              procedure RandomFill (Percent: double); overload;
              procedure RandomFill (NBits: integer); overload;
              property  Bit[ix: longint]: boolean
                           read GetBit write SetBit; default;
            published
              property  Size: longint read FSize write SetSize;
            end;
  TStringAccu = class(TComponent)
            private
              FSize     : longint;                       { size of string list }
              FStrArray : array of string;                       { string list }
              FCntArray : array of integer;                 { count of strings }
              function  GetString (ix: longint): string;
              function  GetCount (ix: longint): integer;
            public
              constructor Create (AOwner: TComponent); override;
              destructor  Destroy; override;
              procedure Clear;
              procedure Add (AString: string);
              property  Count[ix: integer]: integer read GetCount;
              property  Elem[ix: integer]: string read GetString; default;
              property  Size: longint read FSize;
            published
              //
            end;

  TByteMatrix = class(TComponent)
            private
              FNrCols    : integer;
              FNrRows    : integer;
              FByteMat   : array of array of byte;
              FOnChange  : TNotifyEvent;
              function  GetBit (ix, iy, ixBit: longint): boolean;
              function  GetByte (ix, iy: longint): byte;
              procedure SetNrRows (nr: longint);
              procedure SetNrCols (nc: longint);
              procedure SetBit (ix, iy, ixBit: integer; value: boolean);
              procedure SetByte (ix, iy: integer; value: byte);
            protected
              procedure   AssignTo (Dest: TPersistent); override;
            public
              constructor Create (AOwner: TComponent); override;
              destructor Destroy; override;
              procedure Assign(Source: TPersistent); override;
              procedure Changed;
              procedure Fill (value: byte);
              function Resize (NrColumns, NrRows: integer): boolean;
              procedure ToggleBit (col, row, ixBit: integer);
              procedure MirrorColumns;
              procedure MirrorRows;
              procedure CombineWith (SecondByteMatrix: TByteMatrix;
                                     Operation: TLogicOp);
              property Bit[col,row,BitIx: integer]: boolean
                          read GetBit write SetBit;
              property Byte[col,row:integer]: byte
                          read GetByte write SetByte; default;
            published
              property NrOfRows: integer read FNrRows write SetNrRows;
              property NrOfColumns: integer read FNrCols write SetNrCols;
              property OnChange: TNotifyEvent read FOnChange write FOnChange;
            end;


  TFifo = class(TComponent)
          private
            FInPoi  : longint;                                 { input pointer }
            FOutPoi : longint;                                { output pointer }
            FLength : longint;                                { length of Fifo }
            FData   : array of byte;                            { data element }
            procedure SetSize (value: longint);
          public
            constructor Create (AOwner: TComponent); override;
            destructor  Destroy; override;
            procedure   Clear;
            function    PutByte (InByte: byte): boolean;
            function    LoadBack (InByte: Byte): boolean;
            function    ForceByte (InByte: byte): boolean;
            function    GetByte (var OutByte: byte): boolean;
            function    SenseByte (ix: longint;
                          var OutByte: byte): boolean;
            function    CountBytes: longint;
          published
            property Size: longint read FLength write SetSize;
          end;


  TDecodeSt = (rlData, rlLeadin, rlCnt);
  TRLEncoder = class (TComponent)
    private
      FBufLeng    : integer;                       { length of encoding buffer }
      FBuffer     : array of byte;                           { encoding buffer }
      FBufPoi     : integer;
      FLeadInByte : byte;                       { lead-in byte for RL encoding }
      FDecodeSt   : TDecodeSt;                                 { decoder state }
      FCount      : byte;                       { byte counter for en/decoding }
      FLastB      : byte;                                { last byte container }
      procedure SetBufLeng (leng: integer);
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
      procedure Reset;
      function  Decode (InByte: byte): boolean;
      function  Encode (var InBuf: array of byte; NumBytes: integer): boolean;
      procedure GetResult (var OutBuf: array of byte);
      function  Finish (var OutBuf: array of byte): integer;
    published
      property BufLeng: integer read FBufLeng write SetBufLeng;
    end;

  TAssocArray = class (TComponent)
    private
      FNEntries     : integer;        
      FDataArray    : array of Variant;
      FKeyArray     : array of string;
      FGranularity  : integer;
      FIgnoreCase   : boolean;
      FDataID       : string;
      function GetKeys (ix: integer): string;
      function GetValues (ix: integer): Variant;
      procedure SetKeys (ix: integer; v: string);
      procedure SetValues (ix: integer; v: Variant);
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
      procedure Add (Key: string; Value: Variant);
      procedure Clear;
      property Keys[ix: integer]: string read GetKeys write SetKeys;
      property NumEntries: integer read FNEntries;
      function Remove (Key: string): boolean;
      function Resolve (Key: string): Variant;
      function ResolveAsNumber (Key: string): double;
      function ResolveAsString (Key: string): string;
      property Values[ix: integer]: Variant read GetValues write SetValues;
      function AddXMLAttributes (Attributes: string): integer;
      function ReadFromXMLStream (const InStream: TStream; DataID: string): boolean;
      procedure WriteToXMLStream (const OutStream: TStream; CreateHeader: boolean;
                                  DataID: string);
    published
      property  DataID: string read FDataID write FDataID;
      property IgnoreCase: boolean read FIgnoreCase write FIgnoreCase;
      property Granularity: integer read FGranularity write FGranularity;
    end;


  TStringPool = array[1..SABuffSize] of byte;
  TStringArray = class (TComponent)
    private
      FNCol         : longint;                             { number of columns }
      FNRow         : longint;                                { number of rows }
      FAllocRowsBy  : longint;                { number of rows to be allocated }
      FRAllocated   : longint;            { number of rows currently allocated }
      FNumPoolAddr  : integer;                 { number of string pool buffers }
      FFirstFree    : array of longint; { offset of first free byte in buffers }
      FPoiArray     : array of array of longint; { array of pointers to string }
      FSortIx       : array of longint;                   { current sort index }
      FStgPool      : array of TStringPool;                      { string pool }
      FRowAttrib    : array of byte;                          { row attributes }
      FColAttrib    : array of byte;                       { column attributes }
      FOnChange     : TNotifyEvent;
      FOnBefSortExc : TBeforeSortExchgEvent;
      FOnPercentDone: TOnPercentDoneEvent;
      {$IFDEF SDLDEBUG}
      procedure GetDebugInfo (var SL: TStringList);
      {$ENDIF}

      function  GetAsNumber (c, r: longint): double;
      function  GetAsInteger (c, r: longint): integer;
      function  GetSortOrder (ix: longint): longint;
      function  GetString (c,r: longint): Shortstring;
      procedure SetString (c,r: longint; s: Shortstring);
      function  GetRowAttrib (r: longint): byte;
      procedure SetRowAttrib (r: longint; b: byte);
      function  GetColAttrib (c: longint): byte;
      procedure SetColAttrib (c: longint; b: byte);
      procedure SetNrCols (NrCols: longint);
      procedure SetNrRows (NrRows: longint);
      procedure SetSortOrder (ix: longint; position: longint);
      procedure SetAllocRowsBy (NrAllocRows: longint);
      function  FindCellIntern (FindStr: string; MatchCase: boolean; 
                    ColLow, ColHigh, RowLow, RowHigh: longint; 
                    var Col, row: longint; Exact: boolean): boolean;
    protected
      procedure BeforeSortExchange (InString: string; var OutString: string);
    public
      constructor Create (AOwner: TComponent); override;
      destructor  Destroy; override;
      function  AddRow: longint;
      property  AsInteger [ACol, ARow: longint]: integer read GetAsInteger;
      property  AsNumber [ACol, ARow: longint]: double read GetAsNumber;
      procedure Changed;
      procedure Clear;
      property  ColAttrib [c: longint]: byte read GetColAttrib write SetColAttrib;
      function  ColumnEmpty (ACol: longint): boolean;
      procedure CommitSorting;
      procedure CopyRow (Source, Target: integer);
      property  Elem [c,r: longint]: ShortString
                    read GetString write SetString; default;
      procedure Fill (s: ShortString);
      function  FindCell (FindStr: string; MatchCase: boolean;
                    ColLow, ColHigh, RowLow, RowHigh: longint;
                    var Col, row: longint): boolean;
      function  FindCellExact (FindStr: string; MatchCase: boolean;
                    ColLow, ColHigh, RowLow, RowHigh: longint; 
                    var Col, row: longint): boolean;
      function  FindCellInSortedColumn (FindStr: string; MatchCase: boolean; 
                    ColIx, RowLow, RowHigh: longint; ColIsAscending: boolean; 
                    var row: longint): boolean;
      procedure GarbageCollection;
      procedure InsertRow (r: longint);
      function  LoadFromXMLFile (FName: string; DataID: string): boolean;
      property  NumBuffers: integer read FNumPoolAddr;
      function  ReadFromOpenXMLFile (var InFile: TextFile; DataID: string): boolean;
      procedure RemoveRow (r: longint);
      function  Resize (Nc, Nr: longint): boolean;
      property  RowAttrib [r: longint]: byte read GetRowAttrib write SetRowAttrib;
      function  RowEmpty (ARow: longint): boolean;
      procedure SaveAsXMLFile (FName: string; DataID: string);
      procedure WriteToOpenXMLFile (var OutFile : TextFile; CreateHeader: boolean;
                    DataID: string);
      procedure Sort (Col, ColSec: longint; Ascending: boolean);
      property  SortOrder[ix: longint]: longint read GetSortOrder write SetSortOrder;
      procedure UnSort;
    published
      property  AllocRowsBy: longint read FAllocRowsBy write SetAllocRowsBy;
      property  NrOfColumns: longint read FNCol write SetNrCols;
      property  NrOfRows: longint read FNRow write SetNrRows;
      property  OnChange: TNotifyEvent read FOnChange write FOnChange;
      property  OnPercentDone: TOnPercentDoneEvent 
                    read FOnPercentDone write FOnPercentDone;
      property  OnBeforeSortExchange: TBeforeSortExchgEvent 
                    read FOnBefSortExc write FOnBefSortExc;
    end;


  function CalcCRC32ofFile
              (FName : string)              { filename of file to be processed }
                     : longint;                                { resulting CRC }
  function CalcNextCRC16
             (inbyte : byte;                       { next byte of input stream }
                 crc : word)                                    { CRC register }
                     : word;                                   { resulting CRC }
  function CalcNextCRC32
             (inbyte : byte;                       { next byte of input stream }
                 crc : longint)                                 { CRC register }
                     : longint;                                { resulting CRC }
  function CRC16ofBuffer
             (Buffer : TBytes;                                  { input buffer }
             NumData : integer;
           CRC16Mode : TCRC16Mode)           { number of bytes in input buffer }
                     : word;                                      { CRC result }
  function CRC32ofBuffer
             (Buffer : TBytes;                                  { input buffer }
             NumData : integer)              { number of bytes in input buffer }
                     : longint;                                   { CRC result }
  function DecodeASCII85
           (InStream,                           { ASCII85 stream to be decoded }
           OutStream : TStream)                                 { decoded data }
                     : integer;                                 { error number }
  procedure EncodeASCII85
           (InStream,                       { data stream to be BASE85 encoded }
           OutStream : TStream);                                { encoded data }
  function IndexOfNearestArrayValue
              (Value : double;                          { value to be searched }
         ArrOfValues : array of double)                      { array of values }
                     : integer; overload;    { index of nearest value in array }
  function IndexOfNearestArrayValue
              (Value : integer;                         { value to be searched }
         ArrOfValues : array of integer)                     { array of values }
                     : integer; overload;    { index of nearest value in array }
  function NextCombination
   (var CurrentCombi : TCombination;                     { current combination }
              MaxVal : integer)                              { range of digits }
                     : boolean;                  { FALSE: no more combinations }
  function NextPermutation
  (var CurrentPermut : TCombination)                     { current permutation }
                     : boolean;                  { FALSE: no more permutations }
{$IFNDEF DOTNET}
  function SHA1DigestToHex
             (Digest : TSHACode)                              { SHA1 hash code }
                     : string;       { hexadecimal representation of hash code }
  function SHA1FromFile
        (const FName : string)                                    { input file }
                     : TSHACode;                              { SHA1 hash code }
  function SHA1FromStream
           (InStream : TStream)                                 { input stream }
                     : TSHACode;                              { SHA1 hash code }
  function SHA1FromString
     (const InString : string)                                  { input string }
                     : TSHACode;                              { SHA1 hash code }
{$ENDIF}




Last Update: 2012-Oct-20