Collaboration diagram for CStringManager:
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 |
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.
|
The CStringManager destructor simply calls the Destruct function.
|
|
This version of AddStrings simply calls the 3 parameter version, passing the address of the string as its base offset.
|
|
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.
|
|
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. |
|
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.
|
|
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.
|
|
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.
|
|
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.
|