Photon Server API Documentation v5.0RC1

Public Member Functions | Protected Member Functions | Properties | List of all members
ExitGames.Threading.SimpleBaseFactory< TKey, TValue > Class Template Referenceabstract

A base class for a simple factory using a ReaderWriterLockSlim. More...

Inheritance diagram for ExitGames.Threading.SimpleBaseFactory< TKey, TValue >:

Public Member Functions

bool Add (TKey key, TValue value)
 Adds a kay-value pair. More...
 
bool Exists (TKey key, out TValue value)
 Gets the value associated with the specified key. More...
 
TValue Get (TKey key)
 Gets the value associated with the specified key. If the key does not exist in the dictionary a value is loaded with the CreateItem method. More...
 
bool Remove (TKey key)
 Removes the value with the specified key. More...
 
void Reset ()
 Calls DisposeItem for each item and clears the dictionary. More...
 
void Dispose ()
 Releases all resources used by the current instance. More...
 

Protected Member Functions

abstract TValue CreateItem (TKey key)
 This method creates / loads a value for the key. More...
 
virtual void Dispose (bool disposing)
 Releases all resources used by the current instance. More...
 
abstract void DisposeItem (TKey key, TValue value)
 Called when a key-value pair is removed. More...
 

Properties

Dictionary< TKey, TValue > Items [get]
 Gets a reference to the underlying dictionary that contains all existing instances. More...
 
ReaderWriterLockSlim ReaderWriterLock [get]
 Gets the used ReaderWriterLockSlim. More...
 

Detailed Description

A base class for a simple factory using a ReaderWriterLockSlim.

Template Parameters
TKeyThe type of the key.
TValueThe type of the value.

Member Function Documentation

◆ Add()

bool ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Add ( TKey  key,
TValue  value 
)
inline

Adds a kay-value pair.

Parameters
keyThe key.
valueThe value.
Returns
True on success, false if the key already exists.

◆ CreateItem()

abstract TValue ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.CreateItem ( TKey  key)
protectedpure virtual

This method creates / loads a value for the key.

Parameters
keyThe key.
Returns
The value.

◆ Dispose() [1/2]

void ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Dispose ( )
inline

Releases all resources used by the current instance.

◆ Dispose() [2/2]

virtual void ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Dispose ( bool  disposing)
inlineprotectedvirtual

Releases all resources used by the current instance.

Parameters
disposingTrue if called from Dispose().

◆ DisposeItem()

abstract void ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.DisposeItem ( TKey  key,
TValue  value 
)
protectedpure virtual

Called when a key-value pair is removed.

Parameters
keyThe removed key.
valueThe removed value.

◆ Exists()

bool ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Exists ( TKey  key,
out TValue  value 
)
inline

Gets the value associated with the specified key.

Parameters
keyThe key of the value to get.
valueWhen this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
True if an element with the specified key was found; otherwise, false.
Exceptions
ArgumentNullExceptionkey is null.

◆ Get()

TValue ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Get ( TKey  key)
inline

Gets the value associated with the specified key. If the key does not exist in the dictionary a value is loaded with the CreateItem method.

Parameters
keyThe key of the value to get.
Returns
The value.

◆ Remove()

bool ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Remove ( TKey  key)
inline

Removes the value with the specified key.

Parameters
keyThe key of the element to remove.
Returns
True if the element is successfully found and removed; otherwise, false. This method returns false if key is not found.

◆ Reset()

void ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Reset ( )
inline

Calls DisposeItem for each item and clears the dictionary.

Property Documentation

◆ Items

Dictionary<TKey, TValue> ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.Items
getprotected

Gets a reference to the underlying dictionary that contains all existing instances.

Access to this dictionary needs to be syncronized with ReadLock or WriteLock.

◆ ReaderWriterLock

ReaderWriterLockSlim ExitGames.Threading.SimpleBaseFactory< TKey, TValue >.ReaderWriterLock
getprotected

Gets the used ReaderWriterLockSlim.