"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSStandardLib/Src/LSSTDStandardLib.h

00001 
00017 #ifndef __LSSTD_STANDARDLIB_H__
00018 #define __LSSTD_STANDARDLIB_H__
00019 
00020 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00021 // OPERATING SYSTEM
00022 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00023 #if defined( WIN32 ) || defined( _WIN32 ) || defined( _WIN64 )
00024 #define LSE_WINDOWS
00025 #if defined( WIN32 ) || defined( _WIN32 )
00026 #define LSE_WIN32
00027 #endif  // #ifdef defined( WIN32 ) || defined( _WIN32 )
00028 #ifdef _WIN64
00029 #define LSE_WIN64
00030 #endif  // #ifdef _WIN64
00031 #elif defined( MACOS_X ) || defined( __APPLE__ )
00032 #define LSE_MAC // Any Macintosh product (specifically iOS and Macintosh OS X).
00033 #include <TargetConditionals.h>
00034 #if TARGET_OS_IPHONE
00035 #define LSE_IPHONE
00036 #else
00037 #define LSE_OSX
00038 #endif  // #if TARGET_OS_IPHONE
00039 #elif defined( __linux__ )
00040 #define LSE_LINUX
00041 #endif  // defined( WIN32 ) || defined( _WIN32 ) || defined( _WIN64 )
00042 
00043 
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00046 // COMPILER
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00048 #ifdef _MSC_VER
00049 // Microsoft Visual Studio
00050 #define LSE_INLINE                                              __forceinline
00051 #define LSE_CALL                                                __stdcall
00052 #define LSE_CALLCTOR                                    __stdcall
00053 #define LSE_CCALL                                               __cdecl
00054 #define LSE_FCALL                                               __fastcall
00055 #define LSE_RESTRICT                                    __restrict
00056 #define LSE_ALIGN( ALIGN )                              __declspec( align( ALIGN ) )
00057 #ifndef _WIN64
00058 #define LSE_UNALIGNED                   
00059 #else
00060 #define LSE_UNALIGNED                                   __unaligned
00061 #endif  // #ifndef _WIN64
00062 
00063 #define LSE_ASM_BEGIN                                   __asm {
00064 #define LSE_ASM_END                                             }
00065 #ifdef _M_IX86
00066 #define LSE_X86                                                 1
00067 #endif  // #ifdef _M_IX86
00068 
00069 #define LSE_VISUALSTUDIO
00070 #ifndef _WCHAR_T_DEFINED
00071 typedef unsigned short                                  wchar_t;
00072 #define _WCHAR_T_DEFINED
00073 #endif  // #ifndef _WCHAR_T_DEFINED
00074 #elif defined( __GNUC__ )
00075 // GCC.
00076 #define LSE_INLINE                                              inline
00077 #define LSE_CALL                                                
00078 #define LSE_CALLCTOR                                    
00079 #define LSE_CCALL                                               
00080 #define LSE_FCALL                                               
00081 #define LSE_RESTRICT                                    
00082 #define LSE_ALIGN( ALIGN )
00083 #define LSE_UNALIGNED
00084 
00085 #define LSE_ASM_BEGIN                                   __asm {
00086 #define LSE_ASM_END                                             }
00087 #ifdef _M_IX86
00088 #define LSE_X86                                                 1
00089 #endif  // #ifdef _M_IX86
00090 
00091 #define LSE_GCC
00092 #else
00093 #define LSE_ASM_BEGIN                   
00094 #define LSE_ASM_END                             
00095 #endif  // #if defined( _MSC_VER )
00096 
00097 
00098 
00099 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00100 // MACROS
00101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00107 //#define __LSE_CRT_MEMFUNCS__
00108 
00112 #define __LSE_STD_FLOAT__
00113 
00117 #define LSE_ROUND_UP( VALUE, X )                ((VALUE) + (((X) - (VALUE) & ((X) - 1)) & ((X) - 1)))
00118 
00122 #define LSE_ELEMENTS( ARRAY )                   (sizeof( (ARRAY) ) / sizeof( (ARRAY)[0] ))
00123 
00127 #define LSE_DEBUG
00128 
00132 #ifndef NULL
00133 #define NULL                                                    0
00134 #endif  // #ifndef NULL
00135 
00139 #define LSE_MAKEFOURCC( A, B, C, D )    (static_cast<LSUINT32>(A) | (static_cast<LSUINT32>(B) << 8) | (static_cast<LSUINT32>(C) << 16) | (static_cast<LSUINT32>(D) << 24))
00140 
00141 
00142 
00143 namespace lsstd {
00144 
00145 #if defined( LSE_VISUALSTUDIO )
00146         typedef signed __int8                           LSINT8;
00147         typedef signed __int16                          LSINT16;
00148         typedef signed __int32                          LSINT32;
00149         typedef signed __int64                          LSINT64;
00150         typedef unsigned __int8                         LSUINT8;
00151         typedef unsigned __int16                        LSUINT16;
00152         typedef unsigned __int32                        LSUINT32;
00153         typedef unsigned __int64                        LSUINT64;
00154         typedef float                                           LSFLOAT;
00155         typedef double                                          LSDOUBLE;
00156         typedef void                                            LSVOID;
00157         typedef char                                            LSCHAR;
00158         typedef long                                            LSWCHAR;
00159         typedef wchar_t                                         LSWCHAR_T;
00160 
00161 #if defined( _WIN64 )
00162         typedef unsigned __int64                        LSUINTPTR;
00163 #else
00164         typedef unsigned long __w64                     LSUINTPTR;
00165 #endif  // #if defined( _WIN64 )
00166 #define LSS_WINDOWS
00167 #elif defined( LSE_GCC )
00168         typedef signed char                                     LSINT8;
00169         typedef signed short                            LSINT16;
00170         typedef signed int                                      LSINT32;
00171         typedef signed long long                        LSINT64;
00172         typedef unsigned char                           LSUINT8;
00173         typedef unsigned short                          LSUINT16;
00174         typedef unsigned int                            LSUINT32;
00175         typedef unsigned long long                      LSUINT64;
00176         typedef float                                           LSFLOAT;
00177         typedef double                                          LSDOUBLE;
00178         typedef void                                            LSVOID;
00179         typedef char                                            LSCHAR;
00180         typedef long                                            LSWCHAR;
00181         typedef wchar_t                                         LSWCHAR_T;
00182 
00183 #ifdef __LP64__
00184         typedef unsigned long long                      LSUINTPTR;
00185 #else
00186         typedef unsigned int                            LSUINTPTR;
00187 #endif  // #ifdef __LP64__
00188 #endif  // #if defined( LSE_VISUALSTUDIO )
00189 
00193         typedef LSINT32                                         LSBOOL;
00194 
00198         typedef LSUINT8                                         LSUTF8;
00199         typedef LSUINT16                                        LSUTF16;
00200         typedef LSUINT32                                        LSUTF32;
00201         
00208         typedef wchar_t                                         LSUTFX;
00209 
00213 #define LSSUTF_INVALID                                  ~static_cast<LSUINT32>(0)
00214 
00218 #define LSSTD_MAX_INT32                                 2147483647L
00219 
00223 #define LSSTD_MAX_UINT32                                0xFFFFFFFF
00224 
00228 #define LSSTD_MAX_INT64                                 9223372036854775807LL
00229 
00233 #define LSSTD_MAX_UINT64                                0xFFFFFFFFFFFFFFFFULL
00234 
00238         enum LSSTD_ERRORS {
00239                 LSSTD_E_SUCCESS,                                
00240                 LSSTD_E_OUTOFMEMORY,                    
00241                 LSSTD_E_FILENOTFOUND,                   
00242                 LSSTD_E_INVALIDWRITEPERMISSIONS,
00243                 LSSTD_E_NODISKSPACE,                    
00244                 LSSTD_E_INVALIDFILETYPE,                
00245                 LSSTD_E_INVALIDCALL,                    
00246                 LSSTD_E_INVALIDDATA,                    
00247                 LSSTD_E_INTERNALERROR,                  
00248                 LSSTD_E_FEATURENOTSUPPORTED,    
00249         };
00250 
00251 
00252 
00261         class CStd {
00262         public :
00263                 // == Functions.
00272                 static LSINT32 LSE_CALL                 WStrCmp( const LSUTFX * _pwcLeft, const LSUTFX * _pwcRight );
00273                 
00282                 static LSINT32 LSE_CALL                 WStrICmp( const LSUTFX * _pwcLeft, const LSUTFX * _pwcRight );
00283 
00293                 static LSINT32 LSE_CALL                 WStrNCmp( const LSUTFX * _pwcLeft, const LSUTFX * _pwcRight, LSUINT32 _ui32Max );
00294                 
00304                 static LSINT32 LSE_CALL                 WStrNICmp( const LSUTFX * _pwcLeft, const LSUTFX * _pwcRight, LSUINT32 _ui32Max );
00305 
00314                 static LSUTFX * LSE_CALL                WStrCpy( LSUTFX * _pwcDst, const LSUTFX * _pwcSrc );
00315                 
00325                 static LSUTFX * LSE_CALL                WStrNCpy( LSUTFX * _pwcDst, const LSUTFX * _pwcSrc, LSUINT32 _ui32Max );
00326 
00333                 static LSUINT32 LSE_CALL                WStrLen( const LSUTFX * _pwcStr );
00334 
00342                 static LSUTFX * LSE_CALL                WStrCat( LSUTFX * _pwcLeft, const LSUTFX * _pwcRight );
00343                 
00352                 static LSUTFX * LSE_CALL                WStrNCat( LSUTFX * _pwcLeft, const LSUTFX * _pwcRight, LSUINT32 _ui32Max );
00353 
00363                 static LSUINT32 LSE_CALL                WStrCSpn( const LSUTFX * _pwcString, const LSUTFX * _pwcCharSet );
00364                 
00373                 static LSINT32 LSE_CALL                 StrCmp( const LSCHAR * _pcLeft, const LSCHAR * _pcRight );
00374                 
00383                 static LSINT32 LSE_CALL                 StrICmp( const LSCHAR * _pcLeft, const LSCHAR * _pcRight );
00384 
00394                 static LSINT32 LSE_CALL                 StrNCmp( const LSCHAR * _pcLeft, const LSCHAR * _pcRight, LSUINT32 _ui32Max );
00395                 
00405                 static LSINT32 LSE_CALL                 StrNICmp( const LSCHAR * _pcLeft, const LSCHAR * _pcRight, LSUINT32 _ui32Max );
00406 
00415                 static LSCHAR * LSE_CALL                StrCpy( LSCHAR * _pcDst, const LSCHAR * _pcSrc );
00416                 
00426                 static LSCHAR * LSE_CALL                StrNCpy( LSCHAR * _pcDst, const LSCHAR * _pcSrc, LSUINT32 _ui32Max );
00427 
00434                 static LSUINT32 LSE_CALL                StrLen( const LSCHAR * _pcStr );
00435 
00443                 static LSCHAR * LSE_CALL                StrCat( LSCHAR * _pcLeft, const LSCHAR * _pcRight );
00444                 
00453                 static LSCHAR * LSE_CALL                StrNCat( LSCHAR * _pcLeft, const LSCHAR * _pcRight, LSUINT32 _ui32Max );
00454 
00464                 static LSUINT32 LSE_CALL                StrCSpn( const LSCHAR * _pcString, const LSCHAR * _pcCharSet );
00465 
00472                 static LSUTFX * LSE_CALL                WStrDup( const LSUTFX * _pwcSrc );
00473 
00479                 static LSVOID LSE_CALL                  WStrDel( LSUTFX * _pwcStr );
00480 
00487                 static LSCHAR * LSE_CALL                StrDup( const LSCHAR * _pcSrc );
00488 
00494                 static LSVOID LSE_CALL                  StrDel( LSCHAR * _pcStr );
00495                 
00502                 static LSUTFX LSE_CALL                  ToLower( LSUTFX _wcChar );
00503                 
00510                 static LSUTFX LSE_CALL                  ToUpper( LSUTFX _wcChar );
00511                 
00518                 static LSCHAR LSE_CALL                  ToLower( LSCHAR _cChar );
00519                 
00526                 static LSCHAR LSE_CALL                  ToUpper( LSCHAR _cChar );
00527 
00535                 static LSINT32 LSE_CALL                 WtoI32( const LSUTFX * _pwcString );
00536 
00544                 static LSINT32 LSE_CALL                 AtoI32( const LSCHAR * _pcString );
00545 
00553                 static LSINT64 LSE_CALL                 WtoI64( const LSUTFX * _pwcString );
00554 
00562                 static LSINT64 LSE_CALL                 AtoI64( const LSCHAR * _pcString );
00563 
00571                 static LSINT64 LSE_CALL                 WHtoI64( const LSUTFX * _pwcString );
00572 
00580                 static LSINT64 LSE_CALL                 AHtoI64( const LSCHAR * _pcString );
00581 
00592                 static LSUTFX * LSE_CALL                I32toW( LSINT32 _i32Value, LSUTFX * _pwcRet, LSUINT32 _ui32Radix = 10 );
00593 
00604                 static LSCHAR * LSE_CALL                I32toA( LSINT32 _i32Value, LSCHAR * _pcRet, LSUINT32 _ui32Radix = 10 );
00605 
00616                 static LSUTFX * LSE_CALL                I64toW( LSINT64 _i64Value, LSUTFX * _pwcRet, LSUINT32 _ui32Radix = 10 );
00617 
00628                 static LSCHAR * LSE_CALL                I64toA( LSINT64 _i64Value, LSCHAR * _pcRet, LSUINT32 _ui32Radix = 10 );
00629 
00638                 static LSUTFX * LSE_CALL                UI32toW( LSUINT32 _ui32Value, LSUTFX * _pwcRet, LSUINT32 _ui32Radix = 10 );
00639 
00648                 static LSCHAR * LSE_CALL                UI32toA( LSUINT32 _ui32Value, LSCHAR * _pcRet, LSUINT32 _ui32Radix = 10 );
00649 
00658                 static LSUTFX * LSE_CALL                UI64toW( LSUINT64 _ui64Value, LSUTFX * _pwcRet, LSUINT32 _ui32Radix = 10 );
00659 
00668                 static LSCHAR * LSE_CALL                UI64toA( LSUINT64 _ui64Value, LSCHAR * _pcRet, LSUINT32 _ui32Radix = 10 );
00669 
00677                 static LSDOUBLE LSE_CALL                WtoF( const LSUTFX * _pwcString );
00678 
00686                 static LSDOUBLE LSE_CALL                AtoF( const LSCHAR * _pcString );
00687 
00702                 static LSUTFX * LSE_CALL                FtoW( LSUTFX * _pwcBuffer, LSUINT32 _ui32MaxLen, LSDOUBLE _dValue,
00703                         LSUINT32 _ui32Precision = 6UL, LSINT8 _i8Format = 'f' );
00704 
00719                 static LSCHAR * LSE_CALL                FtoA( LSCHAR * _pcBuffer, LSUINT32 _ui32MaxLen, LSDOUBLE _dValue,
00720                         LSUINT32 _ui32Precision = 6UL, LSINT8 _i8Format = 'f' );
00721                 
00729                 static LSUTFX * LSE_CALL                CharToWChar( const LSCHAR * _pcSrc, LSUTFX * _pwcRet );
00730                 
00738                 static LSCHAR * LSE_CALL                WCharToChar( const LSUTFX * _pwcSrc, LSCHAR * _pcRet );
00739 
00749                 static LSCHAR * LSE_CALL                UtfXToUtf8( const LSUTFX * _pwcSrc, LSCHAR * _pcRet, LSUINT32 _ui32RetLen );
00750 
00758                 static LSUINT32 LSE_CALL                UtfXToUtf8Len( const LSUTFX * _pwcSrc );
00759 
00773                 static LSUINT32 LSE_CALL                NextUtf32Char( const LSUTF32 * _putf32Char, LSUINT32 _ui32Len, LSUINT32 * _pui32Size = NULL );
00774 
00785                 static LSUINT32 LSE_CALL                NextUtf16Char( const LSUTF16 * _putf16Char, LSUINT32 _ui32Len, LSUINT32 * _pui32Size = NULL );
00786 
00797                 static LSUINT32 LSE_CALL                NextUtf8Char( const LSUTF8 * _putf8Char, LSUINT32 _ui32Len, LSUINT32 * _pui32Size = NULL );
00798 
00810                 static LSUINT32 LSE_CALL                RawUnicodeToUtf32Char( LSUINT32 _ui32Raw, LSUINT32 &_ui32Len );
00811 
00821                 static LSUINT32 LSE_CALL                RawUnicodeToUtf16Char( LSUINT32 _ui32Raw, LSUINT32 &_ui32Len );
00822 
00832                 static LSUINT32 LSE_CALL                RawUnicodeToUtf8Char( LSUINT32 _ui32Raw, LSUINT32 &_ui32Len );
00833 
00843                 static LSUINT32 LSE_CALL                Utf32ToUnicodeRaw( LSUINT32 * _pui32Dst,
00844                         const LSUTF32 * _putf32Src, LSUINT32 _ui32MaxLen );
00845 
00855                 static LSUINT32 LSE_CALL                Utf16ToUnicodeRaw( LSUINT32 * _pui32Dst,
00856                         const LSUTF16 * _putf16Src, LSUINT32 _ui32MaxLen );
00857 
00867                 static LSUINT32 LSE_CALL                Utf8ToUnicodeRaw( LSUINT32 * _pui32Dst,
00868                         const LSUTF8 * _putf8Src, LSUINT32 _ui32MaxLen );
00869 
00882                 static LSUINT32 LSE_CALL                RawUnicodeToUtf32( LSUTF32 * _putf32Dst,
00883                         const LSUINT32 * _pui32Src, LSUINT32 _ui32MaxLen );
00884 
00897                 static LSUINT32 LSE_CALL                RawUnicodeToUtf16( LSUTF16 * _putf16Dst,
00898                         const LSUINT32 * _pui32Src, LSUINT32 _ui32MaxLen );
00899 
00912                 static LSUINT32 LSE_CALL                RawUnicodeToUtf8( LSUTF8 * _putf8Dst,
00913                         const LSUINT32 * _pui32Src, LSUINT32 _ui32MaxLen );
00914 
00926                 static LSUINT32 LSE_CALL                Utf32ToUtf8( LSUTF8 * _putf8Dst, const LSUTF32 * _putf32Src,
00927                         LSUINT32 _ui32MaxLen );
00928 
00940                 static LSUINT32 LSE_CALL                Utf32ToUtf16( LSUTF16 * _putf16Dst, const LSUTF32 * _putf32Src,
00941                         LSUINT32 _ui32MaxLen );
00942 
00954                 static LSUINT32 LSE_CALL                Utf16ToUtf8( LSUTF8 * _putf8Dst, const LSUTF16 * _putf16Src,
00955                         LSUINT32 _ui32MaxLen );
00956 
00968                 static LSUINT32 LSE_CALL                Utf16ToUtf32( LSUTF32 * _putf32Dst, const LSUTF16 * _putf16Src,
00969                         LSUINT32 _ui32MaxLen );
00970 
00982                 static LSUINT32 LSE_CALL                Utf8ToUtf16( LSUTF16 * _putf16Dst, const LSUTF8 * _putf8Src,
00983                         LSUINT32 _ui32MaxLen );
00984 
00996                 static LSUINT32 LSE_CALL                Utf8ToUtf32( LSUTF32 * _putf32Dst, const LSUTF8 * _putf8Src,
00997                         LSUINT32 _ui32MaxLen );
00998 
01010                 static LSUINT32 LSE_CALL                Utf8ToUtfX( LSUTFX * _putfxDst, const LSUTF8 * _putf8Src,
01011                         LSUINT32 _ui32MaxLen );
01012 
01019                 static LSUINT32 LSE_CALL                Utf32StrLen( const LSUTF32 * _putf32String );
01020 
01027                 static LSUINT32 LSE_CALL                Utf16StrLen( const LSUTF16 * _putf16String );
01028 
01035                 static LSUINT32 LSE_CALL                Utf8StrLen( const LSUTF8 * _putf8String );
01036 
01045                 static LSUINT32 LSE_CALL                Utf32StrLenAsUtf8( const LSUTF32 * _putf32String );
01046 
01055                 static LSUINT32 LSE_CALL                Utf32StrLenAsUtf16( const LSUTF32 * _putf32String );
01056 
01065                 static LSUINT32 LSE_CALL                Utf16StrLenAsUtf8( const LSUTF16 * _putf16String );
01066 
01075                 static LSUINT32 LSE_CALL                Utf16StrLenAsUtf32( const LSUTF16 * _putf16String );
01076 
01085                 static LSUINT32 LSE_CALL                Utf8StrLenAsUtf16( const LSUTF8 * _putf8String );
01086 
01095                 static LSUINT32 LSE_CALL                Utf8StrLenAsUtf32( const LSUTF8 * _putf8String );
01096 
01105                 static LSUINT32 LSE_CALL                Utf8StrLenAsUtfX( const LSUTF8 * _putf8String );
01106 
01113                 static LSBOOL LSE_CALL                  IsWhitespace( LSUTFX _wcChar );
01114 
01121                 static LSBOOL LSE_CALL                  IsWhitespace( LSCHAR _cChar );
01122 
01129                 static LSBOOL LSE_CALL                  IsAlpha( LSUTFX _wcChar );
01130 
01137                 static LSBOOL LSE_CALL                  IsAlpha( LSCHAR _cChar );
01138 
01145                 static LSBOOL LSE_CALL                  IsDigit( LSUTFX _wcChar );
01146 
01153                 static LSBOOL LSE_CALL                  IsDigit( LSCHAR _cChar );
01154 
01161                 static LSBOOL LSE_CALL                  IsAlNum( LSUTFX _wcChar );
01162 
01169                 static LSBOOL LSE_CALL                  IsAlNum( LSCHAR _cChar );
01170 
01178                 static LSBOOL LSE_CALL                  IsIdentifier( const LSUTFX * _pwcStr );
01179 
01187                 static LSBOOL LSE_CALL                  IsIdentifier( const LSCHAR * _pcStr );
01188 
01198                 static LSVOID * LSE_CALL                MemCpy( LSVOID * _pvDst, const LSVOID * _pvSrc, LSUINTPTR _uiptrSize );
01199 
01208                 static LSVOID * LSE_CALL                MemMove( LSVOID * _pvDst, const LSVOID * _pvSrc, LSUINTPTR _uiptrSize );
01209 
01219                 static LSBOOL LSE_CALL                  MemCmpF( const LSVOID * _pvBuf0, const LSVOID * _pvBuf1, LSUINTPTR _uiptrSize );
01220 
01229                 static LSINT32 LSE_CALL                 MemCmp( const LSVOID * _pvBuf0, const LSVOID * _pvBuf1, LSUINTPTR _uiptrSize );
01230 
01238                 static LSVOID LSE_CALL                  MemSet( LSVOID * _pvDst, LSUINT8 _ui8Value, LSUINTPTR _uiptrSize );
01239 
01248                 static const LSVOID * LSE_CALL  MemChr( const LSVOID * _pvBuffer, LSUINT8 _ui8Value, LSUINTPTR _uiptrSize );
01249 
01258                 static LSVOID * LSE_CALL                MemChr( LSVOID * _pvBuffer, LSUINT8 _ui8Value, LSUINTPTR _uiptrSize );
01259 
01269                 static LSUINT32 LSE_CALL                WSPrintF( LSUTFX * _pwcDest, LSUINTPTR _uiptrMaxLen, const LSUTFX * _pwcFormat, ... );
01270 
01280                 static LSUINT32 LSE_CALL                SPrintF( LSCHAR * _pcDest, LSUINTPTR _uiptrMaxLen, const LSCHAR * _pcFormat, ... );
01281                 
01282                 // Read formatted data from a string.
01283                 // Suspended because Microsoft Visual Studio does not expose vsscanf() (WTF).
01284                 //static LSINT32 LSE_CALL               SScanF( const LSCHAR * _pcBuffer, const LSCHAR * _pcFormat, 
01285                 
01292                 static LSVOID LSE_CALL                  Sleep( LSUINT32 _ui32Milliseconds );
01293 
01300                 static LSUINT64 LSE_CALL                ByteSwap64( LSUINT64 _ui64Value );
01301 
01308                 static LSUINT32 LSE_CALL                ByteSwap32( LSUINT32 _ui32Value );
01309 
01316                 static LSUINT16 LSE_CALL                ByteSwap16( LSUINT16 _ui16Value );
01317 
01324                 static LSUINT8 LSE_CALL                 BitSwap8( LSUINT8 _ui8Byte );
01325 
01332                 static LSUINT16 LSE_CALL                BitSwap16( LSUINT16 _ui16Value );
01333 
01340                 static LSUINT32 LSE_CALL                BitSwap32( LSUINT32 _ui32Value );
01341 
01348                 static LSUINT64 LSE_CALL                BitSwap64( LSUINT64 _ui64Value );
01349 
01356                 static LSUINT32 LSE_CALL                CountBits( LSUINT32 _ui32Value );
01357 
01364                 static LSUINT32 LSE_FCALL               GetLowestPo2( LSUINT32 _ui32Value );
01365 
01371                 static LSVOID LSE_CALL                  DebugPrintW( const LSUTFX * _pwcString );
01372 
01378                 static LSVOID LSE_CALL                  DebugPrintA( const LSCHAR * _pcString );
01379 
01385                 static LSVOID LSE_CALL                  PrintError( LSSTD_ERRORS _eError );
01386 
01394                 template <class T>
01395                 static T LSE_CALL                               Min( T _tLeft, T _tRight ) {
01396                         return _tLeft < _tRight ? _tLeft : _tRight;
01397                 }
01398 
01406                 template <class T>
01407                 static T LSE_CALL                               Max( T _tLeft, T _tRight ) {
01408                         return _tLeft > _tRight ? _tLeft : _tRight;
01409                 }
01410 
01419                 template <class T>
01420                 static T LSE_CALL                               Clamp( T _tValue, T _tLow, T _tHigh ) {
01421                         if ( _tValue < _tLow ) { return _tLow; }
01422                         if ( _tValue > _tHigh ) { return _tHigh; }
01423                         return _tValue;
01424                 }
01425 
01432                 static LSE_INLINE LSINT64 LSE_CALL
01433                                                                                 RoundInt( LSDOUBLE _dValue );
01434 
01441                 static LSE_INLINE LSINT64 LSE_CALL
01442                                                                                 RoundInt( LSFLOAT _fValue );
01443 
01450                 static LSE_INLINE LSUINT32 LSE_FCALL
01451                                                                                 HighestBit( LSUINT64 _ui64Value );
01452 
01459                 static LSE_INLINE LSUINT32 LSE_FCALL
01460                                                                                 HighestBit( LSUINT32 _ui32Value );
01461 
01462 
01463         private :
01475                 template <unsigned _uLookUpBits, unsigned _uExpPos, unsigned _uBias, unsigned _uTotalBits, typename _tCharType>
01476                 static _tCharType * LSE_CALL            FtoA( _tCharType * _ptOutBuffer, LSUINT32 _ui32MaxLen, const LSUINT8 * _pui8Value, LSUINT32 _ui32Precision, LSINT8 _i8Format );
01477 
01478         };
01479 
01480 
01481         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
01482         // DEFINITIONS
01483         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
01484         // == Functions.
01498         LSE_INLINE LSUINT32 LSE_CALL CStd::NextUtf32Char( const LSUTF32 * _putf32Char, LSUINT32 _ui32Len, LSUINT32 * _pui32Size ) {
01499                 if ( _ui32Len == 0UL ) { return 0UL; }
01500                 if ( _pui32Size ) {
01501                         (*_pui32Size) = 1UL;
01502                 }
01503                 LSUINT32 ui32Ret = (*_putf32Char);
01504                 if ( ui32Ret & 0xFFE00000 ) { return LSSUTF_INVALID; }
01505                 return ui32Ret;
01506         }
01507 
01519         LSE_INLINE LSUINT32 LSE_CALL CStd::RawUnicodeToUtf32Char( LSUINT32 _ui32Raw, LSUINT32 &_ui32Len ) {
01520                 _ui32Len = 1UL;
01521                 return _ui32Raw;
01522         }
01523 
01530         LSE_INLINE LSUINT64 LSE_CALL CStd::ByteSwap64( LSUINT64 _ui64Value ) {
01531                 return ((_ui64Value >> 56) & 0x00000000000000FFULL) |
01532                         ((_ui64Value >> 40) & 0x000000000000FF00ULL) |
01533                         ((_ui64Value >> 24) & 0x0000000000FF0000ULL) |
01534                         ((_ui64Value >> 8) & 0x00000000FF000000ULL) |
01535                         ((_ui64Value << 8) & 0x000000FF00000000ULL) |
01536                         ((_ui64Value << 24) & 0x0000FF0000000000ULL) |
01537                         ((_ui64Value << 40) & 0x00FF000000000000ULL) |
01538                         ((_ui64Value << 56) & 0xFF00000000000000ULL);
01539         }
01540 
01547         LSE_INLINE LSUINT32 LSE_CALL CStd::ByteSwap32( LSUINT32 _ui32Value ) {
01548                 return ((_ui32Value >> 24) & 0x000000FF) |
01549                         ((_ui32Value >> 8) & 0x0000FF00) |
01550                         ((_ui32Value << 8) & 0x00FF0000) |
01551                         ((_ui32Value << 24) & 0xFF000000);
01552         }
01553 
01560         LSE_INLINE LSUINT16 LSE_CALL CStd::ByteSwap16( LSUINT16 _ui16Value ) { 
01561                 return ((_ui16Value >> 8) & 0x00FF) |
01562                         ((_ui16Value << 8) & 0xFF00);
01563         }
01564 
01571         LSE_INLINE LSUINT8 LSE_CALL CStd::BitSwap8( LSUINT8 _ui8Byte ) {
01572                 _ui8Byte = static_cast<LSUINT8>((_ui8Byte & 0xF0) >> 4 | (_ui8Byte & 0x0F) << 4);
01573                 _ui8Byte = static_cast<LSUINT8>((_ui8Byte & 0xCC) >> 2 | (_ui8Byte & 0x33) << 2);
01574                 _ui8Byte = static_cast<LSUINT8>((_ui8Byte & 0xAA) >> 1 | (_ui8Byte & 0x55) << 1);
01575                 return _ui8Byte;
01576         }
01577 
01584         LSE_INLINE LSUINT16 LSE_CALL CStd::BitSwap16( LSUINT16 _ui16Value ) {
01585                 _ui16Value = static_cast<LSUINT16>(((_ui16Value & 0xAAAA) >>  1) | ((_ui16Value & 0x5555) << 1));
01586                 _ui16Value = static_cast<LSUINT16>(((_ui16Value & 0xCCCC) >>  2) | ((_ui16Value & 0x3333) << 2));
01587                 _ui16Value = static_cast<LSUINT16>(((_ui16Value & 0xF0F0) >>  4) | ((_ui16Value & 0x0F0F) << 4));
01588                 return static_cast<LSUINT16>(((_ui16Value & 0xFF00) >>  8) | ((_ui16Value & 0x00FF) << 8));
01589         }
01590 
01597         LSE_INLINE LSUINT32 LSE_CALL CStd::BitSwap32( LSUINT32 _ui32Value ) {
01598                 _ui32Value = ((_ui32Value >> 1UL) & 0x55555555UL) | ((_ui32Value << 1UL) & 0xAAAAAAAAUL);
01599                 _ui32Value = ((_ui32Value >> 2UL) & 0x33333333UL) | ((_ui32Value << 2UL) & 0xCCCCCCCCUL);
01600                 _ui32Value = ((_ui32Value >> 4UL) & 0x0F0F0F0FUL) | ((_ui32Value << 4UL) & 0xF0F0F0F0UL);
01601                 _ui32Value = ((_ui32Value >> 8UL) & 0x00FF00FFUL) | ((_ui32Value << 8UL) & 0xFF00FF00UL);
01602                 return ((_ui32Value >> 16UL) & 0x0000FFFFUL) | ((_ui32Value << 16UL) & 0xFFFF0000UL);
01603         }
01604 
01611         LSE_INLINE LSUINT64 LSE_CALL CStd::BitSwap64( LSUINT64 _ui64Value ) {
01612                 _ui64Value = ((_ui64Value & 0x5555555555555555ULL) >> 1ULL) | ((_ui64Value & 0xAAAAAAAAAAAAAAAAULL) << 1ULL);
01613                 _ui64Value = ((_ui64Value & 0xCCCCCCCCCCCCCCCCULL) >> 2ULL) | ((_ui64Value & 0x3333333333333333ULL) << 2ULL);
01614                 _ui64Value = ((_ui64Value & 0xF0F0F0F0F0F0F0F0ULL) >> 4ULL) | ((_ui64Value & 0x0F0F0F0F0F0F0F0FULL) << 4ULL);
01615                 _ui64Value = ((_ui64Value & 0x00FF00FF00FF00FFULL) >> 8ULL) | ((_ui64Value & 0xFF00FF00FF00FF00ULL) << 8ULL);
01616                 _ui64Value = ((_ui64Value & 0x0000FFFF0000FFFFULL) >> 16ULL) | ((_ui64Value & 0xFFFF0000FFFF0000ULL) << 16ULL);
01617                 return ((_ui64Value & 0xFFFFFFFF00000000ULL) >> 32ULL) | ((_ui64Value & 0x00000000FFFFFFFFULL) << 32ULL);
01618         }
01619 
01626         LSE_INLINE LSUINT32 LSE_CALL CStd::CountBits( LSUINT32 _ui32Value ) {
01627                 LSUINT32 ui32Total = 0UL;
01628                 for ( LSUINT32 I = (1UL << ((sizeof( _ui32Value ) << 3UL) - 1UL)); I != 0UL; I >>= 1UL ) {
01629                         if ( _ui32Value & I ) { ++ui32Total; }
01630                 }
01631                 return ui32Total;
01632         }
01633 
01640         LSE_INLINE LSUINT32 LSE_FCALL CStd::GetLowestPo2( LSUINT32 _ui32Value ) {
01641                 if ( !_ui32Value ) { return 0UL; }
01642 #ifdef LSE_X86
01643                 // On x86 processors there is an instruction that gets the highest-
01644                 //      set bit automatically.
01645                 LSUINT32 ui32Ret;
01646                 LSE_ASM_BEGIN
01647                         xor eax, eax
01648                         bsr eax, _ui32Value
01649                         mov ui32Ret, eax
01650                 LSE_ASM_END
01651                 ui32Ret = 1UL << ui32Ret;
01652                 return (ui32Ret == _ui32Value) ? ui32Ret : ui32Ret << 1UL;
01653 #else   // LSE_X86
01654                 // Get it the hard way.
01655                 LSUINT32 ui32Ret = 1UL;
01656                 while ( ui32Ret < _ui32Value ) { ui32Ret <<= 1; }
01657 
01658                 // By now, ui32Ret either equals _ui32Value or is the next power of 2 up.
01659                 // If they are equal, _ui32Value is already a power of 2.
01660                 return ui32Ret;
01661 #endif  // LSE_X86
01662         }
01663 
01670         LSE_INLINE LSINT64 LSE_CALL CStd::RoundInt( LSDOUBLE _dValue ) {
01671                 return static_cast<LSINT64>(_dValue >= 0.0 ? _dValue + 0.5 : _dValue - 0.5);
01672         }
01673 
01680         LSE_INLINE LSINT64 LSE_CALL CStd::RoundInt( LSFLOAT _fValue ) {
01681                 return static_cast<LSINT64>(_fValue >= 0.0f ? _fValue + 0.5f : _fValue - 0.5f);
01682         }
01683 
01690         LSE_INLINE LSUINT32 LSE_FCALL CStd::HighestBit( LSUINT64 _ui64Value ) {
01691                 if ( !_ui64Value ) { return 0UL; }
01692 #ifdef LSE_X86
01693                 // On x86 processors there is an instruction that gets the highest-
01694                 //      set bit automatically.
01695                 LSUINT32 ui32Ret;
01696                 LSINT32 i32High = static_cast<LSINT32>(_ui64Value >> 32ULL);
01697                 LSE_ASM_BEGIN
01698                         xor eax, eax
01699                         bsr eax, i32High
01700                         mov ui32Ret, eax
01701                 LSE_ASM_END
01702                 if ( ui32Ret ) {
01703                         return ui32Ret + 32UL;
01704                 }
01705 
01706                 i32High = static_cast<LSINT32>(_ui64Value & 0xFFFFFFFFULL);
01707                 LSE_ASM_BEGIN
01708                         bsr eax, i32High
01709                         mov ui32Ret, eax
01710                 LSE_ASM_END
01711                 return ui32Ret;
01712 #else   // LSE_X86
01713                 // Get it the hard way.
01714                 LSUINT32 ui32Ret = (sizeof( _ui64Value ) << 3UL);
01715                 for ( ; ui32Ret--;  ) {
01716                         if ( _ui64Value & (1ULL << ui32Ret) ) { return ui32Ret; }
01717                 }
01718                 return 0UL;
01719 #endif  // LSE_X86
01720         }
01721 
01728         LSE_INLINE LSUINT32 LSE_FCALL CStd::HighestBit( LSUINT32 _ui32Value ) {
01729                 if ( !_ui32Value ) { return 0UL; }
01730 #ifdef LSE_X86
01731                 // On x86 processors there is an instruction that gets the highest-
01732                 //      set bit automatically.
01733                 LSUINT32 ui32Ret;
01734                 LSE_ASM_BEGIN
01735                         xor eax, eax
01736                         bsr eax, _ui32Value
01737                         mov ui32Ret, eax
01738                 LSE_ASM_END
01739                 return ui32Ret;
01740 #else   // LSE_X86
01741                 // Get it the hard way.
01742                 LSUINT32 ui32Ret = (sizeof( _ui32Value ) << 3UL);
01743                 for ( ; ui32Ret--;  ) {
01744                         if ( _ui32Value & (1UL << ui32Ret) ) { return ui32Ret; }
01745                 }
01746                 return 0UL;
01747 #endif  // LSE_X86
01748         }
01749         
01750 }       // namespace lsstd
01751 
01752 #endif  // __LSSTD_STANDARDLIB_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator