123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- {%mainunit syshelpers.pp}
- { ---------------------------------------------------------------------
- TGUIDHelper
- ---------------------------------------------------------------------}
- Procedure NotImplemented(S : String);
- begin
- Raise Exception.Create('Not yet implemented : '+S);
- end;
- Class Function TGUIDHelper.Create(const Data; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
- begin
- Result:=Create(Data,DataEndian=TEndian.Big)
- end;
- Class Function TGUIDHelper.Create(const B: TBytes; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
- begin
- Result:=Create(B,0,DataEndian);
- end;
- Class Function TGUIDHelper.Create(const B: TBytes; AStartIndex: Cardinal; DataEndian: TEndian = CPUEndian): TGUID; overload; static;
- begin
- if ((System.Length(B)-AStartIndex)<16) then
- raise EArgumentException.CreateFmt('The length of a GUID array must be at least %d',[]);
- Result:=Create(B,AStartIndex,DataEndian=TEndian.Big);
- end;
- Class Function TGUIDHelper.Create(const S: string): TGUID; overload; static;
- begin
- Result:=StringToGUID(S);
- end;
- Class Function TGUIDHelper.Create(A: Integer; B: SmallInt; C: SmallInt; const D: TBytes): TGUID; overload; static;
- begin
- if (System.Length(D)<>8) then
- raise EArgumentException.CreateFmt('The length of a GUID array must be %d',[]);
- Result:=Create(Cardinal(A),Word(B),Word(C),D[0],D[1],D[2],D[3],D[4],D[5],D[6],D[7]);
- end;
- Class Function TGUIDHelper.Create(A: Integer; B: SmallInt; C: SmallInt; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
- begin
- Result:=Create(Cardinal(A),Word(B),Word(C),D,E,F,G,H,I,J,K);
- end;
- Class Function TGUIDHelper.Create(A: Cardinal; B: Word; C: Word; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
- begin
- Result.D1 := Cardinal(A);
- Result.D2 := Word(B);
- Result.D3 := Word(C);
- Result.D4[0] := D;
- Result.D4[1] := E;
- Result.D4[2] := F;
- Result.D4[3] := G;
- Result.D4[4] := H;
- Result.D4[5] := I;
- Result.D4[6] := J;
- Result.D4[7] := K;
- end;
- Class Function TGUIDHelper.NewGuid: TGUID; static;
- begin
- CreateGUID(Result)
- end;
- Function TGUIDHelper.ToByteArray(DataEndian: TEndian = CPUEndian): TBytes;
- begin
- SetLength(Result, 16);
- if DataEndian<>CPUEndian then
- begin
- PCardinal(@Result[0])^ := SwapEndian(D1);
- PWord(@Result[4])^ := SwapEndian(D2);
- PWord(@Result[6])^ := SwapEndian(D3);
- Move(D4, Result[8], 8);
- end
- else
- Move(D1, Result[0], SizeOf(Self));
- end;
- Function TGUIDHelper.ToString(SkipBrackets : Boolean = False): string;
- begin
- Result:=GuidToString(Self);
- If SkipBrackets then
- Result:=Copy(Result,2,Length(Result)-2);
- end;
- {$define TStringHelper:=TAnsiStringHelper}
- {$define TStringChar:=AnsiChar}
- {$define TStringType:=AnsiString}
- {$define PTStringChar:=PAnsiChar}
- {$define TSHStringArray:=TAnsiStringArray}
- {$define IS_ANSISTRINGHELPER}
- {$i syshelps.inc}
- {$undef TStringHelper}
- {$undef TStringChar}
- {$undef TStringType}
- {$undef PTStringChar}
- {$undef TSHStringArray}
- {$undef IS_ANSISTRINGHELPER}
- {$define TStringHelper:=TWideStringHelper}
- {$define TStringChar:=WideChar}
- {$define TStringType:=WideString}
- {$define PTStringChar:=PWideChar}
- {$define TSHStringArray:=TWideStringArray}
- {$define IS_WIDESTRINGHELPER}
- {$i syshelps.inc}
- {$undef TStringHelper}
- {$undef TStringChar}
- {$undef TStringType}
- {$undef PTStringChar}
- {$undef TSHStringArray}
- {$undef IS_WIDESTRINGHELPER}
- {$define TStringHelper:=TUnicodeStringHelper}
- {$define TStringChar:=UnicodeChar}
- {$define TStringType:=UnicodeString}
- {$define PTStringChar:=PUnicodeChar}
- {$define TSHStringArray:=TUnicodeStringArray}
- {$define IS_UNICODESTRINGHELPER}
- {$i syshelps.inc}
- {$undef TStringHelper}
- {$undef TStringChar}
- {$undef TStringType}
- {$undef PTStringChar}
- {$undef TSHStringArray}
- {$undef IS_UNICODESTRINGHELPER}
- {$define TStringHelper:=TShortStringHelper}
- {$define TStringChar:=AnsiChar}
- {$define TStringType:=ShortString}
- {$define IS_SHORTSTRINGHELPER}
- {$define PTStringChar:=PAnsiChar}
- {$define TSHStringArray:=TShortStringArray}
- {$i syshelps.inc}
- {$undef TStringHelper}
- {$undef TStringChar}
- {$undef TStringType}
- {$undef PTStringChar}
- {$undef TSHStringArray}
- {$undef IS_SHORTSTRINGHELPER}
- { ---------------------------------------------------------------------
- TCurrencyHelper
- ---------------------------------------------------------------------}
- function TCurrencyHelper.GetMaxValue: Currency;
- begin
- Result:=MaxCurrency;
- end;
- function TCurrencyHelper.GetMinValue: Currency;
- begin
- Result:=MinCurrency;
- end;
- function TCurrencyHelper.Ceil: Int64;
- begin
- Result:=System.Trunc(Self);
- if Currency(Result)<Self then
- Result:=Result+1;
- end;
- function TCurrencyHelper.Floor: Int64;
- begin
- Result:=System.Trunc(Self);
- if Currency(Result)>Self then
- Result:=Result-1;
- end;
- function TCurrencyHelper.Frac: Currency;
- begin
- Result:=System.Frac(Self);
- end;
- class function TCurrencyHelper.Parse(const S: string; const AFormatSettings: TFormatSettings): Currency;
- begin
- Result:=StrToCurr(S, AFormatSettings);
- end;
- class function TCurrencyHelper.Parse(const S: string): Currency;
- begin
- Result:=StrToCurr(S);
- end;
- class function TCurrencyHelper.Size: Integer;
- begin
- Result:=SizeOf(Currency);
- end;
- function TCurrencyHelper.ToString(const AFormatSettings: TFormatSettings): string;
- begin
- Result:=CurrToStr(Self, AFormatSettings);
- end;
- function TCurrencyHelper.ToString: string;
- begin
- Result:=CurrToStr(Self);
- end;
- class function TCurrencyHelper.ToString(const Value: Currency; const AFormatSettings: TFormatSettings): string;
- begin
- Result:=CurrToStr(Value, AFormatSettings);
- end;
- class function TCurrencyHelper.ToString(const Value: Currency): string;
- begin
- Result:=CurrToStr(Value);
- end;
- function TCurrencyHelper.Trunc: Int64;
- begin
- Result:=System.Trunc(Self);
- end;
- class function TCurrencyHelper.TryParse(const S: string; out Value: Currency; const AFormatSettings: TFormatSettings): Boolean;
- begin
- Result:=True;
- try
- Value:=StrToCurr(S, AFormatSettings);
- except
- on E: Exception do
- Result:=False;
- end;
- end;
- class function TCurrencyHelper.TryParse(const S: string; out Value: Currency): Boolean;
- begin
- Result:=True;
- try
- Value:=StrToCurr(S);
- except
- on E: Exception do
- Result:=False;
- end;
- end;
- { ---------------------------------------------------------------------
- TSingleHelper
- ---------------------------------------------------------------------}
- {$MACRO ON}
- {$IFDEF FPC_HAS_TYPE_SINGLE}
- {$define TFLOATHELPER:=TSingleHelper}
- {$define FLOATTYPE:=Single}
- {$define TFloatRec:=TSingleRec}
- {$i syshelpf.inc}
- {$UNDEF TFloatRec}
- {$ENDIF FPC_HAS_TYPE_SINGLE}
- { ---------------------------------------------------------------------
- TDoubleHelper
- ---------------------------------------------------------------------}
- {$IFDEF FPC_HAS_TYPE_DOUBLE}
- {$define TFLOATHELPER:=TDoubleHelper}
- {$define FLOATTYPE:=Double}
- {$define TFloatRec:=TDoubleRec}
- {$i syshelpf.inc}
- {$UNDEF TFloatRec}
- {$ENDIF FPC_HAS_TYPE_DOUBLE}
- { ---------------------------------------------------------------------
- TExtendedHelper
- ---------------------------------------------------------------------}
- {$ifdef FPC_HAS_TYPE_EXTENDED}
- {$define TFLOATHELPER:=TExtendedHelper}
- {$define FLOATTYPE:=Extended}
- {$define TFloatRec:=TExtended80Rec}
- {$i syshelpf.inc}
- {$UNDEF TFloatRec}
- {$ENDIF FPC_HAS_TYPE_EXTENDED}
- { ---------------------------------------------------------------------
- TByteHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TByteHelper}
- {$define TORDINALTYPE:=Byte}
- {$define TORDINALBITINDEX:=TByteBitIndex}
- {$define TORDINALNIBBLEINDEX:=TByteNibbleIndex}
- {$define TORDINALOVERLAY:=TByteOverlay}
- {$define TORDINALTYPESIZE1}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE1}
- { ---------------------------------------------------------------------
- TShortintHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TShortIntHelper}
- {$define TORDINALTYPE:=ShortInt}
- {$define TORDINALBITINDEX:=TShortIntBitIndex}
- {$define TORDINALNIBBLEINDEX:=TShortIntNibbleIndex}
- {$define TORDINALOVERLAY:=TShortIntOverlay}
- {$define TORDINALTYPESIZE1}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE1}
- { ---------------------------------------------------------------------
- TSmallintHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TSmallIntHelper}
- {$define TORDINALTYPE:=SmallInt}
- {$define TORDINALBITINDEX:=TSmallIntBitIndex}
- {$define TORDINALNIBBLEINDEX:=TSmallIntNibbleIndex}
- {$define TORDINALBYTEINDEX:=TWordByteIndex}
- {$define TORDINALOVERLAY:=TWordOverlay}
- {$define TORDINALTYPESIZE2}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE2}
- { ---------------------------------------------------------------------
- TWordHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TWordHelper}
- {$define TORDINALTYPE:=Word}
- {$define TORDINALBITINDEX:=TWordBitIndex}
- {$define TORDINALNIBBLEINDEX:=TWordNibbleIndex}
- {$define TORDINALBYTEINDEX:=TWordByteIndex}
- {$define TORDINALOVERLAY:=TWordOverlay}
- {$define TORDINALTYPESIZE2}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE2}
- { ---------------------------------------------------------------------
- TCardinalHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TCardinalHelper}
- {$define TORDINALTYPE:=Cardinal}
- {$define TORDINALBITINDEX:=TCardinalBitIndex}
- {$define TORDINALNIBBLEINDEX:=TCardinalNibbleIndex}
- {$define TORDINALBYTEINDEX:=TCardinalByteIndex}
- {$define TORDINALWORDINDEX:=TCardinalWordIndex}
- {$define TORDINALOVERLAY:=TDwordOverlay}
- {$define TORDINALTYPESIZE4}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE4}
- { ---------------------------------------------------------------------
- TIntegerHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TIntegerHelper}
- {$define TORDINALTYPE:=Integer}
- {$define TORDINALBITINDEX:=TIntegerBitIndex}
- {$define TORDINALNIBBLEINDEX:=TIntegerNibbleIndex}
- {$define TORDINALBYTEINDEX:=TIntegerByteIndex}
- {$define TORDINALWORDINDEX:=TIntegerWordIndex}
- {$if sizeof(Integer)=2}
- {$define TORDINALOVERLAY:=TWordOverlay}
- {$define TORDINALTYPESIZE2}
- {$elseif sizeof(Integer)=4}
- {$define TORDINALOVERLAY:=TDwordOverlay}
- {$define TORDINALTYPESIZE4}
- {$else}
- {$fatal Unsupported Integer type size}
- {$endif}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE2}
- {$undef TORDINALTYPESIZE4}
- { ---------------------------------------------------------------------
- TLongIntHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TLongIntHelper}
- {$define TORDINALTYPE:=LongInt}
- {$define TORDINALBITINDEX:=TLongIntBitIndex}
- {$define TORDINALNIBBLEINDEX:=TLongIntNibbleIndex}
- {$define TORDINALBYTEINDEX:=TLongIntByteIndex}
- {$define TORDINALWORDINDEX:=TLongIntWordIndex}
- {$define TORDINALOVERLAY:=TDwordOverlay}
- {$define TORDINALTYPESIZE4}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE4}
- { ---------------------------------------------------------------------
- TInt64Helper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TInt64Helper}
- {$define TORDINALTYPE:=Int64}
- {$define TORDINALBITINDEX:=TInt64BitIndex}
- {$define TORDINALNIBBLEINDEX:=TInt64NibbleIndex}
- {$define TORDINALBYTEINDEX:=TInt64ByteIndex}
- {$define TORDINALWORDINDEX:=TInt64WordIndex}
- {$define TORDINALDWORDINDEX:=TInt64DWordIndex}
- {$define TORDINALOVERLAY:=TQwordOverlay}
- {$define TORDINALTYPESIZE8}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE8}
- { ---------------------------------------------------------------------
- TQWordHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TQWordHelper}
- {$define TORDINALTYPE:=QWord}
- {$define TORDINALBITINDEX:=TQwordBitIndex}
- {$define TORDINALNIBBLEINDEX:=TQwordNibbleIndex}
- {$define TORDINALBYTEINDEX:=TQwordByteIndex}
- {$define TORDINALWORDINDEX:=TQWordWordIndex}
- {$define TORDINALDWORDINDEX:=TQWordDWordIndex}
- {$define TORDINALOVERLAY:=TQwordOverlay}
- {$define TORDINALTYPESIZE8}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE8}
- { ---------------------------------------------------------------------
- TNativeIntHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TNativeIntHelper}
- {$define TORDINALTYPE:=NativeInt}
- {$define TORDINALBITINDEX:=TNativeIntBitIndex}
- {$if sizeof(NativeInt)=2}
- {$define TORDINALNIBBLEINDEX:=TSmallIntNibbleIndex}
- {$define TORDINALBYTEINDEX:=TSmallIntByteIndex}
- {$define TORDINALOVERLAY:=TSmallIntOverlay}
- {$define TORDINALTYPESIZE2}
- {$elseif sizeof(NativeInt)=4}
- {$define TORDINALNIBBLEINDEX:=TLongIntNibbleIndex}
- {$define TORDINALBYTEINDEX:=TLongIntByteIndex}
- {$define TORDINALWORDINDEX:=TLongIntWordIndex}
- {$define TORDINALOVERLAY:=TLongIntOverlay}
- {$define TORDINALTYPESIZE4}
- {$elseif sizeof(NativeInt)=8}
- {$define TORDINALNIBBLEINDEX:=TInt64NibbleIndex}
- {$define TORDINALBYTEINDEX:=TInt64ByteIndex}
- {$define TORDINALWORDINDEX:=TInt64WordIndex}
- {$define TORDINALDWORDINDEX:=TInt64DWordIndex}
- {$define TORDINALOVERLAY:=TInt64Overlay}
- {$define TORDINALTYPESIZE8}
- {$else}
- {$fatal Unsupported NativeInt type size}
- {$endif}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE2}
- {$undef TORDINALTYPESIZE4}
- {$undef TORDINALTYPESIZE8}
- { ---------------------------------------------------------------------
- TNativeUIntHelper
- ---------------------------------------------------------------------}
- {$define TORDINALHELPER:=TNativeUIntHelper}
- {$define TORDINALTYPE:=NativeUInt}
- {$define TORDINALBITINDEX:=TNativeUIntBitIndex}
- {$if sizeof(NativeUInt)=2}
- {$define TORDINALNIBBLEINDEX:=TWordNibbleIndex}
- {$define TORDINALBYTEINDEX:=TWordByteIndex}
- {$define TORDINALOVERLAY:=TWordOverlay}
- {$define TORDINALTYPESIZE2}
- {$elseif sizeof(NativeUInt)=4}
- {$define TORDINALNIBBLEINDEX:=TDwordNibbleIndex}
- {$define TORDINALBYTEINDEX:=TDwordByteIndex}
- {$define TORDINALWORDINDEX:=TDwordWordIndex}
- {$define TORDINALOVERLAY:=TDwordOverlay}
- {$define TORDINALTYPESIZE4}
- {$elseif sizeof(NativeUInt)=8}
- {$define TORDINALNIBBLEINDEX:=TQwordNibbleIndex}
- {$define TORDINALBYTEINDEX:=TQwordByteIndex}
- {$define TORDINALWORDINDEX:=TQwordWordIndex}
- {$define TORDINALDWORDINDEX:=TQwordDWordIndex}
- {$define TORDINALOVERLAY:=TQwordOverlay}
- {$define TORDINALTYPESIZE8}
- {$else}
- {$fatal Unsupported NativeUInt type size}
- {$endif}
- {$i syshelpo.inc}
- {$undef TORDINALTYPESIZE2}
- {$undef TORDINALTYPESIZE4}
- {$undef TORDINALTYPESIZE8}
- { ---------------------------------------------------------------------
- TBooleanHelper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TBooleanHelper}
- {$define TBOOLTYPE:=Boolean}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TBoolean8Helper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TBoolean8Helper}
- {$define TBOOLTYPE:=Boolean8}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TBoolean16Helper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TBoolean16Helper}
- {$define TBOOLTYPE:=Boolean16}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TBoolean32Helper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TBoolean32Helper}
- {$define TBOOLTYPE:=Boolean32}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TBoolean64Helper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TBoolean64Helper}
- {$define TBOOLTYPE:=Boolean64}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TByteBoolHelper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TByteBoolHelper}
- {$define TBOOLTYPE:=ByteBool}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TWordBoolHelper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TWordBoolHelper}
- {$define TBOOLTYPE:=WordBool}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TLongBoolHelper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TLongBoolHelper}
- {$define TBOOLTYPE:=LongBool}
- {$i syshelpb.inc}
- { ---------------------------------------------------------------------
- TQWordBoolHelper
- ---------------------------------------------------------------------}
- {$define TBOOLHELPER:=TQWordBoolHelper}
- {$define TBOOLTYPE:=QWordBool}
- {$i syshelpb.inc}
|