Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

xmog_util Class Reference

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

#include <xmog_util.h>

List of all members.

Static Public Member Functions

static void * alloc (size_t len)
 Allocates the requested number of bytes.
static void free (void *ptr)
 Deallocates a pointer that was allocated using alloc().
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.
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.
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.
static bool to_bool (const char *strVal)
 Returns the bool value represented by the passed in string.
static void * to_funptr (const char *strVal)
 Returns an entry point represented by its string'ized representation.
static char * concatStrings (const char *str1, const char *str2)
 Concatenates two strings and returns the result.
static bool endsWith (const char *str, const char *suffix, bool bCaseSensitive=true)
 Returns true if a given string ends with a given substring.
static int hasFileAccess (const char *name, xmog_privileges priv)
 Returns 0 if we have the requested privileges for a given file, -1 otherwise.
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.
static unsigned short * utf8_to_u16 (const char *utf8)
 Converts a UTF8 string to a dynamically allocated 16bit character string.


Detailed Description

A utility class providing several commonly useful methods.


Member Function Documentation

static void* xmog_util::alloc size_t  len  )  [static]
 

Allocates the requested number of bytes.

Parameters:
len the number of bytes to allocate.

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:
str1 the first string.
str2 the second string.
Returns:
the concatenated string, allocated using new char[].

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:
str the string which we inspect for a certain suffix.
suffix the suffix for which we're looking.
bCaseSensitive true for case sensitive search, false otherwise.

static void xmog_util::free void *  ptr  )  [static]
 

Deallocates a pointer that was allocated using alloc().

Parameters:
ptr the memory to free.

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:
name the file which we want to test.
priv the privileges for which we're asking.

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:
a reference to the variable holding a previously allocated string (or NULL).
the new value of the string. the 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.

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:
ms the time to sleep in milliseconds.

static size_t xmog_util::strlen_u16 const unsigned short *  str  )  [static]
 

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

Parameters:
str the string whose length to take.
Returns:
the string length.

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:
dest pointer to the destination.
src pointer to the source.
len the maximum number of characters to copy.

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.

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:
strVal the string'ized form of the entry point.

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:
utf8 the input string.


The documentation for this class was generated from the following file:
Generated on Wed May 31 14:01:35 2006 for Shared Codemesh Runtime Library API Reference by  doxygen 1.4.1