CRM64Pro GDK  v0.94
A free cross-platform game development kit built on top of SDL 2.0
Classes | Macros | Functions
Tool

Classes

class  CRM64Pro::Tool
 

Macros

#define TMBB_OK   1
 
#define TMBB_CANCEL   2
 
#define TMBB_YES   4
 
#define TMBB_NO   8
 

Functions

Sint32 CRM64Pro::Tool::info (Sint32 iMode=0)
 
Uint32 CRM64Pro::Tool::CRC32 (const void *pBuffer, size_t iSize, Uint32 iPreviousCRC32=0)
 
Uint32 CRM64Pro::Tool::CRC32 (const string &sFile)
 
Uint32 CRM64Pro::Tool::xxHash (const void *pBuffer, size_t iSize, Uint32 iSeed)
 
void * CRM64Pro::Tool::xxHashInit (Uint32 iSeed)
 
Sint32 CRM64Pro::Tool::xxHashUpdate (void *pState, const void *pBuffer, size_t iSize)
 
Uint32 CRM64Pro::Tool::xxHashDigest (void *pState)
 
Sint32 CRM64Pro::Tool::xxHashEnd (void *pState)
 
Sint32 CRM64Pro::Tool::XOR (void *pSrc, size_t iSize, Uint8 cKey)
 
void CRM64Pro::Tool::randSeedMWC (Uint32 iSeed)
 
Uint32 CRM64Pro::Tool::randMWC ()
 
double CRM64Pro::Tool::randRealMWC ()
 
void CRM64Pro::Tool::randSeedWELL (Uint32 iSeed, Uint32 *pSeedTable=nullptr)
 
Uint32 CRM64Pro::Tool::randWELL (Uint32 *pSeedState=nullptr, Uint32 *pSeedTable=nullptr)
 
double CRM64Pro::Tool::randRealWELL ()
 
float CRM64Pro::Tool::round (const float fNum)
 
Sint32 CRM64Pro::Tool::dirExists (const string &sPath)
 
Sint32 CRM64Pro::Tool::dirCreate (const string &sPath)
 
Sint32 CRM64Pro::Tool::fileExists (const string &sPath)
 
Sint32 CRM64Pro::Tool::fileRemove (const string &sPath)
 
Sint32 CRM64Pro::Tool::fileGetAbsolutePath (const string &sPath, string &sAbsolutePath)
 
Sint32 CRM64Pro::Tool::fileGetExePath (string &sPath)
 
Sint32 CRM64Pro::Tool::fileGetName (const string &sPath, string &sFileName)
 
Sint32 CRM64Pro::Tool::fileGetDir (const string &sPath, string &sDirName)
 
Sint32 CRM64Pro::Tool::fileGetExtension (const string &sPath, string &sExtensionName)
 
Sint32 CRM64Pro::Tool::fileCheckExtension (const string &sPath, const string &sExt)
 
Sint32 CRM64Pro::Tool::fileOpenDialog (const string &sTitle, const char *szFilter, string &sSelectedFile)
 
Sint32 CRM64Pro::Tool::fileSaveDialog (const string &sTitle, const char *szFilter, string &sSelectedFile)
 
Sint32 CRM64Pro::Tool::messageBox (const string &sTitle, const string &sMsg, Uint32 iButtons=TMBB_OK, eToolMBT eTMBT=TMBT_INFO, Sint32 iTTL=0, Sint32 idCustomPanel=-1)
 
Sint32 CRM64Pro::Tool::szCopy (char *szDst, const char *szSrc, size_t iSize)
 
Sint32 CRM64Pro::Tool::getDateStamp (string &sString)
 
Sint32 CRM64Pro::Tool::strCompare (const string &sOne, const string &sTwo)
 
Sint32 CRM64Pro::Tool::strToLowerCase (string &sString)
 
Sint32 CRM64Pro::Tool::strToUpperCase (string &sString)
 
Sint32 CRM64Pro::Tool::intToStrDec (Sint32 iNum, string &sString)
 
Sint32 CRM64Pro::Tool::intToStrHex (Sint32 iNum, string &sString)
 
Sint32 CRM64Pro::Tool::vStrToFile (const vector< string > &vString, const string &sFileName)
 
Sint32 CRM64Pro::Tool::fileTovStr (vector< string > &vString, const string &sFileName)
 

Detailed Description

Useful methods:


Only a single instance of the Tool interface exists which is created once Main is instantiated.
You can get a reference to this interface using Main::ITool() method.

Note
The Tool interface is automatically released when Main::Terminate() is called.
At this time, if any resource is still loaded, it will be released avoding a resource leak.

Macro Definition Documentation

#define TMBB_OK   1

MessageBox Button OK. 'iButtons' parameter in Tools::messageBox().

#define TMBB_CANCEL   2

MessageBox Button Cancel. 'iButtons' parameter in Tools::messageBox().

#define TMBB_YES   4

MessageBox Button Yes. 'iButtons' parameter in Tools::messageBox().

#define TMBB_NO   8

MessageBox Button No. 'iButtons' parameter in Tools::messageBox().

Enumeration Type Documentation

Tool MessageBox type.

Enumerator
TMBT_EMPTY 

MessageBox type empty. 'eTMBT' parameter in Tools:messageBox().

TMBT_ERROR 

MessageBox type error. 'eTMBT' parameter in Tools::messageBox().

TMBT_WARNING 

MessageBox type warning. 'eTMBT' parameter in Tools::messageBox().

TMBT_INFO 

MessageBox type information. 'eTMBT' parameter in Tools::messageBox().

Function Documentation

Sint32 CRM64Pro::Tool::info ( Sint32  iMode = 0)

Request Tool Interface information.

For displaying the information, it uses the default log.

Parameters
iModeunused for the time being.
Returns
0 on success or a negative error code on failure.
Uint32 CRM64Pro::Tool::CRC32 ( const void *  pBuffer,
size_t  iSize,
Uint32  iPreviousCRC32 = 0 
)

CRC32 checksum of a memory buffer.

This algorithm take +-8 CPU cycles per byte.

Parameters
pBufferpointer to the memory buffer.
iSizesize in bytes of the memory buffer.
iPreviousCRC32support for rolling mechanism: if you already have a memory buffer and its CRC32 checksum, then you can append new data and calculate the updated CRC32 but using your original value as a seed and just scanning through the appended data.
By default, it is set to 0.
Returns
CRC32 checksum of the memory buffer.
Uint32 CRM64Pro::Tool::CRC32 ( const string &  sFile)

CRC32 checksum of a file.

Internally, it calls to memory buffer CRC32() method.

Parameters
sFilestring containing the [directory]+filename+[extension].
Returns
CRC32 checksum of the file.
Uint32 CRM64Pro::Tool::xxHash ( const void *  pBuffer,
size_t  iSize,
Uint32  iSeed 
)

xxHash 32bits checksum of a memory buffer.

This algorithm is very fast(16x faster than CRC32) and close to the memory bandwidth limit.

Parameters
pBufferpointer to the memory buffer.
iSizesize in bytes of the memory buffer.
iSeedcan be used to alter the result predictably.
Returns
xxHash 32bits checksum of the memory buffer.
void * CRM64Pro::Tool::xxHashInit ( Uint32  iSeed)

Initialize xxHash 32bits for being used in multiple memory buffers.

Parameters
iSeedcan be used to alter the result predictably.
Returns
a void* state which hold internal variables, do not modify it!.
Note
This state must be destroyed calling ton xxHashEnd()
Sint32 CRM64Pro::Tool::xxHashUpdate ( void *  pState,
const void *  pBuffer,
size_t  iSize 
)

Feed with a new memory buffer the xxHash 32bits.

Parameters
pStatea void* state previously created by xxHashInit().
pBufferpointer to the memory buffer.
iSizesize in bytes of the memory buffer.
Returns
0 on success or a negative error code on failure.
Uint32 CRM64Pro::Tool::xxHashDigest ( void *  pState)

Get current xxHash 32bits checksum for the accumulative memory buffers.

Parameters
pStatea void* state created by xxHashInit() and used on xxHashUpdate().
Returns
xxHash 32bits checksum of the memory buffers.
Sint32 CRM64Pro::Tool::xxHashEnd ( void *  pState)

Finalize xxHash 32bits used in multiple memory buffers.

Parameters
pStatea void* state created by xxHashInit().
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::XOR ( void *  pSrc,
size_t  iSize,
Uint8  cKey 
)

XOR of a memory buffer by a key(8bits).

It can be used for simple encryption/decryption tasks.

Parameters
pSrcpointer to the memory buffer.
iSizesize in bytes of the memory buffer.
cKeyunsigned char value representing the key.
Returns
0 on success or a negative error code on failure.
void CRM64Pro::Tool::randSeedMWC ( Uint32  iSeed)

Initializes the Multiply-with-carry(MWC) random number generator with a seed.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Parameters
iSeedany Uint32 from [0,4294967295] interval.
Uint32 CRM64Pro::Tool::randMWC ( )

Generates a random 32bits integer using Multiply-with-carry(MWC) algorithm.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Returns
random integer from [0,4294967295] interval.
double CRM64Pro::Tool::randRealMWC ( )

Generates a random 64bits real number using Multiply-with-carry(MWC) algorithm.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Returns
random real from [0,1] interval.
void CRM64Pro::Tool::randSeedWELL ( Uint32  iSeed,
Uint32 *  pSeedTable = nullptr 
)

Initializes the WELL512 random number generator with a seed.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Parameters
iSeedany Uint32 from [0,4294967295] interval.
pSeedTablepointer to an array of 16 Uint32 for storing the seed output.
By default it is set to nullptr for using an internal array.
Uint32 CRM64Pro::Tool::randWELL ( Uint32 *  pSeedState = nullptr,
Uint32 *  pSeedTable = nullptr 
)

Generates a random 32bits integer using WELL512 algorithm.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Parameters
pSeedStatepointer to an Uint32 containing the WELL512 algorithm state.
By default it is set to nullptr for using an internal Uint32.
pSeedTablepointer to an array of 16 Uint32 containing the seed current status.
By default it is set to nullptr for using an internal array.
Returns
random integer from [0,4294967295] interval.
double CRM64Pro::Tool::randRealWELL ( )

Generates a random 64bits real number using WELL512 algorithm.

For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.

Returns
random real from [0,1] interval.
float CRM64Pro::Tool::round ( const float  fNum)

Round a float value.

Parameters
fNumfloat to be rounded
Returns
rounded float value
Sint32 CRM64Pro::Tool::dirExists ( const string &  sPath)

Check if a directory exists.

Parameters
sPathstring containing the directory.
Directory separators '\' and '/' are supported.
Returns
0 on success(directory exists) or a negative error code on failure.
Sint32 CRM64Pro::Tool::dirCreate ( const string &  sPath)

Create a directory.

It extracts the directory, discards the filename and extension and try to create the directory.
Directory separators '\' and '/' are supported.

Parameters
sPathstring containing the directory (e.g. myDir/, myDir/mySubDir).
Returns
0 on success or a negative error code on failure.
Note
If the directory already exists, it does nothing and return a success code.
Sint32 CRM64Pro::Tool::fileExists ( const string &  sPath)

Check if a file exists.

Parameters
sPathstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
Returns
0 on success(file exists) or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileRemove ( const string &  sPath)

Remove a file.

Parameters
sPathstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileGetAbsolutePath ( const string &  sPath,
string &  sAbsolutePath 
)

Get the absolute path of a given relative path.

Parameters
sPathstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
sAbsolutePatha string variable with the absolute path. Will not be modified on error.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileGetExePath ( string &  sPath)

Get the executable path.

Parameters
sPatha string variable containing the full executable path. Will not be modified on error.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileGetName ( const string &  sPath,
string &  sFileName 
)

Get the filename.

It removes the directory and extension if present and get only the filename.

Parameters
sPathstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
sFileNamea string variable. Will not be modified on error.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileGetDir ( const string &  sPath,
string &  sDirName 
)

Get the directory.

It removes the name and extension if present and get only the directory.

Parameters
sPathstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
sDirNamea string variable. Will not be modified on error.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileGetExtension ( const string &  sPath,
string &  sExtensionName 
)

Get the extension.

It removes the directory and name if present and get only the extension.

Parameters
sPathstring containing the [directory]+filename+[extension].
sExtensionNamea string variable. Will not be modified on error.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileCheckExtension ( const string &  sPath,
const string &  sExt 
)

Check if a filename contains a given extension.

Parameters
sPathstring containing the [directory]+filename+[extension].
sExtthe extension to be checked.
Returns
0 on success(file contains given extension) or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileOpenDialog ( const string &  sTitle,
const char *  szFilter,
string &  sSelectedFile 
)

Create a native file open dialog.

Parameters
sTitlestring containing dialog title.
szFilterpointer to a buffer containing pairs of nullptr-terminated filter strings.
The first string in each pair is a display string that describes the filter (for example, "PNG Files"), and the second string specifies the filter pattern (for example, "*.png").
sSelectedFilestring to contain the directory+filename+extension of the selected file.
Returns
0 on success(sSelectedFile contains the selected file) or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileSaveDialog ( const string &  sTitle,
const char *  szFilter,
string &  sSelectedFile 
)

Create a native file save dialog.

Parameters
sTitlestring containing dialog title.
szFilterpointer to a buffer containing pairs of nullptr-terminated filter strings.
The first string in each pair is a display string that describes the filter (for example, "PNG Files"), and the second string specifies the filter pattern (for example, "*.png").
sSelectedFilestring to contain the directory+filename+extension of the selected file.
Returns
0 on success(sSelectedFile contains the selected file) or a negative error code on failure.
Sint32 CRM64Pro::Tool::messageBox ( const string &  sTitle,
const string &  sMsg,
Uint32  iButtons = TMBB_OK,
eToolMBT  eTMBT = TMBT_INFO,
Sint32  iTTL = 0,
Sint32  idCustomPanel = -1 
)

Create a messagebox.

Parameters
sTitlestring containing the messagebox title. It can be an empty string.
sMsgstring containing the messagebox body text. It can be an empty string.
iButtonsCheck TMBB_OK, TMBB_CANCEL, TMBB_YES and TMBB_NO for further information. You can OR'ed them.
By default is set to TMBB_OK.
eTMBTmessagebox type. Check eToolMBT enum for further information.
By default is set to TMBT_INFO.
iTTLTime to live of this messagebox. If set to 0, it is a modal panel, otherwise, it is a modeless one that will last for the specified time in milliseconds.
By default is set to 0.
idCustomPanelcustom panel id to be used as the messagebox.
By default is set to -1 for using an internal crafted messagebox panel.
Returns
0 when no selection, greater than 0 on success(selected button ::TMBB_OK, ::TMBB_CANCEL, ::TMBB_YES or ::TMBB_NO) or a negative error code on failure.
Sint32 CRM64Pro::Tool::szCopy ( char *  szDst,
const char *  szSrc,
size_t  iSize 
)

Copy a string-zero avoiding buffer overflow.

It avoids buffer overflow and always appends a nullptr string termination.

Parameters
szDstdestination char array of at least iSize size.
szSrcsource char array of at least iSize size.
iSizemaximum size of characters to copy.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::getDateStamp ( string &  sString)

Get current date+time stamp.

Parameters
sStringstring reference with the date+time stamp.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::strCompare ( const string &  sOne,
const string &  sTwo 
)

Case insensitive string comparation.

Parameters
sOnestring one.
sTwostring two.
Returns
0 when the strings are different and 1 if they are equal.
Sint32 CRM64Pro::Tool::strToLowerCase ( string &  sString)

Convert the string to lower case.

Parameters
sStringstring to be converted.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::strToUpperCase ( string &  sString)

Convert the string to upper case.

Parameters
sStringstring to be converted.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::intToStrDec ( Sint32  iNum,
string &  sString 
)

Convert an integer to a string in decimal format.

Parameters
iNuminteger number.
sStringstring to store the result.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::intToStrHex ( Sint32  iNum,
string &  sString 
)

Convert an integer to a string in hexadecimal format.

Parameters
iNuminteger number.
sStringstring to store the result.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::vStrToFile ( const vector< string > &  vString,
const string &  sFileName 
)

Save a vector<string> to a filename.

Parameters
vStringvector<string> to be dumped into an external filename.
Each string will be saved in a line.
sFileNamea string variable with the output file name.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::Tool::fileTovStr ( vector< string > &  vString,
const string &  sFileName 
)

Load lines of a filename into a vector<string>.

Parameters
vStringvector<string> to be loaded with lines of the filename.
sFileNamea string variable with the input file name.
Returns
0 on success or a negative error code on failure.