Photon C++ Client API  5.0.7.3
Classes | Public Member Functions | List of all members
Dictionary< EKeyType, EValueType > Class Template Reference
Inheritance diagram for Dictionary< EKeyType, EValueType >:
Inheritance graph
[legend]
Collaboration diagram for Dictionary< EKeyType, EValueType >:
Collaboration graph
[legend]

Public Member Functions

 Dictionary (void)
 
virtual ~Dictionary (void)
 
 Dictionary (const Dictionary< EKeyType, EValueType > &toCopy)
 
virtual Dictionary< EKeyType, EValueType > & operator= (const DictionaryBase &toCopy)
 
virtual Dictionary< EKeyType, EValueType > & operator= (const Dictionary< EKeyType, EValueType > &toCopy)
 
virtual bool operator== (const DictionaryBase &toCompare) const
 
virtual bool operator!= (const DictionaryBase &toCompare) const
 
const EValueType & operator[] (unsigned int index) const
 
EValueType & operator[] (unsigned int index)
 
virtual const nByte * getKeyTypes (void) const
 
virtual const nByte * getValueTypes (void) const
 
virtual const unsigned int * getValueDimensions (void) const
 
virtual nByte getValueCustomType (void) const
 
virtual void put (const DictionaryBase &src)
 
void put (const EKeyType &key, const EValueType &val)
 
void put (const EKeyType &key)
 
void put (const EKeyType &key, const EValueType pVal, int size)
 
void put (const EKeyType &key, const EValueType pVal, const int *sizes)
 
void remove (const EKeyType &key)
 
bool contains (const EKeyType &key) const
 
virtual JString typeToString (void) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const
 
const EValueType * getValue (const EKeyType &key) const
 
EValueType * getValue (const EKeyType &key)
 
JVector< EKeyType > getKeys (void) const
 
virtual JString typeToString (void) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from DictionaryBase
virtual ~DictionaryBase (void)
 
 DictionaryBase (const DictionaryBase &toCopy)
 
template<typename FKeyType >
const int * getValueSizes (const FKeyType &key) const
 
JString typeToString (void) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from GenericAssociativeContainerBase< DictionaryBase, Hashtable, Object >
virtual ~GenericAssociativeContainerBase (void)=0
 
virtual void removeAt (unsigned int index)
 
virtual void removeAllElements (void)
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const =0
 
JString toString (bool withTypes=false) const
 
virtual const HashtablegetHashtable (void) const
 
virtual unsigned int getSize (void) const
 
- Public Member Functions inherited from Base
virtual ~Base (void)=0
 
- Public Member Functions inherited from LoggingBase< Base >
virtual ~LoggingBase (void)=0
 
- Public Member Functions inherited from ToString
virtual ~ToString (void)
 
JString toString (bool withTypes=false) const
 

Additional Inherited Members

- Static Public Member Functions inherited from LoggingBase< Base >
static void setListener (const BaseListener *pBaseListener)
 
static int getDebugOutputLevel (void)
 
static bool setDebugOutputLevel (int debugLevel)
 
static const LogFormatOptionsgetLogFormatOptions (void)
 
static void setLogFormatOptions (const LogFormatOptions &options)
 

Detailed Description

template<typename EKeyType, typename EValueType>
class ExitGames::Common::Dictionary< EKeyType, EValueType >

The Dictionary class template together with the Hashtable class is one of the two main container classes for objects to be transmitted over Photon when using the C++ Client.

This class implements the well-known concept of a container structure storing an arbitrary number of key/value-pairs.

In contrast to a Hashtable, the types of both the keys and also the values in a Dictionary have to be the same for all entries. This takes flexibility, but it also improves type safety and means, that the type infos only have to be stored twice for the whole Dictionary (once for the key and once for the value), while in a Hashtable they have to be stored twice per entry. Therefor with Dictionaries transferring the same amount of key-value pairs will cause less traffic than with Hashtables.

Please have a look at the Table of Datatypes for a list of types, that are supported as keys and as values.

Please refer to the documentation for put() and getValue() to see how to store and access data in a Dictionary.

See also
put(), getValue(), KeyObject, ValueObject, Hashtable, DictionaryBase

Constructor & Destructor Documentation

◆ Dictionary() [1/2]

Dictionary ( void  )

Constructor: Creates an empty instance.

◆ ~Dictionary()

~Dictionary ( void  )
virtual

Destructor.

◆ Dictionary() [2/2]

Dictionary ( const Dictionary< EKeyType, EValueType > &  toCopy)

Copy-Constructor: Creates a deep copy of the argument.

Parameters
toCopyThe instance to copy.

Member Function Documentation

◆ operator=() [1/2]

Dictionary< EKeyType, EValueType > & operator= ( const DictionaryBase toCopy)
virtual

operator=. Makes a deep copy of its right operand into its left operand. This overwrites old data in the left operand.

Reimplemented from DictionaryBase.

◆ operator=() [2/2]

Dictionary< EKeyType, EValueType > & operator= ( const Dictionary< EKeyType, EValueType > &  toCopy)
virtual

operator=. Makes a deep copy of its right operand into its left operand. This overwrites old data in the left operand.

◆ operator==()

bool operator== ( const DictionaryBase toCompare) const
virtual

operator==.

Returns
true, if both operands are equal, false otherwise.

Two instances are considered equal if they each hold the same number of entries and, for a given key, the corresponding values equal each other.

Two values are considered equal to each other, if instances of class OT, that are holding them as payloads, equal each other.

See also
OT::operator==()

Reimplemented from GenericAssociativeContainerBase< DictionaryBase, Hashtable, Object >.

◆ operator!=()

bool operator!= ( const DictionaryBase toCompare) const
virtual

operator!=.

Returns
false, if operator==() would return true, true otherwise.

Reimplemented from GenericAssociativeContainerBase< DictionaryBase, Hashtable, Object >.

◆ operator[]() [1/2]

const EValueType & operator[] ( unsigned int  index) const

operator[].

Accesses the value at the given index like in an array. This does not check for valid indexes and shows undefined behavior for invalid indexes

◆ operator[]() [2/2]

EValueType & operator[] ( unsigned int  index)

operator[].

Accesses the value at the given index like in an array. This does not check for valid indexes and shows undefined behavior for invalid indexes

◆ getKeyTypes()

const nByte * getKeyTypes ( void  ) const
virtual
Returns
an array, holding the type code for the key type of the Dictionary and type codes for the key types of potential nested Dictionaries.

Only index 0 of the returned array is guaranteed to be valid. The existence of elements at other indices depends on the value of the element in the array returned by getValueTypes() at the previous index in the following way: Only when getValueTypes()[i] == TypeCode::DICTIONARY, then getKeyTypes()[i+1] will be valid.

Type information for nested Dictionaries will be stored like in the following example: Dictionary<int, Dictionary<short, float**>*> This is a Dictionary, with the key type being int and the value type being a 1D array of type Dictionary<short, float**>, so that all values are Dictionaries, which keys are shorts and which values are 2D arrays of float. This function's return value in this example will hold the values TypeCode::INTEGER at index 0 and TypeCode::SHORT at index 1.

The codes returned by this function match the ones, that are stored in member variable "typename" of class template Helpers::ConfirmAllowedKey's specializations. Only the types, for which specializations of that template exist, are valid Dictionary keys.

Reimplemented from DictionaryBase.

◆ getValueTypes()

const nByte * getValueTypes ( void  ) const
virtual
Returns
an array, holding the type code for the value type of the Dictionary and type codes for the value types of potential nested Dictionaries.

Only index 0 of the returned array is guaranteed to be valid. The existence of elements at other indices depends on the value of the element at the previous index in the following way: Only when getValueTypes()[i] == TypeCode::DICTIONARY, then getValueTypes()[i+1] will be valid.

Type information for nested Dictionaries will be stored like in the following example: Dictionary<int, Dictionary<short, float**>*> This is a Dictionary, with the key type being int and the value type being a 1D array of type Dictionary<short, float**>, so that all values are Dictionaries, which keys are shorts and which values are 2D arrays of float. This function's return value in this example will hold the values TypeCode::DICTIONARY at index 0 and TypeCode::FLOAT at index 1.

The codes returned by this function match the ones, that are stored in member variable "typename" of class template Helpers::ConfirmAllowed's specializations. Only the types, for which specializations of that template exist, are valid Dictionary values.

Reimplemented from DictionaryBase.

◆ getValueDimensions()

const unsigned int * getValueDimensions ( void  ) const
virtual
Returns
an array, holding the amount of array dimensions for the value type of the Dictionary and for the value types of potential nested Dictionaries.

Only index 0 of the returned array is guaranteed to be valid. The existence of elements at other indices depends on the value of the element in the array returned by getValueTypes() at the previous index in the following way: Only when getValueTypes()[i] == TypeCode::DICTIONARY, then getValueDimensions()[i+1] will be valid.

Type information for nested Dictionaries will be stored like in the following example: Dictionary<int, Dictionary<short, float**>*> This is a Dictionary, with the key type being int and the value type being a 1D array of type Dictionary<short, float**>, so that all array-elements are Dictionaries, which keys are shorts and which values are 2D arrays of float. This function's return value in this example will hold the value 1 (for 1D array) at index 0 and 2 (for 2D) at index 1. If a value type is no array, then this functions return value will contain 0 at the corresponding index.

Reimplemented from DictionaryBase.

◆ getValueCustomType()

nByte getValueCustomType ( void  ) const
virtual
Returns
the custom type code for the value type of the Dictionary

The returned value will be the custom type code, if the type at the last index of the array that is returned by getValueTypes() is TypeCode::CUSTOM (aka if the Dictionary (or in case of nested Dictionaries the most inner Dictionary) has a subclass of class CustomType as value type), otherwise it will will be 0.

Reimplemented from DictionaryBase.

◆ put() [1/5]

void put ( const DictionaryBase src)
virtual

Adds all pairs of a key and a corresponding value from the passed instance to the instance, on which it is called on. If a key is already existing, then its old value will be replaced with the new one.

Parameters
srcinstance, from which to add the content
Returns
nothing.

Reimplemented from GenericAssociativeContainerBase< DictionaryBase, Hashtable, Object >.

◆ put() [2/5]

void put ( const EKeyType &  key,
const EValueType &  val 
)

Adds a pair of a key and a corresponding value to the instance.

If the key is already existing, then it's old value will be replaced with the new one. Please have a look at the table of datatypes for a list of supported types for keys and values

Parameters
keythe key to add
valthe value to add

◆ put() [3/5]

void put ( const EKeyType &  key)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload adds an empty object as value for the provided key.

◆ put() [4/5]

void put ( const EKeyType &  key,
const EValueType  pVal,
int  size 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload accepts singledimensional arrays and NULL-pointers passed for parameter pVal. NULL pointers are only legal input, if size is 0

Parameters
keythe key to add
pValthe value array to add
sizethe size of the value array

◆ put() [5/5]

void put ( const EKeyType &  key,
const EValueType  pVal,
const int *  sizes 
)

◆ remove()

void remove ( const EKeyType &  key)

Deletes the specified key and the corresponding value, if found in the Hashtable.

Parameters
keyPointer to the key of the key/value-pair to remove.
See also
removeAt(), removeAllElements()

◆ contains()

bool contains ( const EKeyType &  key) const

Checks, whether the Hashtable contains a certain key.

Parameters
keyPointer to the key to look up.
Returns
true if the specified key was found, false otherwise.

◆ typeToString() [1/2]

JString typeToString ( void  ) const
virtual
Remarks
This function is intended for debugging purposes. For runtime type checking you should use RTTI's typeid() instead. Demangling and cutting off of namespaces will only happen on platforms, which offer a system functionality for demangling.
Returns
a string representation of the class name of the polymorphically correct runtime class of the instance, on which it is called on, after this class name has been demangled and eventual namespaces have been removed.

Reimplemented from ToString.

◆ toString() [1/3]

JString & toString ( JString retStr,
bool  withTypes = false 
) const
virtual
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

Reimplemented from DictionaryBase.

◆ getValue() [1/2]

const EValueType * getValue ( const EKeyType &  key) const

Returns a pointer to the corresponding value for a specified key.

Parameters
keyReference to the key to return the corresponding value for.
Returns
a pointer to the corresponding value if the Hashtable contains the specified key, NULL otherwise.
See also
put()

◆ getValue() [2/2]

EValueType * getValue ( const EKeyType &  key)

Returns a pointer to the corresponding value for a specified key.

Parameters
keyReference to the key to return the corresponding value for.
Returns
a pointer to the corresponding value if the Hashtable contains the specified key, NULL otherwise.
See also
put()

◆ getKeys()

JVector< EKeyType > getKeys ( void  ) const

Returns
a JVector holding all keys contained in the Hashtable.

◆ typeToString() [2/2]

JString typeToString
Remarks
This function is intended for debugging purposes. For runtime type checking you should use RTTI's typeid() instead. Demangling and cutting off of namespaces will only happen on platforms, which offer a system functionality for demangling.
Returns
a string representation of the class name of the polymorphically correct runtime class of the instance, on which it is called on, after this class name has been demangled and eventual namespaces have been removed.

◆ toString() [2/3]

toString
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

◆ toString() [3/3]

JString toString

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.
See also
JString