Codemesh Runtime v3 C++ API Reference  3.9.205
Static Public Member Functions | List of all members
xmog_util Class Reference

A utility class providing several commonly useful methods. More...

#include <xmog_util.h>

Static Public Member Functions

static void * alloc (size_t len)
 Allocates the requested number of bytes. More...
 
static void free (void *ptr)
 Deallocates a pointer that was allocated using alloc(). More...
 
static char * setString (char *&strVar, const char *value, size_t len=(size_t) -1)
 Sets a string to another string after cleaning up the previous string. More...
 
static unsigned short * setString_u16 (unsigned short *&strVar, const unsigned short *value, size_t len=(size_t) -1)
 
static size_t strlen_u16 (const unsigned short *str)
 Returns the length of the given string in 2-byte characters. More...
 
static size_t strlen_XMOG_WCHAR (const XMOG_WCHAR *str)
 Returns the length of the given string . More...
 
static void strncpy_u16 (unsigned short *dest, const unsigned short *src, size_t len)
 Copies up to len 2-byte characters from the source string to the target location. More...
 
static bool to_bool (const char *strVal)
 Returns the bool value represented by the passed in string. More...
 
static void * to_funptr (const char *strVal)
 Returns an entry point represented by its string'ized representation. More...
 
static char * concatStrings (const char *str1, const char *str2)
 Concatenates two strings and returns the result. More...
 
static bool endsWith (const char *str, const char *suffix, bool bCaseSensitive=true)
 Returns true if a given string ends with a given substring. More...
 
static int hasFileAccess (const char *name, xmog_privileges priv)
 Returns 0 if we have the requested privileges for a given file, -1 otherwise. More...
 
static bool hasProperType (const char *name)
 Returns true if the specified file is of the proper binary type to be used with this module. More...
 
static bool isWindows ()
 Returns true if we're running on a Windows platform.
 
static int readLine (FILE *file, char *&line)
 Reads a line from a file.
 
static void sleep (int ms)
 Sleeps for the specified number of milliseconds. More...
 
static unsigned short * utf8_to_u16 (const char *utf8)
 Converts a UTF8 string to a dynamically allocated 16bit character string. More...
 
static unsigned char * utf16_to_u8 (const unsigned short *utf16)
 Converts a UTF16 string to a dynamically allocated 8bit character string. More...
 

Detailed Description

A utility class providing several commonly useful methods.

Member Function Documentation

◆ alloc()

static void* xmog_util::alloc ( size_t  len)
static

Allocates the requested number of bytes.

Parameters
lenthe number of bytes to allocate.

◆ concatStrings()

static char* xmog_util::concatStrings ( const char *  str1,
const char *  str2 
)
static

Concatenates two strings and returns the result.

Both strings must be non-NULL.

Parameters
str1the first string.
str2the second string.
Returns
the concatenated string, allocated using new char[].

◆ endsWith()

static bool xmog_util::endsWith ( const char *  str,
const char *  suffix,
bool  bCaseSensitive = true 
)
static

Returns true if a given string ends with a given substring.

The comparison can be performed either case sensitive of case insensitive. The default is case sensitive.

Parameters
strthe string which we inspect for a certain suffix.
suffixthe suffix for which we're looking.
bCaseSensitivetrue for case sensitive search, false otherwise.

◆ free()

static void xmog_util::free ( void *  ptr)
static

Deallocates a pointer that was allocated using alloc().

Parameters
ptrthe memory to free.

◆ hasFileAccess()

static int xmog_util::hasFileAccess ( const char *  name,
xmog_privileges  priv 
)
static

Returns 0 if we have the requested privileges for a given file, -1 otherwise.

Parameters
namethe file which we want to test.
privthe privileges for which we're asking.

◆ hasProperType()

static bool xmog_util::hasProperType ( const char *  name)
static

Returns true if the specified file is of the proper binary type to be used with this module.

This function is mostly used on Windows to perform 64-bit vs. 32-bit testing of DLLs. A DLL might not be processor architecture compatible with the process into which it should be loaded. By testing the DLL prior to loading it, we can provide a better diagnostic message.

On platforms where we don't know how to find out the compatibility status, we always return true.

Parameters
namethe file which we want to test.

◆ setString()

static char* xmog_util::setString ( char *&  strVar,
const char *  value,
size_t  len = (size_t) -1 
)
static

Sets a string to another string after cleaning up the previous string.

This utility method dynamically allocates a new string and sets it to value. The newly allocated string is set into strVar after first deleting the string that was stored there.

Parameters
strVara reference to the variable holding a previously allocated string (or NULL).
valuethe new value of the string.
lenthe optional string length. If -1, setString() calculates value's string length, otherwise it uses the passed in string length and only uses the specified substring.
Returns
the newly allocated string.

◆ sleep()

static void xmog_util::sleep ( int  ms)
static

Sleeps for the specified number of milliseconds.

The time resolution is platform and maybe even host-specific. On Windows systems you can typically expect a 16ms resolution, on Unix systems where we are using the sleep() method, you should assume a 1000ms resolution.

Parameters
msthe time to sleep in milliseconds.

◆ strlen_u16()

static size_t xmog_util::strlen_u16 ( const unsigned short *  str)
static

Returns the length of the given string in 2-byte characters.

Parameters
strthe string whose length to take.
Returns
the string length.

◆ strlen_XMOG_WCHAR()

static size_t xmog_util::strlen_XMOG_WCHAR ( const XMOG_WCHAR *  str)
static

Returns the length of the given string .

Parameters
strthe string whose length to take.
Returns
the string length.

◆ strncpy_u16()

static void xmog_util::strncpy_u16 ( unsigned short *  dest,
const unsigned short *  src,
size_t  len 
)
static

Copies up to len 2-byte characters from the source string to the target location.

Parameters
destpointer to the destination.
srcpointer to the source.
lenthe maximum number of characters to copy.

◆ to_bool()

static bool xmog_util::to_bool ( const char *  strVal)
static

Returns the bool value represented by the passed in string.

The string "true" (case-insensitive) will result in true, every other string will result in false.

◆ to_funptr()

static void* xmog_util::to_funptr ( const char *  strVal)
static

Returns an entry point represented by its string'ized representation.

An entry point is defined by its module (optional) and its name (required). The two parts are separated by a semicolon. Examples of legal string representations are:

Example 1

The following example looks for an entry point named MyFunction that is expected to be found in the runtime library itself:

MyFunction

Example 2

The following example looks for an entry point named MyFunction that is expected to be found in a dynamic library called myutil.dll or libmyutil.so or whatever the platform-dependent name of a dynamic library called myutil resolves to:

myutil;MyFunction
Parameters
strValthe string'ized form of the entry point.

◆ utf16_to_u8()

static unsigned char* xmog_util::utf16_to_u8 ( const unsigned short *  utf16)
static

Converts a UTF16 string to a dynamically allocated 8bit character string.

The caller is responsible for freeing the string using xmog_util::free().

Parameters
utf16the input string.

◆ utf8_to_u16()

static unsigned short* xmog_util::utf8_to_u16 ( const char *  utf8)
static

Converts a UTF8 string to a dynamically allocated 16bit character string.

The caller is responsible for freeing the string using xmog_util::free().

Parameters
utf8the input string.

The documentation for this class was generated from the following file:

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.