syshelph.inc 64 KB

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