ADTF  3.18.2
cStringTable

String table. More...

Public Member Functions

 cStringTable ()
 Default constructor.
 
virtual ~cStringTable ()
 Destructor.
 
tResult Load (const tChar *strFilename)
 Loads a string table from a file. More...
 
tResult LoadFromString (const tChar *strTable)
 Initializes the string table from a string. More...
 
tResult Free ()
 Frees all allocated resources. More...
 
cStringGet (const tChar *strId)
 Returns the value assigned to a string. More...
 
cString Format (const tChar *strId,...)
 Printf-style formating. More...
 
tInt32 GetItemCount () const
 This function returns the number of items the table contains. More...
 
cStringoperator[] (const cString &strKey)
 This function retrieves a string value from the list. More...
 
cStringoperator[] (tInt32 nIdx)
 Use this function to access single elements of the table. More...
 
tBool IsEmpty () const
 This function checks if the string table object is empty. More...
 

Static Public Member Functions

static cStringTableGetGlobal ()
 Returns the global table if available. More...
 

Protected Attributes

cStringMap m_mapStrings
 Internally used string map.
 

Static Protected Attributes

static cStringTablem_pGlobalInstance
 Pointer to global string table.
 

Detailed Description

String table.

Represents pairs of strings.

Definition at line 18 of file stringtable.h.

Member Function Documentation

◆ Format()

cString Format ( const tChar strId,
  ... 
)

Printf-style formating.

Parameters
strId[in] The id string which value string should be used as format string.
Returns
The formatted string.

◆ Free()

tResult Free ( )

Frees all allocated resources.

Returns
Always returns ERR_NOERROR

◆ Get()

cString& Get ( const tChar strId)

Returns the value assigned to a string.

Parameters
strId[in] The key string.
Returns
The value assigned to the string, or "#resource not found#" if the keystring is not found.

◆ GetGlobal()

static cStringTable* GetGlobal ( )
static

Returns the global table if available.

Please note that this is not an actual singleton. This just returns a pointer to the first instance created of cStringTable. If this instance is deleted, the global table is not available until another table is created and takes its place.

Note
This is NOT a singleton pattern implementation. It is your resposibility to make sure your global table is instantiated a) as the first table b) as long as you need it Use with care!
Returns
pointer to global table if available, else nullptr.

◆ GetItemCount()

tInt32 GetItemCount ( ) const

This function returns the number of items the table contains.

Returns
Returns the number of table items.

◆ IsEmpty()

tBool IsEmpty ( ) const

This function checks if the string table object is empty.

Returns
tBool value that is true, if the string table object has no elements.

◆ Load()

tResult Load ( const tChar strFilename)

Loads a string table from a file.

The file has to be formated with name=value pairs seperated by newlines. Comments begin with #, ; or //.

Parameters
strFilename[in] The filename.
Returns
ERR_FAILED if the file could not be read.
ERR_POINTER if strFilename is nullptr

◆ LoadFromString()

tResult LoadFromString ( const tChar strTable)

Initializes the string table from a string.

The string has to be formated with name=value pairs seperated by newlines. Comments begin with #, ; or // If you want either key or value to contain whitespace characters, escape them. This function will not return an error even if some pairs could not be parsed or look like they were parsed incorrectly. Only an invalid argument will cause an error. Neither key nor value can be empty. If the key is empyt, side effects may happen ( see note )

Note
a string like "bla=\nblub=bingo" will create the pair<bla,blub=bingo>
Parameters
strTable[in] The input string.
Returns
ERR_NOERROR if all went well
ERR_INVAILD_ARG if first character is '\0' or strlen of strTable is 0
ERR_POINTER if strTable is nullptr

◆ operator[]() [1/2]

cString& operator[] ( const cString strKey)

This function retrieves a string value from the list.

Parameters
strKey[in] Key value of string to be fetched.
Returns
The function creates a cString object that is initialized with the contents of the referenced table item.

◆ operator[]() [2/2]

cString& operator[] ( tInt32  nIdx)

Use this function to access single elements of the table.

Parameters
nIdx[in] Zero-based index of table item.
Returns
Reference to string table element.