Class ArrayDataLayer<TItem>
Base class for all data layers that use an array as a data container.
Inherited Members
Namespace: Fwt.Core.DataLayers
Assembly: fwt.core.dll
Syntax
public abstract class ArrayDataLayer<TItem> : DataLayer, IDisposable, ICommitChanges, IListDataLayer<TItem>
Type Parameters
| Name | Description |
|---|---|
| TItem | Item type to store in the data layer |
Fields
_data
Declaration
protected TItem[] _data
Field Value
| Type | Description |
|---|---|
| TItem[] |
Properties
Data
The data array that stores the items in the layer.
Declaration
public TItem[] Data { get; }
Property Value
| Type | Description |
|---|---|
| TItem[] |
Length
The length of the data layer.
Declaration
public override int Length { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
DisposeAllItems()
Disposes all items in the data layer. Calls DisposeDataItem(item) for each item in the data array.
Declaration
public override void DisposeAllItems()
Overrides
DisposeDataItem(TItem)
Disposes the provided item if it is IDisposable.
Declaration
protected virtual void DisposeDataItem(TItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| TItem | item |
DisposeExcessItems(int)
Disposes every item in the data layer that is beyond the specified layer size. Usually used when layer is resized and there was items in the data layer that are not needed anymore and IsDisposableItems == true.
Declaration
public virtual void DisposeExcessItems(int layerSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize |
GetData(int)
Gets the data at the specified index.
Declaration
public virtual TItem GetData(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index of cell to get data from |
Returns
| Type | Description |
|---|---|
| TItem | data from the cell at provided index |
Init(int, Allocator)
Initializes/Reinitializes the data layer with the specified size.
Declaration
public virtual void Init(int layerSize, Allocator allocator)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize | size of the data layer (cells count) |
| Allocator | allocator | allocator to create internal collections with (used in classes inherited from this data layer) |
SetData(int, TItem)
Sets the data to the cell at the specified index.
Declaration
public virtual bool SetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index of cell to put data into |
| TItem | data | data to put in a cell at provided index |
Returns
| Type | Description |
|---|---|
| bool |
TryGetData(int, out TItem)
Tries to get the data at the specified index. returns false if index is out of the bounds and data is set to default value.
Declaration
public virtual bool TryGetData(int index, out TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | cell index to get data from |
| TItem | data | found value if index is inside the bounds. Default value if index is out of bounds |
Returns
| Type | Description |
|---|---|
| bool |
TrySetData(int, TItem)
Tries to set the data at the specified index. Returns true if data was set. Returns false if index is out of the bounds.
Declaration
public virtual bool TrySetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | cell index to put data into |
| TItem | data | data to put in the cell at provided index |
Returns
| Type | Description |
|---|---|
| bool | true if data was set, otherwise - false |