syshelph.inc 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. {%mainunit syshelpers.pp}
  2. Type
  3. generic TArray<T> = array of T;
  4. TStringArray = Array of string;
  5. TCharArray = Array of char;
  6. TEndian = ObjPas.TEndian;
  7. TByteBitIndex = 0..7;
  8. TShortIntBitIndex = 0..7;
  9. TWordBitIndex = 0..15;
  10. TSmallIntBitIndex = 0..15;
  11. TCardinalBitIndex = 0..31;
  12. {$if sizeof(Integer)=2}
  13. TIntegerBitIndex = 0..15;
  14. {$elseif sizeof(Integer)=4}
  15. TIntegerBitIndex = 0..31;
  16. {$else}
  17. {$fatal Unsupported Integer type size}
  18. {$endif}
  19. TLongIntBitIndex = 0..31;
  20. TQwordBitIndex = 0..63;
  21. TInt64BitIndex = 0..63;
  22. {$IFDEF cpu16}
  23. TNativeUIntBitIndex = TWordBitIndex;
  24. TNativeIntBitIndex = TSmallIntBitIndex;
  25. {$ENDIF}
  26. {$IFDEF cpu32}
  27. TNativeUIntBitIndex = TCardinalBitIndex;
  28. TNativeIntBitIndex = TIntegerBitIndex;
  29. {$ENDIF}
  30. {$IFDEF cpu64}
  31. TNativeUIntBitIndex = TQWordBitIndex;
  32. TNativeIntBitIndex = TInt64BitIndex;
  33. {$ENDIF}
  34. Const
  35. CPUEndian = {$IFDEF FPC_LITTLE_ENDIAN}TEndian.Little{$ELSE}TEndian.Big{$ENDIF};
  36. Type
  37. TGuidHelper = record helper for TGUID
  38. Class function Create(const Data; BigEndian: Boolean): TGUID; overload; static;
  39. class function Create(const Data: array of Byte; AStartIndex: Cardinal; BigEndian: Boolean): TGUID; overload; static;
  40. Class Function Create(const Data; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
  41. Class Function Create(const B: TBytes; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
  42. Class Function Create(const B: TBytes; AStartIndex: Cardinal; DataEndian: TEndian = CPUEndian): TGUID; overload; static;
  43. Class Function Create(const S: string): TGUID; overload; static;
  44. Class Function Create(A: Integer; B: SmallInt; C: SmallInt; const D: TBytes): TGUID; overload; static;
  45. Class Function Create(A: Integer; B: SmallInt; C: SmallInt; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
  46. Class Function Create(A: Cardinal; B: Word; C: Word; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
  47. Class Function NewGuid: TGUID; static;
  48. Function ToByteArray(DataEndian: TEndian = CPUEndian): TBytes;
  49. Function ToString(SkipBrackets: Boolean = False): string;
  50. end;
  51. TCompareOption = system.TCompareOption;
  52. TCompareOptions = system.TCompareOptions;
  53. {$SCOPEDENUMS ON}
  54. TStringSplitOptions = (None, ExcludeEmpty, ExcludeLastEmpty);
  55. {$SCOPEDENUMS OFF}
  56. { TStringHelper }
  57. TStringHelper = Type Helper for AnsiString
  58. Private
  59. Function GetChar(AIndex : SizeInt) : Char;
  60. Function GetLength : SizeInt;
  61. public
  62. const Empty = '';
  63. // Methods
  64. Class Function Compare(const A: string; const B: string): Integer; overload; static; //inline;
  65. Class Function Compare(const A: string; const B: string; IgnoreCase: Boolean): Integer; overload; static; //inline; //deprecated 'Use same with TCompareOptions';
  66. Class Function Compare(const A: string; const B: string; Options: TCompareOptions): Integer; overload; static; // inline;
  67. Class Function Compare(const A: string; IndexA: SizeInt; const B: string; IndexB: SizeInt; ALen: SizeInt): Integer; overload; static; // inline;
  68. Class Function Compare(const A: string; IndexA: SizeInt; const B: string; IndexB: SizeInt; ALen: SizeInt; IgnoreCase: Boolean): Integer; overload; static; // inline; //deprecated 'Use same with TCompareOptions';
  69. Class Function Compare(const A: string; IndexA: SizeInt; const B: string; IndexB: SizeInt; ALen: SizeInt; Options: TCompareOptions): Integer; overload; static;// inline;
  70. Class Function CompareOrdinal(const A: string; const B: string): Integer; overload; static;
  71. Class Function CompareOrdinal(const A: string; IndexA: SizeInt; const B: string; IndexB: SizeInt; ALen: SizeInt): Integer; overload; static;
  72. Class Function CompareText(const A: string; const B: string): Integer; static; inline;
  73. Class Function Copy(const Str: string): string; inline; static;
  74. Class Function Create(AChar: Char; ACount: SizeInt): string; overload; inline; static;
  75. Class Function Create(const AValue: array of Char): string; overload; static;
  76. Class Function Create(const AValue: array of Char; StartIndex: SizeInt; ALen: SizeInt): string; overload; static;
  77. Class Function EndsText(const ASubText, AText: string): Boolean; static;
  78. Class Function Equals(const a: string; const b: string): Boolean; overload; static;
  79. Class Function Format(const AFormat: string; const args: array of const): string; overload; static;
  80. Class Function IsNullOrEmpty(const AValue: string): Boolean; static;
  81. Class Function IsNullOrWhiteSpace(const AValue: string): Boolean; static;
  82. Class Function Join(const Separator: string; const Values: array of const): string; overload; static;
  83. Class Function Join(const Separator: string; const Values: array of string): string; overload; static;
  84. Class Function Join(const Separator: string; const Values: array of string; StartIndex: SizeInt; ACount: SizeInt): string; overload; static;
  85. Class Function LowerCase(const S: string): string; overload; static; inline;
  86. Class Function Parse(const AValue: Boolean): string; overload; static; inline;
  87. Class Function Parse(const AValue: Extended): string; overload; static;inline;
  88. Class Function Parse(const AValue: Int64): string; overload; static; inline;
  89. Class Function Parse(const AValue: Integer): string; overload; static; inline;
  90. Class Function ToBoolean(const S: string): Boolean; overload; static; inline;
  91. Class Function ToDouble(const S: string): Double; overload; static; inline;
  92. Class Function ToExtended(const S: string): Extended; overload; static; inline;
  93. Class Function ToInt64(const S: string): Int64; overload; static; inline;
  94. Class Function ToInteger(const S: string): Integer; overload; static; inline;
  95. Class Function ToSingle(const S: string): Single; overload; static; inline;
  96. Class Function UpperCase(const S: string): string; overload; static; inline;
  97. Function CompareTo(const B: string): Integer;
  98. Function Contains(const AValue: string; IgnoreCase: Boolean = False): Boolean;
  99. procedure CopyTo(SourceIndex: SizeInt; var destination: array of Char; DestinationIndex: SizeInt; ACount: SizeInt);
  100. Function CountChar(const C: Char): SizeInt;
  101. Function DeQuotedString: string; overload;
  102. Function DeQuotedString(const AQuoteChar: Char): string; overload;
  103. Function EndsWith(const AValue: string): Boolean; overload; inline;
  104. Function EndsWith(const AValue: string; IgnoreCase: Boolean): Boolean; overload;
  105. Function Equals(const AValue: string; IgnoreCase: Boolean = False): Boolean; overload;
  106. Function Format(const args: array of const): string; overload;
  107. Function GetHashCode: Integer;
  108. Function IndexOf(AValue: Char): SizeInt; overload; inline;
  109. Function IndexOf(const AValue: string): SizeInt; overload; inline;
  110. Function IndexOf(AValue: Char; StartIndex: SizeInt): SizeInt; overload;
  111. Function IndexOf(const AValue: string; StartIndex: SizeInt): SizeInt; overload;
  112. Function IndexOf(AValue: Char; StartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  113. Function IndexOf(const AValue: string; StartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  114. Function IndexOfUnQuoted(const AValue: string; StartQuote, EndQuote: Char; StartIndex: SizeInt = 0): SizeInt; overload;
  115. Function IndexOfAny(const AnyOf: array of Char): SizeInt; overload;
  116. Function IndexOfAny(const AnyOf: array of Char; StartIndex: SizeInt): SizeInt; overload;
  117. Function IndexOfAny(const AnyOf: array of Char; StartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  118. Function IndexOfAny(const AnyOf: array of String): SizeInt; overload;
  119. Function IndexOfAny(const AnyOf: array of String; StartIndex: SizeInt): SizeInt; overload;
  120. Function IndexOfAny(const AnyOf: array of String; StartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  121. Function IndexOfAny(const AnyOf: array of String; StartIndex: SizeInt; ACount: SizeInt; Out AMatch : SizeInt): SizeInt; overload;
  122. Function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char): SizeInt; overload;
  123. Function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char; StartIndex: SizeInt): SizeInt; overload;
  124. Function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char; StartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  125. function IndexOfAnyUnquoted(const AnyOf: array of string; StartQuote, EndQuote: Char; StartIndex: SizeInt; Out Matched: SizeInt): SizeInt; overload;
  126. Function Insert(StartIndex: SizeInt; const AValue: string): string;
  127. Function IsDelimiter(const Delimiters: string; Index: SizeInt): Boolean;
  128. Function IsEmpty: Boolean;
  129. Function LastDelimiter(const Delims: string): SizeInt;
  130. Function LastIndexOf(AValue: Char): SizeInt; overload;
  131. Function LastIndexOf(const AValue: string): SizeInt; overload;
  132. Function LastIndexOf(AValue: Char; AStartIndex: SizeInt): SizeInt; overload;
  133. Function LastIndexOf(const AValue: string; AStartIndex: SizeInt): SizeInt; overload;
  134. Function LastIndexOf(AValue: Char; AStartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  135. Function LastIndexOf(const AValue: string; AStartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  136. Function LastIndexOfAny(const AnyOf: array of Char): SizeInt; overload;
  137. Function LastIndexOfAny(const AnyOf: array of Char; AStartIndex: SizeInt): SizeInt; overload;
  138. Function LastIndexOfAny(const AnyOf: array of Char; AStartIndex: SizeInt; ACount: SizeInt): SizeInt; overload;
  139. Function PadLeft(ATotalWidth: SizeInt): string; overload; inline;
  140. Function PadLeft(ATotalWidth: SizeInt; PaddingChar: Char): string; overload; inline;
  141. Function PadRight(ATotalWidth: SizeInt): string; overload; inline;
  142. Function PadRight(ATotalWidth: SizeInt; PaddingChar: Char): string; overload; inline;
  143. Function QuotedString: string; overload;
  144. Function QuotedString(const AQuoteChar: Char): string; overload;
  145. Function Remove(StartIndex: SizeInt): string; overload; inline;
  146. Function Remove(StartIndex: SizeInt; ACount: SizeInt): string; overload; inline;
  147. Function Replace(OldChar: Char; NewChar: Char): string; overload;
  148. Function Replace(OldChar: Char; NewChar: Char; ReplaceFlags: TReplaceFlags): string; overload;
  149. Function Replace(const OldValue: string; const NewValue: string): string; overload;
  150. Function Replace(const OldValue: string; const NewValue: string; ReplaceFlags: TReplaceFlags): string; overload;
  151. Function Split(const Separators: array of Char): TStringArray; overload;
  152. Function Split(const Separators: array of Char; ACount: SizeInt): TStringArray; overload;
  153. Function Split(const Separators: array of Char; Options: TStringSplitOptions): TStringArray; overload;
  154. Function Split(const Separators: array of Char; ACount: SizeInt; Options: TStringSplitOptions): TStringArray; overload;
  155. Function Split(const Separators: array of string): TStringArray; overload;
  156. Function Split(const Separators: array of string; ACount: SizeInt): TStringArray; overload;
  157. Function Split(const Separators: array of string; Options: TStringSplitOptions): TStringArray; overload;
  158. Function Split(const Separators: array of string; ACount: SizeInt; Options: TStringSplitOptions): TStringArray; overload;
  159. Function Split(const Separators: array of Char; AQuote: Char): TStringArray; overload;
  160. Function Split(const Separators: array of Char; AQuoteStart, AQuoteEnd: Char): TStringArray; overload;
  161. Function Split(const Separators: array of Char; AQuoteStart, AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray; overload;
  162. Function Split(const Separators: array of Char; AQuoteStart, AQuoteEnd: Char; ACount: SizeInt): TStringArray; overload;
  163. Function Split(const Separators: array of Char; AQuoteStart, AQuoteEnd: Char; ACount: SizeInt; Options: TStringSplitOptions): TStringArray; overload;
  164. Function Split(const Separators: array of string; AQuote: Char): TStringArray; overload;
  165. Function Split(const Separators: array of string; AQuoteStart, AQuoteEnd: Char): TStringArray; overload;
  166. Function Split(const Separators: array of string; AQuoteStart, AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray; overload;
  167. Function Split(const Separators: array of string; AQuoteStart, AQuoteEnd: Char; ACount: SizeInt): TStringArray; overload;
  168. Function Split(const Separators: array of string; AQuoteStart, AQuoteEnd: Char; ACount: SizeInt; Options: TStringSplitOptions): TStringArray; overload;
  169. Function StartsWith(const AValue: string): Boolean; overload; inline;
  170. Function StartsWith(const AValue: string; IgnoreCase: Boolean): Boolean; overload;
  171. Function Substring(AStartIndex: SizeInt): string; overload;
  172. Function Substring(AStartIndex: SizeInt; ALen: SizeInt): string; overload;
  173. Function ToBoolean: Boolean; overload; inline;
  174. Function ToInteger: Integer; overload; inline;
  175. Function ToInt64: Int64; overload; inline;
  176. Function ToSingle: Single; overload; inline;
  177. Function ToDouble: Double; overload; inline;
  178. Function ToExtended: Extended; overload; inline;
  179. Function ToCharArray: TCharArray; overload;
  180. Function ToCharArray(AStartIndex: SizeInt; ALen: SizeInt): TCharArray; overload;
  181. Function ToLower: string; overload; inline;
  182. Function ToLowerInvariant: string;
  183. Function ToUpper: string; overload; inline;
  184. Function ToUpperInvariant: string; inline;
  185. Function Trim: string; overload;
  186. Function TrimLeft: string; overload;
  187. Function TrimRight: string; overload;
  188. Function Trim(const ATrimChars: array of Char): string; overload;
  189. Function TrimLeft(const ATrimChars: array of Char): string; overload;
  190. Function TrimRight(const ATrimChars: array of Char): string; overload;
  191. Function TrimEnd(const ATrimChars: array of Char): string; deprecated 'Use TrimRight';
  192. Function TrimStart(const ATrimChars: array of Char): string; deprecated 'Use TrimLeft';
  193. property Chars[AIndex: SizeInt]: Char read GetChar;
  194. property Length: SizeInt read GetLength;
  195. end;
  196. TCurrencyHelper = type helper for Currency
  197. private
  198. function GetMaxValue: Currency; inline;
  199. function GetMinValue: Currency; inline;
  200. public
  201. function Ceil: Int64; inline;
  202. function Floor: Int64; inline;
  203. function Frac: Currency; inline;
  204. class function Parse(const S: string; const AFormatSettings: TFormatSettings): Currency; overload; static;
  205. class function Parse(const S: string): Currency; overload; inline; static;
  206. class function Size: Integer; inline; static;
  207. function ToString(const AFormatSettings: TFormatSettings): string; overload; inline;
  208. function ToString: string; overload; inline;
  209. class function ToString(const Value: Currency; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  210. class function ToString(const Value: Currency): string; overload; inline; static;
  211. function Trunc: Int64; inline;
  212. class function TryParse(const S: string; out Value: Currency; const AFormatSettings: TFormatSettings): Boolean; overload; inline; static;
  213. class function TryParse(const S: string; out Value: Currency): Boolean; overload; inline; static;
  214. property MaxValue: Currency read GetMaxValue;
  215. property MinValue: Currency read GetMinValue;
  216. end;
  217. {$IFDEF FPC_HAS_TYPE_SINGLE}
  218. TSingleHelper = Type Helper for Single
  219. Private
  220. Function GetB(AIndex: Cardinal): Byte;
  221. Function GetW(AIndex: Cardinal): Word;
  222. Function GetE: QWord; inline;
  223. Function GetF: QWord; inline;
  224. Function GetS: Boolean; inline;
  225. procedure SetB(AIndex: Cardinal; const AValue: Byte);
  226. procedure SetW(AIndex: Cardinal; const AValue: Word);
  227. procedure SetE(AValue: QWord);
  228. procedure SetF(AValue: QWord);
  229. procedure SetS(AValue: Boolean);
  230. public
  231. {$push}
  232. {$R-}
  233. {$Q-}
  234. const
  235. Epsilon : Single = 1.4012984643248170709e-45;
  236. MaxValue : Single = 340282346638528859811704183484516925440.0;
  237. MinValue : Single = -340282346638528859811704183484516925440.0;
  238. PositiveInfinity : Single = 1.0/0.0;
  239. NegativeInfinity : Single = -1.0/0.0;
  240. NaN : Single = 0.0/0.0;
  241. {$POP}
  242. Class Function IsNan(const AValue: Single): Boolean; overload; inline; static;
  243. Class Function IsInfinity(const AValue: Single): Boolean; overload; inline; static;
  244. Class Function IsNegativeInfinity(const AValue: Single): Boolean; overload; inline; static;
  245. Class Function IsPositiveInfinity(const AValue: Single): Boolean; overload; inline; static;
  246. Class Function Parse(const AString: string): Single; overload; inline; static;
  247. Class Function Parse(const AString: string; const AFormatSettings: TFormatSettings): Single; overload; inline; static;
  248. Class Function Size: Integer; inline; static;
  249. Class Function ToString(const AValue: Single): string; overload; inline; static;
  250. Class Function ToString(const AValue: Single; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  251. Class Function ToString(const AValue: Single; const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline; static;
  252. Class Function ToString(const AValue: Single; const AFormat: TFloatFormat; const APrecision, ADigits: Integer;
  253. const AFormatSettings: TFormatSettings): string; overload; inline; static;
  254. Class Function TryParse(const AString: string; out AValue: Single): Boolean; overload; inline; static;
  255. Class Function TryParse(const AString: string; out AValue: Single; const AFormatSettings: TFormatSettings): Boolean; overload; inline; static;
  256. Procedure BuildUp(const ASignFlag: Boolean; const AMantissa: QWord; const AExponent: Integer);
  257. Function Exponent: Integer;
  258. Function Fraction: Extended;
  259. Function IsInfinity: Boolean; overload; inline;
  260. Function IsNan: Boolean; overload; inline;
  261. Function IsNegativeInfinity: Boolean; overload; inline;
  262. Function IsPositiveInfinity: Boolean; overload; inline;
  263. Function Mantissa: QWord;
  264. Function SpecialType: TFloatSpecial;
  265. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline;
  266. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline;
  267. Function ToString(const AFormatSettings: TFormatSettings): string; overload; inline;
  268. Function ToString: string; overload; inline;
  269. property Bytes [AIndex: Cardinal]: Byte read GetB write SetB;
  270. property Words[AIndex: Cardinal]: Word read GetW write SetW;
  271. property Sign: Boolean read GetS write SetS;
  272. property Exp: QWord read GetE write SetE;
  273. property Frac: QWord read GetF write SetF;
  274. end;
  275. {$ENDIF FPC_HAS_TYPE_SINGLE}
  276. {$IFDEF FPC_HAS_TYPE_DOUBLE}
  277. TDoubleHelper = Type Helper for Double
  278. private
  279. Function GetB(AIndex: Cardinal): Byte;
  280. Function GetW(AIndex: Cardinal): Word;
  281. Function GetE: QWord; inline;
  282. Function GetF: QWord; inline;
  283. Function GetS: Boolean; inline;
  284. procedure SetB(AIndex: Cardinal; const AValue: Byte);
  285. procedure SetW(AIndex: Cardinal; const AValue: Word);
  286. procedure SetE(AValue: QWord);
  287. procedure SetF(AValue: QWord);
  288. procedure SetS(AValue: Boolean);
  289. public
  290. const
  291. {$push}
  292. {$R-}
  293. {$Q-}
  294. Epsilon : Double = 4.9406564584124654418e-324;
  295. MaxValue : Double = 1.7976931348623157081e+308;
  296. MinValue : Double = -1.7976931348623157081e+308;
  297. PositiveInfinity : Double = 1.0/0.0;
  298. NegativeInfinity : Double = -1.0/0.0;
  299. NaN : Double = 0.0/0.0;
  300. {$POP}
  301. Class Function IsInfinity(const AValue: Double): Boolean; overload; inline; static;
  302. Class Function IsNan(const AValue: Double): Boolean; overload; inline; static;
  303. Class Function IsNegativeInfinity(const AValue: Double): Boolean; overload; inline; static;
  304. Class Function IsPositiveInfinity(const AValue: Double): Boolean; overload; inline; static;
  305. Class Function Parse(const AString: string): Double; overload; inline; static;
  306. Class Function Parse(const AString: string; const AFormatSettings: TFormatSettings): Double; overload; inline; static;
  307. Class Function Size: Integer; inline; static;
  308. Class Function ToString(const AValue: Double): string; overload; inline; static;
  309. Class Function ToString(const AValue: Double; const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline; static;
  310. Class Function ToString(const AValue: Double; const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  311. Class Function ToString(const AValue: Double; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  312. Class Function TryParse(const AString: string; out AValue: Double): Boolean; overload; inline; static;
  313. Class Function TryParse(const AString: string; out AValue: Double; const AFormatSettings: TFormatSettings): Boolean; overload; inline; static;
  314. Procedure BuildUp(const ASignFlag: Boolean; const AMantissa: QWord; const AExponent: Integer);
  315. Function Exponent: Integer;
  316. Function Fraction: Extended;
  317. Function IsInfinity: Boolean; overload; inline;
  318. Function IsNan: Boolean; overload; inline;
  319. Function IsNegativeInfinity: Boolean; overload; inline;
  320. Function IsPositiveInfinity: Boolean; overload; inline;
  321. Function Mantissa: QWord;
  322. Function SpecialType: TFloatSpecial;
  323. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline;
  324. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline;
  325. Function ToString(const AFormatSettings: TFormatSettings): string; overload; inline;
  326. Function ToString: string; overload; inline;
  327. property Bytes [AIndex: Cardinal]: Byte read GetB write SetB; // 0..7
  328. property Words [AIndex: Cardinal]: Word read GetW write SetW; // 0..3
  329. property Sign: Boolean read GetS write SetS;
  330. property Exp: QWord read GetE write SetE;
  331. property Frac: QWord read GetF write SetF;
  332. end;
  333. {$ENDIF FPC_HAS_TYPE_DOUBLE}
  334. {$ifdef FPC_HAS_TYPE_EXTENDED}
  335. TExtendedHelper = Type Helper for Extended
  336. private
  337. Function GetB(AIndex: Cardinal): Byte;
  338. Function GetW(AIndex: Cardinal): Word;
  339. Function GetE: QWord; inline;
  340. Function GetF: QWord; inline;
  341. Function GetS: Boolean; inline;
  342. procedure SetB(AIndex: Cardinal; const AValue: Byte);
  343. procedure SetW(AIndex: Cardinal; const AValue: Word);
  344. procedure SetE(AValue: QWord);
  345. procedure SetF(AValue: QWord);
  346. procedure SetS(AValue: Boolean);
  347. public
  348. {$push}
  349. {$R-}
  350. {$Q-}
  351. const
  352. Epsilon : Extended = 3.64519953188247460253e-4951;
  353. MaxValue : Extended = 1.18973149535723176505e+4932;
  354. MinValue : Extended = -1.18973149535723176505e+4932;
  355. PositiveInfinity : Extended = 1.0/0.0;
  356. NegativeInfinity : Extended = -1.0/0.0;
  357. NaN : Extended = 0.0/0.0;
  358. {$POP}
  359. Class Function ToString(const AValue: Extended): string; overload; inline; static;
  360. Class Function ToString(const AValue: Extended; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  361. Class Function ToString(const AValue: Extended; const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline; static;
  362. Class Function ToString(const AValue: Extended; const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline; static;
  363. Class Function Parse(const AString: string): Extended; overload; inline; static;
  364. Class Function Parse(const AString: string; const AFormatSettings: TFormatSettings): Extended; overload; inline; static;
  365. Class Function TryParse(const AString: string; out AValue: Extended): Boolean; overload; inline; static;
  366. Class Function TryParse(const AString: string; out AValue: Extended; const AFormatSettings: TFormatSettings): Boolean; overload; inline; static;
  367. Class Function IsNan(const AValue: Extended): Boolean; overload; inline; static;
  368. Class Function IsInfinity(const AValue: Extended): Boolean; overload; inline; static;
  369. Class Function IsNegativeInfinity(const AValue: Extended): Boolean; overload; inline; static;
  370. Class Function IsPositiveInfinity(const AValue: Extended): Boolean; overload; inline; static;
  371. Class Function Size: Integer; inline; static;
  372. procedure BuildUp(const ASignFlag: Boolean; const AMantissa: QWord; Const AExponent: Integer);
  373. Function Exponent: Integer;
  374. Function Fraction: Extended;
  375. Function IsInfinity: Boolean; overload; inline;
  376. Function IsNan: Boolean; overload; inline;
  377. Function IsNegativeInfinity: Boolean; overload; inline;
  378. Function IsPositiveInfinity: Boolean; overload; inline;
  379. Function Mantissa: QWord;
  380. Function SpecialType: TFloatSpecial;
  381. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline;
  382. Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline;
  383. Function ToString(const AFormatSettings: TFormatSettings): string; overload; inline;
  384. Function ToString: string; overload; inline;
  385. property Bytes [AIndex: Cardinal]: Byte read GetB write SetB;
  386. property Words [AIndex: Cardinal]: Word read GetW write SetW;
  387. property Sign: Boolean read GetS write SetS;
  388. property Exp: QWord read GetE write SetE;
  389. property Frac: QWord read GetF write SetF;
  390. end;
  391. {$ENDIF FPC_HAS_TYPE_EXTENDED}
  392. nibble = 0..15;
  393. TNibbleBitIndex = 0..3;
  394. // TByteBitIndex is already defined
  395. TByteNibbleIndex = 0..1;
  396. TByteOverlay = bitpacked record case integer of // for fast extraction of bits
  397. 0: (AsBit: bitpacked array[TByteBitIndex] of boolean);
  398. 1: (AsNibble: bitpacked array[TByteNibbleIndex] of nibble);
  399. 2: (AsByte: byte);
  400. end;
  401. TByteHelper = Type Helper for Byte
  402. const
  403. MaxValue = High(byte);
  404. MinValue = Low(byte);
  405. MaxBit = High(TByteBitIndex);
  406. MinBit = Low(TByteBitIndex);
  407. MaxNibble = High(TByteNibbleIndex);
  408. MinNibble = Low(TByteNibbleIndex);
  409. public
  410. Class Function Parse(const AString: string): Byte; inline; static;
  411. Class Function Size: Integer; inline; static;
  412. Class Function ToString(const AValue: Byte): string; overload; inline; static;
  413. Class Function TryParse(const AString: string; out AValue: Byte): Boolean; inline; static;
  414. protected
  415. function GetBit(const aIndex: TByteBitIndex): boolean; inline;
  416. procedure PutBit(const aIndex: TByteBitIndex; const aNewValue: boolean); inline;
  417. function GetNibble(const aIndex: TByteNibbleIndex): nibble; inline;
  418. procedure PutNibble(const aIndex: TByteNibbleIndex; const aNewValue: nibble); inline;
  419. public
  420. Function ToBoolean: Boolean; inline;
  421. Function ToDouble: Double; inline;
  422. Function ToExtended: Extended; inline;
  423. Function ToBinString:string;
  424. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  425. Function ToHexString: string; overload; inline;
  426. Function ToSingle: Single; inline;
  427. Function ToString: string; overload; inline;
  428. Function SetBit(const Index: TByteBitIndex) : Byte; inline;
  429. Function ClearBit(const Index: TByteBitIndex) : Byte; inline;
  430. Function ToggleBit(const Index: TByteBitIndex) : Byte; inline;
  431. Function TestBit(const Index:TByteBitIndex):Boolean; inline;
  432. procedure Clear; inline;
  433. function HighestSetBitPos: int8; inline;
  434. function LowestSetBitPos: int8; inline;
  435. function SetBitsCount: byte; inline;
  436. property Bits [aIndex: TByteBitIndex]: boolean read GetBit write PutBit;
  437. property Nibbles [aIndex: TByteNibbleIndex]: nibble read GetNibble write PutNibble;
  438. end;
  439. // TShortIntBitIndex is already defined
  440. TShortIntNibbleIndex = TByteNibbleIndex;
  441. TShortIntOverlay = TByteOverlay;
  442. TShortIntHelper = Type Helper for ShortInt
  443. const
  444. MaxValue = High(shortint);
  445. MinValue = Low(shortint);
  446. MaxBit = High(TShortIntBitIndex);
  447. MinBit = Low(TShortIntBitIndex);
  448. MaxNibble = High(TShortIntNibbleIndex);
  449. MinNibble = Low(TShortIntNibbleIndex);
  450. public
  451. Class Function Parse(const AString: string): ShortInt; inline; static;
  452. Class Function Size: Integer; inline; static;
  453. Class Function ToString(const AValue: ShortInt): string; overload; inline; static;
  454. Class Function TryParse(const AString: string; out AValue: ShortInt): Boolean; inline; static;
  455. protected
  456. function GetBit(const aIndex: TShortIntBitIndex): boolean; inline;
  457. procedure PutBit(const aIndex: TShortIntBitIndex; const aNewValue: boolean); inline;
  458. function GetNibble(const aIndex: TShortIntNibbleIndex): nibble; inline;
  459. procedure PutNibble(const aIndex: TShortIntNibbleIndex; const aNewValue: nibble); inline;
  460. public
  461. Function ToBoolean: Boolean; inline;
  462. Function ToDouble: Double; inline;
  463. Function ToExtended: Extended; inline;
  464. Function ToBinString:string; inline;
  465. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  466. Function ToHexString: string; overload; inline;
  467. Function ToSingle: Single; inline;
  468. Function ToString: string; overload; inline;
  469. Function SetBit(const Index: TShortIntBitIndex): Shortint; inline;
  470. Function ClearBit(const Index: TShortIntBitIndex): Shortint; inline;
  471. Function ToggleBit(const Index: TShortIntBitIndex): Shortint; inline;
  472. Function TestBit(const Index:TShortIntBitIndex):Boolean;
  473. procedure Clear; inline;
  474. function HighestSetBitPos: int8; inline;
  475. function LowestSetBitPos: int8; inline;
  476. function SetBitsCount: byte; inline;
  477. property Bits [aIndex: TShortIntBitIndex]: boolean read GetBit write PutBit;
  478. property Nibbles [aIndex: TShortIntNibbleIndex]: nibble read GetNibble write PutNibble;
  479. end;
  480. // TWordBitIndex is already defined
  481. TWordByteIndex = 0..1;
  482. TWordNibbleIndex = 0..3;
  483. TWordOverlay = bitpacked record case integer of // for fast extraction of bytes and bits
  484. 0: (AsBit: bitpacked array[TWordBitIndex] of boolean);
  485. 1: (AsNibble: bitpacked array[TWordNibbleIndex] of nibble);
  486. 2: (AsByte: array[TWordByteIndex] of byte);
  487. 3: (AsWord: word);
  488. // recursive overlay:
  489. 4: (AsByteOverlay: array[TWordByteIndex] of TByteOverlay);
  490. end;
  491. TWordHelper = Type Helper for Word
  492. const
  493. MaxValue = High(word);
  494. MinValue = Low(word);
  495. MaxBit = High(TWordBitIndex);
  496. MinBit = Low(TWordBitIndex);
  497. MaxNibble = High(TWordNibbleIndex);
  498. MinNibble = Low(TWordNibbleIndex);
  499. MaxByte = High(TWordByteIndex);
  500. MinByte = Low(TWordByteIndex);
  501. public
  502. Class Function Parse(const AString: string): Word; inline; static;
  503. Class Function Size: Integer; inline; static;
  504. Class Function ToString(const AValue: Word): string; overload; inline; static;
  505. Class Function TryParse(const AString: string; out AValue: Word): Boolean; inline; static;
  506. protected
  507. function GetBit(const aIndex: TWordBitIndex): boolean; inline;
  508. procedure PutBit(const aIndex: TWordBitIndex; const aNewValue: boolean); inline;
  509. function GetNibble(const aIndex: TWordNibbleIndex): nibble; inline;
  510. procedure PutNibble(const aIndex: TWordNibbleIndex; const aNewValue: nibble); inline;
  511. function GetByte(const aIndex: TWordByteIndex): byte;
  512. procedure PutByte(const aIndex: TWordByteIndex; const aNewValue: byte);
  513. public
  514. Function ToBoolean: Boolean; inline;
  515. Function ToDouble: Double; inline;
  516. Function ToExtended: Extended; inline;
  517. Function ToBinString:string; inline;
  518. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  519. Function ToHexString: string; overload; inline;
  520. Function ToSingle: Single; inline;
  521. Function ToString: string; overload; inline;
  522. Function SetBit(const Index: TWordBitIndex) : Word; inline;
  523. Function ClearBit(const Index: TWordBitIndex) : Word; inline;
  524. Function ToggleBit(const Index: TWordBitIndex) : Word; inline;
  525. Function TestBit(const Index:TWordBitIndex):Boolean; inline;
  526. procedure Clear; inline;
  527. function HighestSetBitPos: int8; inline;
  528. function LowestSetBitPos: int8; inline;
  529. function SetBitsCount: byte; inline;
  530. property Bits [aIndex: TWordBitIndex]: boolean read GetBit write PutBit;
  531. property Nibbles [aIndex: TWordNibbleIndex]: nibble read GetNibble write PutNibble;
  532. property Bytes [aIndex: TWordByteIndex]: byte read GetByte write PutByte;
  533. end;
  534. // TSmallIntBitIndex is already defined
  535. TSmallIntByteIndex = TWordByteIndex;
  536. TSmallIntNibbleIndex = TWordNibbleIndex;
  537. TSmallIntOverlay = TWordOverlay;
  538. TSmallIntHelper = Type Helper for SmallInt
  539. const
  540. MaxValue = High(SmallInt);
  541. MinValue = Low(SmallInt);
  542. MaxBit = High(TSmallIntBitIndex);
  543. MinBit = Low(TSmallIntBitIndex);
  544. MaxNibble = High(TSmallIntNibbleIndex);
  545. MinNibble = Low(TSmallIntNibbleIndex);
  546. MaxByte = High(TSmallIntByteIndex);
  547. MinByte = Low(TSmallIntByteIndex);
  548. public
  549. Class Function Parse(const AString: string): SmallInt; inline; static;
  550. Class Function Size: Integer; inline; static;
  551. Class Function ToString(const AValue: SmallInt): string; overload; inline; static;
  552. Class Function TryParse(const AString: string; out AValue: SmallInt): Boolean; inline; static;
  553. protected
  554. function GetBit(const aIndex: TSmallIntBitIndex): boolean; inline;
  555. procedure PutBit(const aIndex: TSmallIntBitIndex; const aNewValue: boolean); inline;
  556. function GetNibble(const aIndex: TSmallIntNibbleIndex): nibble; inline;
  557. procedure PutNibble(const aIndex: TSmallIntNibbleIndex; const aNewValue: nibble); inline;
  558. function GetByte(const aIndex: TSmallIntByteIndex): byte;
  559. procedure PutByte(const aIndex: TSmallIntByteIndex; const aNewValue: byte);
  560. public
  561. Function ToString: string; overload; inline;
  562. Function ToBoolean: Boolean; inline;
  563. Function ToBinString:string; inline;
  564. Function ToHexString: string; overload; inline;
  565. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  566. Function ToSingle: Single; inline;
  567. Function ToDouble: Double; inline;
  568. Function ToExtended: Extended; inline;
  569. Function SetBit(const Index: TSmallIntBitIndex) : Smallint; inline;
  570. Function ClearBit(const Index: TSmallIntBitIndex) : Smallint; inline;
  571. Function ToggleBit(const Index: TSmallIntBitIndex) : Smallint; inline;
  572. Function TestBit(const Index:TSmallIntBitIndex):Boolean;
  573. procedure Clear; inline;
  574. function HighestSetBitPos: int8; inline;
  575. function LowestSetBitPos: int8; inline;
  576. function SetBitsCount: byte; inline;
  577. property Bits [aIndex: TSmallIntBitIndex]: boolean read GetBit write PutBit;
  578. property Nibbles [aIndex: TSmallIntNibbleIndex]: nibble read GetNibble write PutNibble;
  579. property Bytes [aIndex: TSmallIntByteIndex]: byte read GetByte write PutByte;
  580. end;
  581. TDwordBitIndex = TCardinalBitIndex;
  582. TDwordNibbleIndex = 0..7;
  583. TDwordByteIndex = 0..3;
  584. TDwordWordIndex = 0..1;
  585. TDwordOverlay = bitpacked record case integer of // for fast extraction of words, bytes and bits
  586. 0: (AsBit: bitpacked array[TDwordBitIndex] of boolean);
  587. 1: (AsNibble: bitpacked array[TDwordNibbleIndex] of nibble);
  588. 2: (AsByte: array[TDwordByteIndex] of byte);
  589. 3: (AsWord: array[TDwordWordIndex] of word);
  590. 4: (AsDword: dword);
  591. // recursive overlays:
  592. 5: (AsByteOverlay: array[TDwordByteIndex] of TByteOverlay);
  593. 6: (AsWordOverlay: array[TDwordWordIndex] of TWordOverlay);
  594. end;
  595. // TCardinalBitIndex is already defined
  596. TCardinalNibbleIndex = TDwordNibbleIndex;
  597. TCardinalByteIndex = TDwordByteIndex;
  598. TCardinalWordIndex = TDwordWordIndex;
  599. TCardinalOverlay = TDwordOverlay;
  600. TCardinalHelper = Type Helper for Cardinal { for LongWord Type too }
  601. const
  602. MaxValue = High(Cardinal);
  603. MinValue = Low(Cardinal);
  604. MaxBit = High(TCardinalBitIndex);
  605. MinBit = Low(TCardinalBitIndex);
  606. MaxNibble = High(TCardinalNibbleIndex);
  607. MinNibble = Low(TCardinalNibbleIndex);
  608. MaxByte = High(TCardinalByteIndex);
  609. MinByte = Low(TCardinalByteIndex);
  610. MaxWord = High(TCardinalWordIndex);
  611. MinWord = Low(TCardinalWordIndex);
  612. public
  613. Class Function Parse(const AString: string): Cardinal; inline; static;
  614. Class Function Size: Integer; inline; static;
  615. Class Function ToString(const AValue: Cardinal): string; overload; inline; static;
  616. Class Function TryParse(const AString: string; out AValue: Cardinal): Boolean; inline; static;
  617. protected
  618. function GetBit(const aIndex: TCardinalBitIndex): boolean; inline;
  619. procedure PutBit(const aIndex: TCardinalBitIndex; const aNewValue: boolean); inline;
  620. function GetNibble(const aIndex: TCardinalNibbleIndex): nibble; inline;
  621. procedure PutNibble(const aIndex: TCardinalNibbleIndex; const aNewValue: nibble); inline;
  622. function GetByte(const aIndex: TCardinalByteIndex): byte;
  623. procedure PutByte(const aIndex: TCardinalByteIndex; const aNewValue: byte);
  624. function GetWord(const aIndex: TCardinalWordIndex): word;
  625. procedure PutWord(const aIndex: TCardinalWordIndex; const aNewValue: word);
  626. public
  627. Function ToBoolean: Boolean; inline;
  628. Function ToDouble: Double; inline;
  629. Function ToExtended: Extended; inline;
  630. Function ToBinString:string; inline;
  631. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  632. Function ToHexString: string; overload; inline;
  633. Function ToSingle: Single; inline;
  634. Function ToString: string; overload; inline;
  635. Function SetBit(const Index: TCardinalBitIndex) : Cardinal; inline;
  636. Function ClearBit(const Index: TCardinalBitIndex) : Cardinal; inline;
  637. Function ToggleBit(const Index: TCardinalBitIndex) : Cardinal; inline;
  638. Function TestBit(const Index:TCardinalBitIndex):Boolean; inline;
  639. procedure Clear; inline;
  640. function HighestSetBitPos: int8; inline;
  641. function LowestSetBitPos: int8; inline;
  642. function SetBitsCount: byte; inline;
  643. property Bits [aIndex: TCardinalBitIndex]: boolean read GetBit write PutBit;
  644. property Nibbles[aIndex: TCardinalNibbleIndex]: nibble read GetNibble write PutNibble;
  645. property Bytes [aIndex: TCardinalByteIndex]: byte read GetByte write PutByte;
  646. property Words [aIndex: TCardinalWordIndex]: word read GetWord write PutWord;
  647. end;
  648. // TIntegerBitIndex is already defined
  649. {$if sizeof(Integer)=2}
  650. TIntegerNibbleIndex = TWordNibbleIndex;
  651. TIntegerByteIndex = TWordByteIndex;
  652. TIntegerOverlay = TWordOverlay;
  653. {$elseif sizeof(Integer)=4}
  654. TIntegerNibbleIndex = TDwordNibbleIndex;
  655. TIntegerByteIndex = TDwordByteIndex;
  656. TIntegerWordIndex = TDwordWordIndex;
  657. TIntegerOverlay = TDwordOverlay;
  658. {$else}
  659. {$fatal Unsupported Integer type size}
  660. {$endif}
  661. TIntegerHelper = Type Helper for Integer
  662. const
  663. MaxValue = High(integer);
  664. MinValue = Low(integer);
  665. MaxBit = High(TIntegerBitIndex);
  666. MinBit = Low(TIntegerBitIndex);
  667. MaxNibble = High(TIntegerNibbleIndex);
  668. MinNibble = Low(TIntegerNibbleIndex);
  669. MaxByte = High(TIntegerByteIndex);
  670. MinByte = Low(TIntegerByteIndex);
  671. {$if sizeof(Integer)>=4}
  672. MaxWord = High(TIntegerWordIndex);
  673. MinWord = Low(TIntegerWordIndex);
  674. {$endif}
  675. public
  676. Class Function Size: Integer; inline; static;
  677. Class Function ToString(const AValue: Integer): string; overload; inline; static;
  678. Class Function Parse(const AString: string): Integer; inline; static;
  679. Class Function TryParse(const AString: string; out AValue: Integer): Boolean; inline; static;
  680. protected
  681. function GetBit(const aIndex: TIntegerBitIndex): boolean; inline;
  682. procedure PutBit(const aIndex: TIntegerBitIndex; const aNewValue: boolean); inline;
  683. function GetNibble(const aIndex: TIntegerNibbleIndex): nibble; inline;
  684. procedure PutNibble(const aIndex: TIntegerNibbleIndex; const aNewValue: nibble); inline;
  685. function GetByte(const aIndex: TIntegerByteIndex): byte;
  686. procedure PutByte(const aIndex: TIntegerByteIndex; const aNewValue: byte);
  687. {$if sizeof(Integer)>=4}
  688. function GetWord(const aIndex: TIntegerWordIndex): word;
  689. procedure PutWord(const aIndex: TIntegerWordIndex; const aNewValue: word);
  690. {$endif}
  691. public
  692. Function ToBoolean: Boolean; inline;
  693. Function ToDouble: Double; inline;
  694. Function ToExtended: Extended; inline;
  695. Function ToBinString:string; inline;
  696. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  697. Function ToHexString: string; overload; inline;
  698. Function ToSingle: Single; inline;
  699. Function ToString: string; overload; inline;
  700. Function SetBit(const Index: TIntegerBitIndex) : Integer; inline;
  701. Function ClearBit(const Index: TIntegerBitIndex) : Integer; inline;
  702. Function ToggleBit(const Index: TIntegerBitIndex) : Integer; inline;
  703. Function TestBit(const Index:TIntegerBitIndex):Boolean; inline;
  704. procedure Clear; inline;
  705. function HighestSetBitPos: int8; inline;
  706. function LowestSetBitPos: int8; inline;
  707. function SetBitsCount: byte; inline;
  708. property Bits [aIndex: TIntegerBitIndex]: boolean read GetBit write PutBit;
  709. property Nibbles[aIndex: TIntegerNibbleIndex]: nibble read GetNibble write PutNibble;
  710. property Bytes [aIndex: TIntegerByteIndex]: byte read GetByte write PutByte;
  711. {$if sizeof(Integer)>=4}
  712. property Words [aIndex: TIntegerWordIndex]: word read GetWord write PutWord;
  713. {$endif}
  714. end;
  715. // TLongIntBitIndex is already defined
  716. TLongIntNibbleIndex = TDwordNibbleIndex;
  717. TLongIntByteIndex = TDwordByteIndex;
  718. TLongIntWordIndex = TDwordWordIndex;
  719. TLongIntOverlay = TDwordOverlay;
  720. TLongIntHelper = Type Helper for LongInt
  721. const
  722. MaxValue = High(LongInt);
  723. MinValue = Low(LongInt);
  724. MaxBit = High(TLongIntBitIndex);
  725. MinBit = Low(TLongIntBitIndex);
  726. MaxNibble = High(TLongIntNibbleIndex);
  727. MinNibble = Low(TLongIntNibbleIndex);
  728. MaxByte = High(TLongIntByteIndex);
  729. MinByte = Low(TLongIntByteIndex);
  730. MaxWord = High(TLongIntWordIndex);
  731. MinWord = Low(TLongIntWordIndex);
  732. public
  733. Class Function Size: Integer; inline; static;
  734. Class Function ToString(const AValue: LongInt): string; overload; inline; static;
  735. Class Function Parse(const AString: string): LongInt; inline; static;
  736. Class Function TryParse(const AString: string; out AValue: LongInt): Boolean; inline; static;
  737. protected
  738. function GetBit(const aIndex: TLongIntBitIndex): boolean; inline;
  739. procedure PutBit(const aIndex: TLongIntBitIndex; const aNewValue: boolean); inline;
  740. function GetNibble(const aIndex: TLongIntNibbleIndex): nibble; inline;
  741. procedure PutNibble(const aIndex: TLongIntNibbleIndex; const aNewValue: nibble); inline;
  742. function GetByte(const aIndex: TLongIntByteIndex): byte;
  743. procedure PutByte(const aIndex: TLongIntByteIndex; const aNewValue: byte);
  744. function GetWord(const aIndex: TLongIntWordIndex): word;
  745. procedure PutWord(const aIndex: TLongIntWordIndex; const aNewValue: word);
  746. public
  747. Function ToBoolean: Boolean; inline;
  748. Function ToDouble: Double; inline;
  749. Function ToExtended: Extended; inline;
  750. Function ToBinString:string; inline;
  751. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  752. Function ToHexString: string; overload; inline;
  753. Function ToSingle: Single; inline;
  754. Function ToString: string; overload; inline;
  755. Function SetBit(const Index: TLongIntBitIndex) : LongInt; inline;
  756. Function ClearBit(const Index: TLongIntBitIndex) : LongInt; inline;
  757. Function ToggleBit(const Index: TLongIntBitIndex) : LongInt; inline;
  758. Function TestBit(const Index:TLongIntBitIndex):Boolean; inline;
  759. procedure Clear; inline;
  760. function HighestSetBitPos: int8; inline;
  761. function LowestSetBitPos: int8; inline;
  762. function SetBitsCount: byte; inline;
  763. property Bits [aIndex: TLongIntBitIndex]: boolean read GetBit write PutBit;
  764. property Nibbles[aIndex: TLongIntNibbleIndex]: nibble read GetNibble write PutNibble;
  765. property Bytes [aIndex: TLongIntByteIndex]: byte read GetByte write PutByte;
  766. property Words [aIndex: TLongIntWordIndex]: word read GetWord write PutWord;
  767. end;
  768. // TQwordBitIndex is already defined
  769. TQwordNibbleIndex = 0..15;
  770. TQwordByteIndex = 0..7;
  771. TQwordWordIndex = 0..3;
  772. TQwordDwordIndex = 0..1;
  773. TQwordOverlay = bitpacked record case integer of // for fast extraction of longwords, words, bytes and bits
  774. 0: (AsBit: bitpacked array[TQwordBitIndex] of boolean);
  775. 1: (AsNibble: bitpacked array[TQwordNibbleIndex] of nibble);
  776. 2: (AsByte: array[TQwordByteIndex] of byte);
  777. 3: (AsWord: array[TQwordWordIndex] of word);
  778. 4: (AsDword: array[TQwordDwordIndex] of dword);
  779. 5: (AsQword: qword);
  780. // recursive overlays:
  781. 6: (AsByteOverlay: array[TQwordByteIndex] of TByteOverlay);
  782. 7: (AsWordOverlay: array[TQwordWordIndex] of TWordOverlay);
  783. 8: (AsDwordOverlay: array[TQwordDwordIndex] of TDwordOverlay);
  784. end;
  785. TQWordHelper = Type Helper for QWord
  786. const
  787. MaxValue = High(qword);
  788. MinValue = Low(qword);
  789. MaxBit = High(TQwordBitIndex);
  790. MinBit = Low(TQwordBitIndex);
  791. MaxNibble = High(TQwordNibbleIndex);
  792. MinNibble = Low(TQwordNibbleIndex);
  793. MaxByte = High(TQwordByteIndex);
  794. MinByte = Low(TQwordByteIndex);
  795. MaxWord = High(TQwordWordIndex);
  796. MinWord = Low(TQwordWordIndex);
  797. MaxDword = High(TQwordDwordIndex);
  798. MinDword = Low(TQwordDwordIndex);
  799. public
  800. Class Function Parse(const AString: string): Qword; inline; static;
  801. Class Function Size: Integer; inline; static;
  802. Class Function ToString(const AValue: Qword): string; overload; inline; static;
  803. Class Function TryParse(const AString: string; out AValue: Qword): Boolean; inline; static;
  804. protected
  805. function GetBit(const aIndex: TQwordBitIndex): boolean; inline;
  806. procedure PutBit(const aIndex: TQwordBitIndex; const aNewValue: boolean); inline;
  807. function GetNibble(const aIndex: TQwordNibbleIndex): nibble; inline;
  808. procedure PutNibble(const aIndex: TQwordNibbleIndex; const aNewValue: nibble); inline;
  809. function GetByte(const aIndex: TQwordByteIndex): byte;
  810. procedure PutByte(const aIndex: TQwordByteIndex; const aNewValue: byte);
  811. function GetWord(const aIndex: TQwordWordIndex): word;
  812. procedure PutWord(const aIndex: TQwordWordIndex; const aNewValue: word);
  813. function GetDword(const aIndex: TQwordDwordIndex): dword;
  814. procedure PutDword(const aIndex: TQwordDwordIndex; const aNewValue: dword);
  815. public
  816. Function ToBoolean: Boolean; inline;
  817. Function ToDouble: Double; inline;
  818. Function ToExtended: Extended; inline;
  819. Function ToBinString:string; inline;
  820. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  821. Function ToHexString: string; overload; inline;
  822. Function ToSingle: Single; inline;
  823. Function ToString: string; overload; inline;
  824. Function SetBit(const Index: TQwordBitIndex): Qword; inline;
  825. Function ClearBit(const Index: TQwordBitIndex): Qword; inline;
  826. Function ToggleBit(const Index: TQwordBitIndex): Qword; inline;
  827. Function TestBit(const Index:TQwordBitIndex): Boolean; inline;
  828. procedure Clear; inline;
  829. function HighestSetBitPos: int8; inline;
  830. function LowestSetBitPos: int8; inline;
  831. function SetBitsCount: byte; inline;
  832. property Bits [aIndex: TQwordBitIndex]: boolean read GetBit write PutBit;
  833. property Nibbles[aIndex: TQwordNibbleIndex]: nibble read GetNibble write PutNibble;
  834. property Bytes [aIndex: TQwordByteIndex]: byte read GetByte write PutByte;
  835. property Words [aIndex: TQwordWordIndex]: word read GetWord write PutWord;
  836. property DWords [aIndex: TQwordDwordIndex]: dword read GetDWord write PutDWord;
  837. end;
  838. // TInt64BitIndex is already defined
  839. TInt64NibbleIndex = TQwordNibbleIndex;
  840. TInt64ByteIndex = TQwordByteIndex;
  841. TInt64WordIndex = TQwordWordIndex;
  842. TInt64DwordIndex = TQwordDwordIndex;
  843. TInt64Overlay = TQwordOverlay;
  844. TInt64Helper = Type Helper for Int64
  845. const
  846. MaxValue = High(int64);
  847. MinValue = Low(int64);
  848. MaxBit = High(TInt64BitIndex);
  849. MinBit = Low(TInt64BitIndex);
  850. MaxNibble = High(TInt64NibbleIndex);
  851. MinNibble = Low(TInt64NibbleIndex);
  852. MaxByte = High(TInt64ByteIndex);
  853. MinByte = Low(TInt64ByteIndex);
  854. MaxWord = High(TInt64WordIndex);
  855. MinWord = Low(TInt64WordIndex);
  856. MaxDword = High(TInt64DwordIndex);
  857. MinDword = Low(TInt64DwordIndex);
  858. public
  859. Class Function Parse(const AString: string): Int64; inline; static;
  860. Class Function Size: Integer; inline; static;
  861. Class Function ToString(const AValue: Int64): string; overload; inline; static;
  862. Class Function TryParse(const AString: string; out AValue: Int64): Boolean; inline; static;
  863. protected
  864. function GetBit(const aIndex: TInt64BitIndex): boolean; inline;
  865. procedure PutBit(const aIndex: TInt64BitIndex; const aNewValue: boolean); inline;
  866. function GetNibble(const aIndex: TInt64NibbleIndex): nibble; inline;
  867. procedure PutNibble(const aIndex: TInt64NibbleIndex; const aNewValue: nibble); inline;
  868. function GetByte(const aIndex: TInt64ByteIndex): byte;
  869. procedure PutByte(const aIndex: TInt64ByteIndex; const aNewValue: byte);
  870. function GetWord(const aIndex: TInt64WordIndex): word;
  871. procedure PutWord(const aIndex: TInt64WordIndex; const aNewValue: word);
  872. function GetDword(const aIndex: TInt64DwordIndex): dword;
  873. procedure PutDword(const aIndex: TInt64DwordIndex; const aNewValue: dword);
  874. public
  875. Function ToBoolean: Boolean; inline;
  876. Function ToDouble: Double; inline;
  877. Function ToExtended: Extended; inline;
  878. Function ToBinString:string; inline;
  879. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  880. Function ToHexString: string; overload; inline;
  881. Function ToSingle: Single; inline;
  882. Function ToString: string; overload; inline;
  883. Function SetBit(const Index: TInt64BitIndex) : Int64; inline;
  884. Function ClearBit(const Index: TInt64BitIndex) : Int64; inline;
  885. Function ToggleBit(const Index: TInt64BitIndex) : Int64; inline;
  886. Function TestBit(const Index: TInt64BitIndex): Boolean; inline;
  887. procedure Clear; inline;
  888. function HighestSetBitPos: int8; inline;
  889. function LowestSetBitPos: int8; inline;
  890. function SetBitsCount: byte; inline;
  891. property Bits [aIndex: TInt64BitIndex]: boolean read GetBit write PutBit;
  892. property Nibbles[aIndex: TInt64NibbleIndex]: nibble read GetNibble write PutNibble;
  893. property Bytes [aIndex: TInt64ByteIndex]: byte read GetByte write PutByte;
  894. property Words [aIndex: TInt64WordIndex]: word read GetWord write PutWord;
  895. property DWords [aIndex: TInt64DwordIndex]: dword read GetDWord write PutDWord;
  896. end;
  897. // TNativeIntBitIndex is already defined
  898. {$if sizeof(NativeInt)=2}
  899. TNativeIntNibbleIndex = TSmallIntNibbleIndex;
  900. TNativeIntByteIndex = TSmallIntByteIndex;
  901. TNativeIntOverlay = TSmallIntOverlay;
  902. {$elseif sizeof(NativeInt)=4}
  903. TNativeIntNibbleIndex = TLongIntNibbleIndex;
  904. TNativeIntByteIndex = TLongIntByteIndex;
  905. TNativeIntWordIndex = TLongIntWordIndex;
  906. TNativeIntOverlay = TLongIntOverlay;
  907. {$elseif sizeof(NativeInt)=8}
  908. TNativeIntNibbleIndex = TInt64NibbleIndex;
  909. TNativeIntByteIndex = TInt64ByteIndex;
  910. TNativeIntWordIndex = TInt64WordIndex;
  911. TNativeIntDwordIndex = TInt64DWordIndex;
  912. TNativeIntOverlay = TInt64Overlay;
  913. {$else}
  914. {$fatal Unsupported NativeInt type size}
  915. {$endif}
  916. TNativeIntHelper = Type Helper for NativeInt
  917. const
  918. MaxValue = High(NativeInt);
  919. MinValue = Low(NativeInt);
  920. MaxBit = High(TNativeIntBitIndex);
  921. MinBit = Low(TNativeIntBitIndex);
  922. MaxNibble = High(TNativeIntNibbleIndex);
  923. MinNibble = Low(TNativeIntNibbleIndex);
  924. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need MaxByte and MinByte
  925. MaxByte = High(TNativeIntByteIndex);
  926. MinByte = Low(TNativeIntByteIndex);
  927. {$if sizeof(NativeInt)>=4}
  928. MaxWord = High(TNativeIntWordIndex);
  929. MinWord = Low(TNativeIntWordIndex);
  930. {$endif}
  931. {$ifdef sizeof(NativeInt)>=8}
  932. MaxDword = High(TNativeIntDwordIndex);
  933. MinDword = Low(TNativeIntDwordIndex);
  934. {$endif}
  935. public
  936. Class Function Parse(const AString: string): NativeInt; inline; static;
  937. Class Function Size: Integer; inline; static;
  938. Class Function ToString(const AValue: NativeInt): string; overload; inline; static;
  939. Class Function TryParse(const AString: string; out AValue: NativeInt): Boolean; inline; static;
  940. protected
  941. function GetBit(const aIndex: TNativeIntBitIndex): boolean; inline;
  942. procedure PutBit(const aIndex: TNativeIntBitIndex; const aNewValue: boolean); inline;
  943. function GetNibble(const aIndex: TNativeIntNibbleIndex): nibble; inline;
  944. procedure PutNibble(const aIndex: TNativeIntNibbleIndex; const aNewValue: nibble); inline;
  945. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need GetByte and PutByte
  946. function GetByte(const aIndex: TNativeIntByteIndex): byte;
  947. procedure PutByte(const aIndex: TNativeIntByteIndex; const aNewValue: byte);
  948. {$if sizeof(NativeInt)>=4}
  949. function GetWord(const aIndex: TNativeIntWordIndex): word;
  950. procedure PutWord(const aIndex: TNativeIntWordIndex; const aNewValue: word);
  951. {$endif}
  952. {$if sizeof(NativeInt)>=8}
  953. function GetDword(const aIndex: TNativeIntDwordIndex): dword;
  954. procedure PutDword(const aIndex: TNativeIntDwordIndex; const aNewValue: dword);
  955. {$endif}
  956. public
  957. Function ToBoolean: Boolean; inline;
  958. Function ToDouble: Double; inline;
  959. Function ToExtended: Extended; inline;
  960. Function ToBinString:string; inline;
  961. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  962. Function ToHexString: string; overload; inline;
  963. Function ToSingle: Single; inline;
  964. Function ToString: string; overload; inline;
  965. Function SetBit(const Index: TNativeIntBitIndex) : NativeInt; inline;
  966. Function ClearBit(const Index: TNativeIntBitIndex) : NativeInt; inline;
  967. Function ToggleBit(const Index: TNativeIntBitIndex) : NativeInt; inline;
  968. Function TestBit(const Index:TNativeIntBitIndex):Boolean; inline;
  969. procedure Clear; inline;
  970. function HighestSetBitPos: int8; inline;
  971. function LowestSetBitPos: int8; inline;
  972. function SetBitsCount: byte; inline;
  973. property Bits [aIndex: TNativeIntBitIndex]: boolean read GetBit write PutBit;
  974. property Nibbles [aIndex: TNativeIntNibbleIndex]: nibble read GetNibble write PutNibble;
  975. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need Byte[]
  976. property Bytes [aIndex: TNativeIntByteIndex]: byte read GetByte write PutByte;
  977. {$if sizeof(NativeInt)>=4}
  978. property Words [aIndex: TNativeIntWordIndex]: word read GetWord write PutWord;
  979. {$endif}
  980. {$if sizeof(NativeInt)>=8}
  981. property DWords [aIndex: TNativeIntDwordIndex]: dword read GetDWord write PutDWord;
  982. {$endif}
  983. end;
  984. // TNativeUIntBitIndex is already defined
  985. {$if sizeof(NativeUInt)=2}
  986. TNativeUIntNibbleIndex = TWordNibbleIndex;
  987. TNativeUIntByteIndex = TWordByteIndex;
  988. TNativeUIntOverlay = TWordOverlay;
  989. {$elseif sizeof(NativeUInt)=4}
  990. TNativeUIntNibbleIndex = TDwordNibbleIndex;
  991. TNativeUIntByteIndex = TDwordByteIndex;
  992. TNativeUIntWordIndex = TDwordWordIndex;
  993. TNativeUIntOverlay = TDwordOverlay;
  994. {$elseif sizeof(NativeUInt)=8}
  995. TNativeUIntNibbleIndex = TQwordNibbleIndex;
  996. TNativeUIntByteIndex = TQwordByteIndex;
  997. TNativeUIntWordIndex = TQwordWordIndex;
  998. TNativeUIntDwordIndex = TQwordDWordIndex;
  999. TNativeUIntOverlay = TQwordOverlay;
  1000. {$else}
  1001. {$fatal Unsupported NativeUInt type size}
  1002. {$endif}
  1003. TNativeUIntHelper = Type Helper for NativeUInt
  1004. const
  1005. MaxValue = High(NativeUInt);
  1006. MinValue = 0;
  1007. MaxBit = High(TNativeUIntBitIndex);
  1008. MinBit = Low(TNativeUIntBitIndex);
  1009. MaxNibble = High(TNativeUIntNibbleIndex);
  1010. MinNibble = Low(TNativeUIntNibbleIndex);
  1011. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need MaxByte and MinByte
  1012. MaxByte = High(TNativeUIntByteIndex);
  1013. MinByte = Low(TNativeUIntByteIndex);
  1014. {$if sizeof(NativeUInt)>=4}
  1015. MaxWord = High(TNativeUIntWordIndex);
  1016. MinWord = Low(TNativeUIntWordIndex);
  1017. {$endif}
  1018. {$if sizeof(NativeUInt)>=8}
  1019. MaxDword = High(TNativeUIntDwordIndex);
  1020. MinDword = Low(TNativeUIntDwordIndex);
  1021. {$endif}
  1022. public
  1023. Class Function Parse(const AString: string): NativeUInt; inline; static;
  1024. Class Function Size: Integer; inline; static;
  1025. Class Function ToString(const AValue: NativeUInt): string; overload; inline; static;
  1026. Class Function TryParse(const AString: string; out AValue: NativeUInt): Boolean; inline; static;
  1027. protected
  1028. function GetBit(const aIndex: TNativeUIntBitIndex): boolean; inline;
  1029. procedure PutBit(const aIndex: TNativeUIntBitIndex; const aNewValue: boolean); inline;
  1030. function GetNibble(const aIndex: TNativeUIntNibbleIndex): nibble; inline;
  1031. procedure PutNibble(const aIndex: TNativeUIntNibbleIndex; const aNewValue: nibble); inline;
  1032. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need GetByte and PutByte
  1033. function GetByte(const aIndex: TNativeUIntByteIndex): byte;
  1034. procedure PutByte(const aIndex: TNativeUIntByteIndex; const aNewValue: byte);
  1035. {$if sizeof(NativeUInt)>=4}
  1036. function GetWord(const aIndex: TNativeUIntWordIndex): word;
  1037. procedure PutWord(const aIndex: TNativeUIntWordIndex; const aNewValue: word);
  1038. {$endif}
  1039. {$if sizeof(NativeUInt)>=8}
  1040. function GetDword(const aIndex: TNativeUIntDwordIndex): dword;
  1041. procedure PutDword(const aIndex: TNativeUIntDwordIndex; const aNewValue: dword);
  1042. {$endif}
  1043. public
  1044. Function ToBoolean: Boolean; inline;
  1045. Function ToDouble: Double; inline;
  1046. Function ToExtended: Extended; inline;
  1047. Function ToBinString:string; inline;
  1048. Function ToHexString(const AMinDigits: Integer): string; overload; inline;
  1049. Function ToHexString: string; overload; inline;
  1050. Function ToSingle: Single; inline;
  1051. Function ToString: string; overload; inline;
  1052. Function SetBit(const Index: TNativeUIntBitIndex) : NativeUint; inline;
  1053. Function ClearBit(const Index: TNativeUIntBitIndex): NativeUint; inline;
  1054. Function ToggleBit(const Index: TNativeUIntBitIndex) : NativeUint; inline;
  1055. Function TestBit(const Index:TNativeUIntBitIndex) :Boolean; inline;
  1056. procedure Clear; inline;
  1057. function HighestSetBitPos: int8; inline;
  1058. function LowestSetBitPos: int8; inline;
  1059. function SetBitsCount: byte; inline;
  1060. property Bits [aIndex: TNativeUIntBitIndex]: boolean read GetBit write PutBit;
  1061. property Nibbles [aIndex: TNativeUIntNibbleIndex]: nibble read GetNibble write PutNibble;
  1062. // NativeInt on cpu16 has 2 bytes, so no need for cpu16 check because we always need Byte[]
  1063. property Bytes [aIndex: TNativeUIntByteIndex]: byte read GetByte write PutByte;
  1064. {$if sizeof(NativeUInt)>=4}
  1065. property Words [aIndex: TNativeUIntWordIndex]: word read GetWord write PutWord;
  1066. {$endif}
  1067. {$if sizeof(NativeUInt)>=8}
  1068. property DWords [aIndex: TNativeUIntDwordIndex]: dword read GetDWord write PutDWord;
  1069. {$endif}
  1070. end;
  1071. {$SCOPEDENUMS ON}
  1072. TUseBoolStrs = (False, True);
  1073. {$SCOPEDENUMS OFF}
  1074. TBooleanHelper = Type Helper for Boolean
  1075. public
  1076. Class Function Parse(const S: string): Boolean; inline; static;
  1077. Class Function Size: Integer; inline; static;
  1078. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1079. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1080. Public
  1081. Function ToInteger: Integer; inline;
  1082. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1083. end;
  1084. TBoolean8Helper = Type Helper for Boolean8
  1085. public
  1086. Class Function Parse(const S: string): Boolean; inline; static;
  1087. Class Function Size: Integer; inline; static;
  1088. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1089. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1090. Public
  1091. Function ToInteger: Integer; inline;
  1092. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1093. end;
  1094. TBoolean16Helper = Type Helper for Boolean16
  1095. public
  1096. Class Function Parse(const S: string): Boolean; inline; static;
  1097. Class Function Size: Integer; inline; static;
  1098. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1099. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1100. Public
  1101. Function ToInteger: Integer; inline;
  1102. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1103. end;
  1104. TBoolean32Helper = Type Helper for Boolean32
  1105. public
  1106. Class Function Parse(const S: string): Boolean; inline; static;
  1107. Class Function Size: Integer; inline; static;
  1108. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1109. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1110. Public
  1111. Function ToInteger: Integer; inline;
  1112. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1113. end;
  1114. TBoolean64Helper = Type Helper for Boolean64
  1115. public
  1116. Class Function Parse(const S: string): Boolean; inline; static;
  1117. Class Function Size: Integer; inline; static;
  1118. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1119. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1120. Public
  1121. Function ToInteger: Integer; inline;
  1122. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1123. end;
  1124. TByteBoolHelper = Type Helper for ByteBool
  1125. public
  1126. Class Function Parse(const S: string): Boolean; inline; static;
  1127. Class Function Size: Integer; inline; static;
  1128. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1129. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1130. Public
  1131. Function ToInteger: Integer; inline;
  1132. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1133. end;
  1134. TWordBoolHelper = Type Helper for WordBool
  1135. public
  1136. Class Function Parse(const S: string): Boolean; inline; static;
  1137. Class Function Size: Integer; inline; static;
  1138. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1139. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1140. Public
  1141. Function ToInteger: Integer; inline;
  1142. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1143. end;
  1144. TLongBoolHelper = Type Helper for LongBool
  1145. public
  1146. Class Function Parse(const S: string): Boolean; inline; static;
  1147. Class Function Size: Integer; inline; static;
  1148. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1149. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1150. public
  1151. Function ToInteger: Integer; inline;
  1152. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1153. end;
  1154. TQWordBoolHelper = Type Helper for QWordBool
  1155. public
  1156. Class Function Parse(const S: string): Boolean; inline; static;
  1157. Class Function Size: Integer; inline; static;
  1158. Class Function ToString(const AValue: Boolean; UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline; static;
  1159. Class Function TryToParse(const S: string; out AValue: Boolean): Boolean; inline; static;
  1160. public
  1161. Function ToInteger: Integer; inline;
  1162. Function ToString(UseBoolStrs: TUseBoolStrs = TUseBoolStrs.False): string; overload; inline;
  1163. end;