SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
SLNet::StringTable Class Reference

Writes a string index, instead of the whole string. More...

`#include <slikenet/StringTable.h>`

## Public Member Functions

| ~StringTable ()
void | AddString (const char *str, bool copyString)
void | EncodeString (const char *input, int maxCharsToWrite, SLNet::BitStream *output)
bool | DecodeString (char *output, int maxCharsToWrite, SLNet::BitStream *input)
| StringTable ()
| Private Constructor.

## Static Public Member Functions

static StringTable * | Instance (void)
static void | AddReference (void)
| Used so I can allocate and deallocate this singleton at runtime.
static void | RemoveReference (void)
| Used so I can allocate and deallocate this singleton at runtime.

## Protected Member Functions

void | LogStringNotFound (const char *strName)

## Protected Attributes

DataStructures::OrderedList < char *, StrAndBool, StrAndBoolComp > | orderedStringList

## Static Protected Attributes

static StringTable * | instance =0
| Singleton instance.
static int | referenceCount =0

## Detailed Description

Writes a string index, instead of the whole string.

This is an even more efficient alternative to StringCompressor in that it writes a single byte from a lookup table and only does compression.
if the string does not already exist in the table.
All string tables must match on all systems - hence you must add all the strings in the same order on all systems.
Furthermore, this must be done before sending packets that use this class, since the strings are ordered for fast lookup. Adding after that time would mess up all the indices so don't do it.
Don't use this class to write strings which were not previously registered with AddString, since you just waste bandwidth then. Use StringCompressor instead.

Definition at line 55 of file StringTable.h.

## Constructor & Destructor Documentation

StringTable::~StringTable | ( |  | ) |

Definition at line 40 of file StringTable.cpp.

References _FILE_AND_LINE_, orderedStringList, rakFree_Ex, and DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Size().

StringTable::StringTable | ( |  | ) |

Private Constructor.

Definition at line 35 of file StringTable.cpp.

## Member Function Documentation

void StringTable::AddReference | ( | void |  | ) |

static

Used so I can allocate and deallocate this singleton at runtime.

Definition at line 50 of file StringTable.cpp.

References _FILE_AND_LINE_, instance, and referenceCount.

Referenced by SLNet::RakPeer::RakPeer().

void StringTable::AddString | ( | const char * | str,
|  | bool | copyString
| ) |  |

Add a string to the string table.

Parameters

  [in] | str | The string to add to the string table
  [in] | copyString | true to make a copy of the passed string (takes more memory), false to not do so (if your string is in static memory).

Definition at line 76 of file StringTable.cpp.

References _FILE_AND_LINE_, StrAndBool::b, DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Insert(), orderedStringList, RakAssert, rakMalloc_Ex, DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Size(), and StrAndBool::str.

bool StringTable::DecodeString | ( | char * | output,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | input
| ) |  |

Writes input to output, uncompressed. Takes care of the null terminator for you. Relies on the StringCompressor class, which is automatically reference counted in the constructor and destructor in RakPeer. You can call the reference counting functions yourself if you wish too.

Parameters

  [out] | output | A block of bytes to receive the output
  [in] | maxCharsToWrite | Size, in bytes, of output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated.
  [in] | input | The bitstream containing the compressed string

Definition at line 116 of file StringTable.cpp.

References SLNet::StringCompressor::DecodeString(), SLNet::StringCompressor::Instance(), orderedStringList, RakAssert, SLNet::BitStream::Read(), and DataStructures::OrderedList< key_type, data_type, default_comparison_function >::Size().

void StringTable::EncodeString | ( | const char * | input,
|  | int | maxCharsToWrite,
|  | SLNet::BitStream * | output
| ) |  |

Writes input to output, compressed. Takes care of the null terminator for you. Relies on the StringCompressor class, which is automatically reference counted in the constructor and destructor in RakPeer. You can call the reference counting functions yourself if you wish too.

Parameters

  [in] | input | Pointer to an ASCII string
  [in] | maxCharsToWrite | The size of input
  [out] | output | The bitstream to write the compressed string to

Definition at line 97 of file StringTable.cpp.

References SLNet::StringCompressor::EncodeString(), DataStructures::OrderedList< key_type, data_type, default_comparison_function >::GetIndexFromKey(), SLNet::StringCompressor::Instance(), LogStringNotFound(), orderedStringList, and SLNet::BitStream::Write().

StringTable * StringTable::Instance | ( | void |  | ) |

static

static function because only static functions can access static members The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself.

Returns
  the unique instance of the StringTable

Definition at line 71 of file StringTable.cpp.

References instance.

void StringTable::LogStringNotFound | ( | const char * | strName | ) |

protected

Called when you mess up and send a string using this class that was not registered with AddString

Parameters

  [in] | maxCharsToWrite | Size, in bytes, of output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated.

Definition at line 150 of file StringTable.cpp.

References RAKNET_DEBUG_PRINTF.

Referenced by EncodeString().

void StringTable::RemoveReference | ( | void |  | ) |

static

Used so I can allocate and deallocate this singleton at runtime.

Definition at line 57 of file StringTable.cpp.

References _FILE_AND_LINE_, instance, SLNet::OP_DELETE(), RakAssert, and referenceCount.

Referenced by SLNet::RakPeer::~RakPeer().

## Member Data Documentation

StringTable * StringTable::instance =0

staticprotected

Singleton instance.

Definition at line 101 of file StringTable.h.

Referenced by AddReference(), Instance(), and RemoveReference().

DataStructures::OrderedList<char *, StrAndBool, StrAndBoolComp> SLNet::StringTable::orderedStringList

protected

Definition at line 104 of file StringTable.h.

Referenced by AddString(), DecodeString(), EncodeString(), and ~StringTable().

int StringTable::referenceCount =0

staticprotected

Definition at line 102 of file StringTable.h.

Referenced by AddReference(), and RemoveReference().

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

- Source/include/slikenet/StringTable.h
- Source/src/StringTable.cpp