QlpArrayUtils.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. unit QlpArrayUtils;
  2. {$I ..\Include\QRCodeGenLib.inc}
  3. interface
  4. uses
  5. Math,
  6. QlpQRCodeGenLibTypes;
  7. type
  8. TArrayUtils = class sealed(TObject)
  9. public
  10. /// <summary>
  11. /// Copies the specified array, truncating or padding with zeros (if
  12. /// necessary) so the copy has the specified length. For all indices that
  13. /// are valid in both the original array and the copy, the two arrays
  14. /// will contain identical values. For any indices that are valid in the
  15. /// copy but not the original, the copy will contain <c>0</c>. <br />Such
  16. /// indices will exist if and only if the specified length is greater
  17. /// than that of the original array.
  18. /// </summary>
  19. /// <param name="ANewLength">
  20. /// the length of the copy to be returned
  21. /// </param>
  22. /// <param name="AData">
  23. /// the array to be copied
  24. /// </param>
  25. /// <remarks>
  26. /// This Function Assumes <c>AOriginal</c> and <c>ANewLength</c> are
  27. /// Valid. (Non Null and Non Negative Respectively)
  28. /// </remarks>
  29. class function CopyOf(const AOriginal: TQRCodeGenLibInt32Array;
  30. ANewLength: Int32): TQRCodeGenLibInt32Array; static; inline;
  31. /// <summary>
  32. /// Assigns the specified <c>Int32</c> value to each element of the
  33. /// specified array of <c>Int32s</c>.
  34. /// </summary>
  35. /// <param name="ABuffer">
  36. /// the array to be filled
  37. /// </param>
  38. /// <param name="AFiller">
  39. /// the value to be stored in all elements of the array
  40. /// </param>
  41. class procedure Fill(const ABuffer: TQRCodeGenLibInt32Array;
  42. AFiller: Int32); overload; static; inline;
  43. /// <summary>
  44. /// Assigns the specified <c>Byte</c> value to each element of the
  45. /// specified array of <c>Bytes</c>.
  46. /// </summary>
  47. /// <param name="ABuffer">
  48. /// the array to be filled
  49. /// </param>
  50. /// <param name="AFiller">
  51. /// the value to be stored in all elements of the array
  52. /// </param>
  53. class procedure Fill(const ABuffer: TQRCodeGenLibByteArray; AFiller: Byte);
  54. overload; static; inline;
  55. end;
  56. implementation
  57. { TArrayUtils }
  58. class function TArrayUtils.CopyOf(const AOriginal: TQRCodeGenLibInt32Array;
  59. ANewLength: Int32): TQRCodeGenLibInt32Array;
  60. begin
  61. System.SetLength(Result, ANewLength);
  62. System.Move(AOriginal[0], Result[0], Min(System.Length(AOriginal), ANewLength)
  63. * System.SizeOf(Int32));
  64. end;
  65. class procedure TArrayUtils.Fill(const ABuffer: TQRCodeGenLibInt32Array;
  66. AFiller: Int32);
  67. var
  68. LIdx: Int32;
  69. begin
  70. for LIdx := System.Low(ABuffer) to System.High(ABuffer) do
  71. begin
  72. ABuffer[LIdx] := AFiller;
  73. end;
  74. end;
  75. class procedure TArrayUtils.Fill(const ABuffer: TQRCodeGenLibByteArray;
  76. AFiller: Byte);
  77. begin
  78. System.FillChar(ABuffer[0], System.Length(ABuffer) *
  79. System.SizeOf(Byte), AFiller);
  80. end;
  81. end.