Class DictionaryDataLayer<TKey, TItem>
Base class for all data layers that use a dictionary as a data structure.
Inherited Members
Namespace: Fwt.Core.DataLayers
Assembly: fwt.core.dll
Syntax
public abstract class DictionaryDataLayer<TKey, TItem> : DataLayer, IDisposable, ICommitChanges where TKey : IEquatable<TItem>
Type Parameters
| Name | Description |
|---|---|
| TKey | type of the key in the underlying dictionary |
| TItem | type of the item to store as value in the underlying dictionary |
Fields
_data
Declaration
protected Dictionary<TKey, TItem> _data
Field Value
| Type | Description |
|---|---|
| Dictionary<TKey, TItem> |
Properties
Data
Container for the data of the layer
Declaration
public Dictionary<TKey, TItem> Data { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<TKey, TItem> |
Length
Returns the number of items in the layer.
Declaration
public override int Length { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
DisposeAllItems()
Disposes all items in the data layer by calling DisposeDataItem() for each item.
Declaration
public override void DisposeAllItems()
Overrides
DisposeDataItem(TItem)
Disposes the data item if it is IDisposable.
Declaration
protected virtual void DisposeDataItem(TItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| TItem | item |
GetData(TKey)
Returns the data item at the given key.
Declaration
public virtual TItem GetData(TKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | key to get data by |
Returns
| Type | Description |
|---|---|
| TItem | data found in the layer by provided key |
Init(int, Allocator)
Initializes/Reinitializes the data layer with a given size.
Declaration
public virtual void Init(int layerSize, Allocator allocator = Allocator.Persistent)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize | size of the data layer (cells count) |
| Allocator | allocator | allocator to create internal collections. Used in classes inherited from this data layer |
SetData(TKey, TItem)
Sets the data item at the given key.
Declaration
public virtual bool SetData(TKey key, TItem value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | key to put data under |
| TItem | value | data to put at the cell of provided key |
Returns
| Type | Description |
|---|---|
| bool |
TryGetData(TKey, out TItem)
Tries to get the data item at the given key. If nothing is found, returns false and sets the value to default.
Declaration
public virtual bool TryGetData(TKey key, out TItem value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | key to find data by |
| TItem | value | data from data layer by provided key or default if nothing found |
Returns
| Type | Description |
|---|---|
| bool | true if data was found, otherwise - false |
TrySetData(TKey, TItem)
Tries to set the data item at the given key.
Declaration
public virtual bool TrySetData(TKey key, TItem value)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | key to put data under |
| TItem | value | value to put under the provided key |
Returns
| Type | Description |
|---|---|
| bool | true if value was set |