The Crosswalk SDK provides a number of helpful macros which fall under the these categories:
• String Manipulation Wrappers
Some macros can facilitate writing cross-platform code using string functions. _SI_TEXT is used to wrap string constants so that it is compatible with both Unicode and ANSI code. For example, rather than use the following code:
_SI_PRINTF("Hello World\n");Use this instead:
_SI_PRINTF(_SI_TEXT("Hello World\n"));These macros wrap string manipulation functions. See any ANSI C documentation for more details:
|
Macro Name |
Description |
|
_SI_STRCMP |
Macro for the strcmp function |
|
_SI_STRDUP |
Macro for the strdup function |
|
_SI_STRCPY |
Macro for the strcpy function |
|
_SI_STRCAT |
Macro for the strcat function |
|
_SI_SPRINTF |
Macro for the sprintf function |
|
_SI_STRLEN |
Macro for the strlen function |
|
_SI_PRINTF |
Macro for the printf function |
|
_SI_STRTOK |
Macro for the strtok function |
|
_SI_STRSTR |
Macro for the strstr function |
|
_SI_STRCHR |
Macro for the strchr function |
|
_SI_ATOI |
Macro for the atoi function |
Since the XSI Viewer does not have a console to output to, the XSI Viewer redirects the output of the _SI_PRINTF macro to a log file which you can find under the launch directory for the XSI Viewer application. You use your own log file by using the CSIBCUtil::Open and CSIBCutil::Close functions.
Example (String Manipulation)
SI_Error result = SI_SUCCESS;
_SI_CALL(CSIBCUtil::Open("foo"),_SI_TEXT("Opening File Failed"));
if (result == SI_SUCCESS)
{
_SI_PRINTF(_SI_TEXT(“Hello World\n”);
}
_SI_CALL(CSIBCutil::Close(), _SI_TEXT(“Closing file”));
These macros wrap common math functions. See any ANSI C documentation for more details.
|
Macro Name |
Description |
|
_SI_RAND |
Macro for the rand function |
|
_SI_SQRT |
Macro for the sqrt function |
|
_SI_SQRTF |
Macro for the sqrtf function |
|
_SI_ASIN |
Macro for the asin function |
|
_SI_ASINF |
Macro for the asinf function |
|
_SI_ACOS |
Macro for the acos function |
|
_SI_ACOSF |
Macro for the acosf function |
|
_SI_FLOOR |
Macro for the floor function |
|
_SI_FLOORF |
Macro for the floorf function |
|
_SI_COS |
Macro for the cos function |
|
_SI_COSF |
Macro for the cosf function |
|
_SI_SIN |
Macro for the sin function |
|
_SI_SINF |
Macro for the sinf function |
|
_SI_TAN |
Macro for the tan function |
|
_SI_TANF |
Macro for the tanf function |
|
_SI_ATANF |
Macro for the atanf function |
|
_SI_ATAN |
Macro for the atan function |
Since file systems may differ from platform to platform, some macros are also provided to facilitate file access. _SI_FILE is the XSI Viewer file handle. It is used by all file access macros. See any ANSI C documentation for more details.
These are the wrapped file access functions:
|
Functions |
Descriptions |
|
_SI_FOPEN( name, mode ) |
Opens a file using a file name and an access mode. The access mode can be either one of _SI_FILE_READ_TEXT (to open a file in text mode) or _SI_FILE_READ_BINARY (to open a file in binary mode). It returns _SI_FILE_NULL if the file cannot be opened. Otherwise, if successful, it returns an _SI_FILE handle. |
|
_SI_FCLOSE(handle) |
Closes a file described by the file handle. |
|
_SI_FREAD( buffer, size, count, handle ) |
Reads from a file. See the fread function in the ANSI C documentation for more details. |
|
_SI_FWRITE( buffer, size, count, handle ) |
Writes to a file. See the fread function in the ANSI C documentation for more details. |
|
_SI_FPRINTF(handle, string) |
Prints the string to a file. |
|
_SI_FSEEK( handle, count, type ) |
Sets the file at a specific position according to these rules: • If type is set to _SI_FILE_SET then count is used as the offset from the beginning of the file. • If type is set to _SI_FILE_CUR, then count is used as the offset from the current file position. • If type is set to _SI_FILE_END, then count is used as a negative offset from the end of the file. See the fseek function in the ANSI C documentation for more details. |
|
_SI_FTELL( handle ) |
Returns the current position in bytes of the file. See the ftell function in the ANSI C documentation for more details. |
|
_SI_FGETC( handle ) |
Gets the next character in the file. See the getc function in the ANSI C documentation for more details. |
|
_SI_FEOF( handle ) |
Checks if the end of the file has been reached. |
|
_SI_FERROR( handle ) |
Checks if there is an error on the file. See the ferror function in the ANSI C documentation for more details. |
|
_SI_FFLUSH( x ) |
Flushes the buffered content of the file on disk. See the fflush function in the ANSI C documentation for more details. |
|
_SI_UNGETC( character, handle ) |
Pushes a character back into the file. See the ungetc function in the ANSI C documentation for more details. |
Example (File Access)
Here is an example of reading 10 bytes from a file called "foo"
_SI_FILE filePtr;
SI_Byte buffer[10];
filePtr = _SI_Open(_SI_TEXT("foo"), _SI_FILE_READ_BINARY);
if(filePtr != _SI_FILE_NULL)
{
_SI_FREAD(buffer,sizeof(SI_Byte), 10, filePtr);
_SI_FCLOSE(filePtr);
}
Some macros facilitate memory allocation and error checking. These include:
• _SI_NEW(instance pointer, class constructor)
• _SI_DELETE(instance pointer)
Example (Memory Allocation)
CSIBCVector3D* pVec3D; _SI_NEW(pVec3D, CSIBCVector3D()); _SI_DELETE(pVec3D);
You can use the XSIEXPORT macro to export functions. This macro maps to __desclspec(dllexport) when the _XSI_PLUGIN_ macro is defined.
Autodesk Crosswalk v5.0