Torque2D Reference
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
_StringTable Class Reference

#include <stringTable.h>

Public Member Functions

StringTableEntry insert (const char *string, bool caseSens=false)
 
StringTableEntry insertn (const char *string, S32 len, bool caseSens=false)
 
StringTableEntry lookup (const char *string, bool caseSens=false)
 
StringTableEntry lookupn (const char *string, S32 len, bool caseSens=false)
 
void resize (const U32 newSize)
 

Static Public Member Functions

static void create ()
 
static void destroy ()
 
static U32 hashString (const char *in_pString)
 Hash a string into a U32. More...
 
static U32 hashStringn (const char *in_pString, S32 len)
 Hash a string of given length into a U32. More...
 

Static Public Attributes

static StringTableEntry EmptyString
 Empty string. More...
 

Implementation details

static const U32 csm_stInitSize = 29
 
 _StringTable ()
 
 ~_StringTable ()
 

Detailed Description

A global table for the hashing and tracking of strings.

Only one _StringTable is ever instantiated in Torque. It is accessible via the global variable StringTable.

StringTable is used to manage strings in Torque. It performs the following tasks:

// Adding a string to the StringTable.
StringTableEntry mRoot;
mRoot = StringTable->insert(root);
// Looking up a string in the StringTable.
StringTableEntry stName = StringTable->lookupn(name, len);
// Comparing two strings in the StringTable (see below).
if(mRoot == stName) Con::printf("These strings are equal!");

But why is this useful, you ask? Because every string that's run through the StringTable is stored once and only once, every string has one and only one pointer mapped to it. As a pointer is an integer value (usually an unsigned int), so we can do several neat things:

The scripting engine and the resource manager are the primary users of the StringTable.

Note
Be aware that the StringTable NEVER DEALLOCATES memory, so be careful when you add strings to it. If you carelessly add many strings, you will end up wasting space.

Constructor & Destructor Documentation

_StringTable ( )
protected
~_StringTable ( )
protected

Member Function Documentation

void create ( )
static

Initialize StringTable.

This is called at program start to initialize the StringTable global.

void destroy ( )
static

Destroy the StringTable

This is called at program end to destroy the StringTable global.

U32 hashString ( const char *  in_pString)
static

Hash a string into a U32.

U32 hashStringn ( const char *  in_pString,
S32  len 
)
static

Hash a string of given length into a U32.

StringTableEntry insert ( const char *  string,
bool  caseSens = false 
)

Get a pointer from the string table, adding the string to the table if it was not already present.

Parameters
stringString to check in the table (and add).
caseSensDetermines whether case matters.
StringTableEntry insertn ( const char *  string,
S32  len,
bool  caseSens = false 
)

Get a pointer from the string table, adding the string to the table if it was not already present.

Parameters
stringString to check in the table (and add).
lenLength of the string in bytes.
caseSensDetermines whether case matters.
StringTableEntry lookup ( const char *  string,
bool  caseSens = false 
)

Get a pointer from the string table, NOT adding the string to the table if it was not already present.

Parameters
stringString to check in the table (but not add).
caseSensDetermines whether case matters.
StringTableEntry lookupn ( const char *  string,
S32  len,
bool  caseSens = false 
)

Get a pointer from the string table, NOT adding the string to the table if it was not already present.

Parameters
stringString to check in the table (but not add).
lenLength of string in bytes.
caseSensDetermines whether case matters.
void resize ( const U32  newSize)

Resize the StringTable to be able to hold newSize items. This is called automatically by the StringTable when the table is full past a certain threshhold.

Parameters
newSizeNumber of new items to allocate space for.

Member Data Documentation

const U32 csm_stInitSize = 29
staticprotected
StringTableEntry EmptyString
static

Empty string.


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