Class ArrayView<T>
Implementation of ISettableGridView<T> that uses a 1D array to store data.
Inherited Members
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class ArrayView<T> : SettableGridView1DIndexBase<T>, ISettableGridView<T>, IGridView<T>, ICloneable, IMatchable<ArrayView<T>>
Type Parameters
Name | Description |
---|---|
T | The type of value being stored. |
Remarks
An ArrayView<T> can be implicitly converted to its underlying 1D array, which allows exposing that array to code that works with 1D arrays. Modifications in the array appear in the map view as well.
If you need a 2D array instead of 1D, then you should use ArrayView2D<T> instead.
Constructors
ArrayView(T[], Int32)
Constructor. Takes an existing 1D array to use as the underlying array, and the width of the 2D grid represented by that array.
Declaration
public ArrayView(T[] existingArray, int width)
Parameters
Type | Name | Description |
---|---|---|
T[] | existingArray | Existing 1D array to use as the underlying array. |
Int32 | width | The width of the 2D grid represented by |
ArrayView(Int32, Int32)
Constructor. Takes width and height of array to create.
Declaration
public ArrayView(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
Int32 | width | Width of array. |
Int32 | height | Height of array. |
Properties
Height
The height of the grid being represented.
Declaration
public override int Height { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
Item[Int32]
Interface designed to act as a standardized input/output format that defines minimal required data for algorithms that operate and make changes to a grid of some sort. For a concrete implementation to subclass for custom implementations, see SettableGridViewBase<T>.
Declaration
public override T this[int index1D] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index1D | 1D index of location to get/set the "value" for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the given location. |
Overrides
Remarks
See IGridView<T>. This interface serves the same purpose, but for cases when it is also necessary for an algorithm to be able to change the value at each location.
Like IGridView, a number of implementations of this interface to cover common needs are provided. For example, ArrayView<T> defines the interface such that the data is retrieved from and set to an array, and LambdaSettableGridView<T> defines the interface such that arbitrary callbacks are used to retrieve and set the data.
Width
The width of the grid being represented.
Declaration
public override int Width { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
Methods
Clear()
Sets every location within the grid view to the default value for the type.
Declaration
public override void Clear()
Overrides
Remarks
This function can sometimes be implemented more efficiently than Fill(default), so it is provided as an interface function to enable dispatching.
Remember the default value of a non-nullable type is null for reference types; so use with caution if your element type is non-nullable!
Clone()
Performs deep copy of array view.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
Object | The cloned ArrayView. |
Matches(ArrayView<T>)
Compares the current ArrayView to the one given.
Declaration
public bool Matches(ArrayView<T> other)
Parameters
Type | Name | Description |
---|---|---|
ArrayView<T> | other |
Returns
Type | Description |
---|---|
Boolean | True if the given ArrayView<T> references the same underlying array, false otherwise. |
ToArray()
Converts to 1D array, without copying the values. Typically using this method is unnecessary and you can use the implicit conversion defined for this type instead.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | The underlying ArrayView data as a 1D array. |
ToString()
Returns a string representation of the grid values.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string representation of the grid values. |
ToString(Func<T, String>)
Returns a string representation of the grid values, using elementStringifier
to determine what string represents each value.
Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type | Name | Description |
---|---|---|
Func<T, String> | elementStringifier | Function determining the string representation of each value. |
Returns
Type | Description |
---|---|
String | A string representation of the grid values. |
ToString(Int32, Func<T, String>)
Returns a string representation of the grid values using the given parameters.
Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | fieldSize | The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text. |
Func<T, String> | elementStringifier | Function to use to convert each value to a string. null defaults to the ToString function of type T. |
Returns
Type | Description |
---|---|
String | A string representation of the grid values. |
Remarks
Each element will have spaces added to cause it to take up exactly
fieldSize
characters, provided fieldSize
is less than the length of the value's string representation.
Operators
Implicit(ArrayView<T> to T[])
Allows implicit conversion to 1D array. Does not copy the underlying values.
Declaration
public static implicit operator T[](ArrayView<T> arrayView)
Parameters
Type | Name | Description |
---|---|---|
ArrayView<T> | arrayView | ArrayView to convert. |
Returns
Type | Description |
---|---|
T[] |