Photon Server API
Public Member Functions | Protected Member Functions | Properties | List of all members
ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue > Class Template Reference

This class is used to create instances that are unique per key. More...

Public Member Functions

 UnsynchronizedSingletonFactory (CreateMethodDelegate< TKey, TValue > defaultCreateMethod)
 Initializes a new instance of the UnsynchronizedSingletonFactory<TKey,TValue> class. More...
 
virtual bool Add (TKey key, TValue value)
 Adds a new value if there is none for the same key. More...
 
void ForAll (Action< TValue > action)
 This method iterates over a copy of Instances and executes the action on each item. More...
 
TResult ForAll< TResult > (Func< TValue, TResult > selector, Func< TResult, TResult, TResult > aggregateFunction, TResult seed)
 This method iterates over a copy of Instances. The selector parameter selects a value of each instance. These values are combined with the aggregateFunction . More...
 
virtual TValue Get (TKey key, CreateMethodDelegate< TKey, TValue > createMethod)
 Gets an existing value for a key or creates a new one. More...
 
TValue Get (TKey key)
 Gets an existing value for a key or creates a new one with the default CreateMethod. More...
 
virtual bool Remove (TKey key)
 Removes a value from the Instances. More...
 
virtual bool TryGet (TKey key, out TValue value)
 Tries to get an existing value for the key. More...
 

Protected Member Functions

virtual void DoAdd (TKey key, TValue value)
 Adds a value to the Instances. This method is called from Add and Get. More...
 

Properties

int Count [get]
 Gets the number of existing instances. More...
 
CreateMethodDelegate< TKey, TValue > CreateMethod [get, set]
 Gets or sets the default function that creates new instances. More...
 
Dictionary< TKey, TValue > Instances [get]
 Gets a reference to the underlying dictionary that contains all existing instances. More...
 

Detailed Description

This class is used to create instances that are unique per key.

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

Instance members are not thread safe. For multi-threaded environments use the SynchronizedSingletonFactory<TKey, TValue>.

Constructor & Destructor Documentation

ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.UnsynchronizedSingletonFactory ( CreateMethodDelegate< TKey, TValue >  defaultCreateMethod)
inline

Initializes a new instance of the UnsynchronizedSingletonFactory<TKey,TValue> class.

Parameters
defaultCreateMethodThe default function that creates new instances.

Member Function Documentation

virtual bool ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.Add ( TKey  key,
TValue  value 
)
inlinevirtual

Adds a new value if there is none for the same key.

Parameters
keyThe key.
valueThe value.
Returns
True if the value has been added. False if another value for this key has already been present.
virtual void ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.DoAdd ( TKey  key,
TValue  value 
)
inlineprotectedvirtual

Adds a value to the Instances. This method is called from Add and Get.

Parameters
keyThe key.
valueThe value.
void ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.ForAll ( Action< TValue >  action)
inline

This method iterates over a copy of Instances and executes the action on each item.

Parameters
actionThe action.
TResult ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.ForAll< TResult > ( Func< TValue, TResult >  selector,
Func< TResult, TResult, TResult >  aggregateFunction,
TResult  seed 
)
inline

This method iterates over a copy of Instances. The selector parameter selects a value of each instance. These values are combined with the aggregateFunction .

Parameters
selectorThe action that maps a value to each instance.
aggregateFunctionThe function that combines all selector results.
seedThe result value to start with.
Template Parameters
TResultThe type of the result value.
Returns
An aggregegated value from all instances.
virtual TValue ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.Get ( TKey  key,
CreateMethodDelegate< TKey, TValue >  createMethod 
)
inlinevirtual

Gets an existing value for a key or creates a new one.

Parameters
keyThe key.
createMethodThe method that creates a new value if the key has not been added yet.
Returns
The value for the key.
TValue ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.Get ( TKey  key)
inline

Gets an existing value for a key or creates a new one with the default CreateMethod.

Parameters
keyThe key.
Returns
The value for the key.
virtual bool ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.Remove ( TKey  key)
inlinevirtual

Removes a value from the Instances.

Parameters
keyThe key.
Returns
True if key was found and removed, otherwise false.
virtual bool ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.TryGet ( TKey  key,
out TValue  value 
)
inlinevirtual

Tries to get an existing value for the key.

Parameters
keyThe key.
valueThe value.
Returns
True if a value was found, otherwise false.

Property Documentation

Gets the number of existing instances.

CreateMethodDelegate<TKey, TValue> ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.CreateMethod
getset

Gets or sets the default function that creates new instances.

Dictionary<TKey, TValue> ExitGames.Threading.UnsynchronizedSingletonFactory< TKey, TValue >.Instances
getprotected

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