Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CStringManager Class Reference

This class keeps the string data for the entire process. More...

Collaboration diagram for CStringManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~CStringManager ()
 The CStringManager destructor simply calls the Destruct function.
char * RetrieveString (unsigned long number)
 The RetrieveString function returns a pointer to a string given an offset.
char * RetrieveString (unsigned long number) const
 The RetrieveString function (const version) returns a pointer to a string given an offset.
void AddStrings (const char *string, unsigned long length, unsigned long originaloffset)
 The AddStrings function takes a block of string data (one or more strings seperated by 0s) its length, and the original offset and adds that data to the string table.
void AddStrings (const char *string, unsigned long length)
 This version of AddStrings simply calls the 3 parameter version, passing the address of the string as its base offset.
void Destruct ()
 The Destruct function frees all memory associated with the object and cleans up the internal structure.
void Construct ()
 The Construct function sets up the internal structure of the CStringManager object.
void RemoveString (unsigned long number)
 This function removes a single string (not a block of string data).
unsigned long RetrieveOffset (const char *string) const
 The RetrieveOffset function finds the offset of a string in the table given a pointer.

Private Attributes

LongArray Originals
 keeps the original offsets in the string table, the one the main program is looking for
PointerArray NewAddresses
 keeps the addresses those string table offsets that are mapped to in memory
PointerArray Strings
 keeps the addresses of one or more strings, so that memory can be released on completion
char * laststringretrieved
 caches the last string that RetrieveString returned on for faster results
unsigned long lastoffsetlookedup
 caches the last offset that RetrieveString was called with for faster results

Detailed Description

This class keeps the string data for the entire process.

Usually an object of this class keeps one large memory block that holds multiple strings, seperated by 0 chars. However there is a possibility to add additional strings later, but this has not been well tested, use at your own risk.

See also:
CProcessData


Constructor & Destructor Documentation

CStringManager::~CStringManager  ) 
 

The CStringManager destructor simply calls the Destruct function.

See also:
CStringManager::Destruct()


Member Function Documentation

void CStringManager::AddStrings const char *  string,
unsigned long  length
 

This version of AddStrings simply calls the 3 parameter version, passing the address of the string as its base offset.

See also:
CStringManager::AddStrings(const char* string, unsigned long length, unsigned long originaloffset)

void CStringManager::AddStrings const char *  string,
unsigned long  length,
unsigned long  originaloffset
 

The AddStrings function takes a block of string data (one or more strings seperated by 0s) its length, and the original offset and adds that data to the string table.

The AddStrings function first makes a copy of the data to be added and stores that (so that if needed the data passed to it can be freed afterwards. The pointer to this new data is stored in the CStringManager::Strings member. Then the block of string data is looped though, and every non-0 charachter that follows on or more 0 charachter (including the first charachter if it is non-0) is treated a string within the block of string data that needs to be added. The address of that charachter is stored in CStringManager::NewAddresses and the distance of that charachter from the beggining of the block of data is added to the originaloffset parameter and stored in CStringManager::Originals. Most of the time originaloffset will be zero, resulting in the value stored in CStringManager::Originals being simply the distance of the beginning of a string to the block of data it is part of.

Parameters:
string the block of data which may contain multiple strings seperated by 0 charachters.
length the total size of the block of data
originaloffset a value that is combined with the position of the string within the block of data to save as its offset.

void CStringManager::Destruct  ) 
 

The Destruct function frees all memory associated with the object and cleans up the internal structure.

Every chunk of memory that the CStringManager Strings list is passed to the default memory manager to be freed. Thus freeing this memory yourself or is an error.

void CStringManager::RemoveString unsigned long  number  ) 
 

This function removes a single string (not a block of string data).

The function searches for a string with the same offset as the number passed in the CStringManager::Originals member. If its offset is found it is removed and the corresponding address in CStringManager::NewAddresses is removed. If the string with this offset cannot be found nothing happens. Note that this function does not actually free any memory.

Parameters:
number the offset of the string to be removed.

unsigned long CStringManager::RetrieveOffset const char *  string  )  const
 

The RetrieveOffset function finds the offset of a string in the table given a pointer.

This function searches throught he pointers found in the new CStringManager::NewAddresses array, comparing them to the passed string pointer using strcmp.

Parameters:
string the sequence of charachters to be found.
Returns:
the offset of the string as stored in CStringManager::Originals or 0xFFFFFFFF if not found.

char * CStringManager::RetrieveString unsigned long  number  )  const
 

The RetrieveString function (const version) returns a pointer to a string given an offset.

This function is passed the original offset of a string that is stored in the CStringManager object. Usually this offset will come from the offset of the desired string in the script's string table. If the offset is equal to the last offset looked up the stored result is returned. Otherwise the offset is looked up in the CStringManager::Originals member. The appropriate char pointer is returned from the value in CStringManager::NewAddresses at the same position. The stored results are not modified however.

Parameters:
number the offset of the string to be found.
Returns:
the pointer to the desired string, or NULL if it cannot be found.

char * CStringManager::RetrieveString unsigned long  number  ) 
 

The RetrieveString function returns a pointer to a string given an offset.

This function is passed the original offset of a string that is stored in the CStringManager object. Usually this offset will come from the offset of the desired string in the script's string table. If the offset is equal to the last offset looked up the stored result is returned. Otherwise the offset is looked up in the CStringManager::Originals member. The appropriate char pointer is returned from the value in CStringManager::NewAddresses at the same position. Also this new find offset and results replace the old stored ones mentioned earlier for fast look-up.

Parameters:
number the offset of the string to be found.
Returns:
the pointer to the desired string, or NULL if it cannot be found.


The documentation for this class was generated from the following files:
Generated on Sat Apr 16 16:31:09 2005 for Centum API by  doxygen 1.4.2