Class NativeArrayChunkedDataLayer<TItem>
Base class for data layers that use NativeArray{T} as a data storage and track changes per chunk.
Inherited Members
Namespace: Fwt.Core.DataLayers
Assembly: fwt.core.dll
Syntax
public abstract class NativeArrayChunkedDataLayer<TItem> : ChunkedDataLayer, IDisposable, ICommitChanges, IListDataLayer<TItem> where TItem : unmanaged
Type Parameters
| Name | Description |
|---|---|
| TItem | type of item in data layer |
Fields
DefaultValue
When the data layer is resized, new cells will be filled with this value.
Declaration
public TItem DefaultValue
Field Value
| Type | Description |
|---|---|
| TItem |
_data
Declaration
protected NativeArray<TItem> _data
Field Value
| Type | Description |
|---|---|
| NativeArray<TItem> |
Properties
Data
Declaration
public NativeArray<TItem> Data { get; }
Property Value
| Type | Description |
|---|---|
| NativeArray<TItem> |
Length
Returns the number of items in the layer.
Declaration
public override int Length { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
Deserialize(BinaryReader)
Deserializes data from the specified binary reader into the current instance.
Declaration
public virtual bool Deserialize(BinaryReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryReader | reader | The binary reader from which to read the serialized data. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the data was successfully deserialized; otherwise, false. |
Dispose()
Disposes the layer and calls DisposeAllItems() under the hood
Declaration
public override void Dispose()
Overrides
DisposeAllItems()
Disposes all items in the layer. Called on Dispose() if IsDisposableItems is true.
Declaration
public override void DisposeAllItems()
Overrides
DisposeDataItem(TItem)
Declaration
protected virtual void DisposeDataItem(TItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| TItem | item |
DisposeExcessItems(int)
Declaration
public virtual void DisposeExcessItems(int layerSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize |
GetData(int)
Returns the data at the specified index.
Declaration
public virtual TItem GetData(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index to get data at |
Returns
| Type | Description |
|---|---|
| TItem | data in a cell with provided index |
Init(int)
Initializes/Reinitializes the layer with a size of the layer (cells count) and a size of the chunks.
Declaration
public override void Init(int layerSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize | Amount of items (cells) in the data layer |
Overrides
Serialize(BinaryWriter)
Serializes the internal data to the specified binary writer.
Declaration
public virtual bool Serialize(BinaryWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryWriter | writer | The binary writer to which the data will be serialized. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the data was successfully serialized; otherwise, false. |
Remarks
Serialization will not occur if the writer is null or if the internal data is not initialized.
SetData(int, TItem)
Sets the data at the specified index. Marks affected chunk as dirty.
Declaration
public virtual bool SetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index of the cell to put data into |
| TItem | data | data to put into the cell with provided index |
Returns
| Type | Description |
|---|---|
| bool | true if value was set (not out of the bounds) |
TryGetData(int, out TItem)
Tries to get the data at the specified index. if index is out of the bounds, returns false and data is set to default value.
Declaration
public virtual bool TryGetData(int index, out TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index of cell to get data from |
| TItem | data | filled with default value if index is out of bounds or contains data from cell with requested index |
Returns
| Type | Description |
|---|---|
| bool |
TrySetData(int, TItem)
Tries to set the data at the specified index. If index is out of the bounds, returns false.
Declaration
public bool TrySetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index of cell to set data into |
| TItem | data | data to put into a cell with provided index |
Returns
| Type | Description |
|---|---|
| bool | true if value was set |