Show / Hide Table of Contents

Class ArrayView<T>

Implementation of ISettableGridView<T> that uses a 1D array to store data.

Inheritance
Object
SettableGridViewBase<T>
ArrayView<T>
Implements
ISettableGridView<T>
IGridView<T>
ICloneable
IMatchable<ArrayView<T>>
Inherited Members
SettableGridViewBase<T>.Count
SettableGridViewBase<T>.Item[Int32, Int32]
SettableGridViewBase<T>.Item[Int32]
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class ArrayView<T> : SettableGridViewBase<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

| Improve this Doc View Source

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 existingArray.

| Improve this Doc View Source

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

| Improve this Doc View Source

Height

The height of the grid being represented.

Declaration
public override int Height { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.SettableGridViewBase<T>.Height
| Improve this Doc View Source

Item[Point]

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[Point pos] { get; set; }
Parameters
Type Name Description
Point pos

Location to get/set the value for.

Property Value
Type Description
T

The "value" associated with the provided location.

Overrides
SadRogue.Primitives.GridViews.SettableGridViewBase<T>.Item[SadRogue.Primitives.Point]
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.

| Improve this Doc View Source

Width

The width of the grid being represented.

Declaration
public override int Width { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.SettableGridViewBase<T>.Width

Methods

| Improve this Doc View Source

Clear()

Sets each element in the ArrayView to the default for type T.

Declaration
public void Clear()
| Improve this Doc View Source

Clone()

Performs deep copy of array view.

Declaration
public object Clone()
Returns
Type Description
Object

The cloned ArrayView.

| Improve this Doc View Source

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> with a reference to the same underlying array, false otherwise.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

Overrides
Object.ToString()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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[]

Implements

ISettableGridView<T>
IGridView<T>
System.ICloneable
IMatchable<T>

Extension Methods

GridViewExtensions.ApplyOverlay<T>(ISettableGridView<T>, IGridView<T>)
GridViewExtensions.ApplyOverlay<T>(ISettableGridView<T>, Func<Point, T>)
GridViewExtensions.Bounds<T>(IGridView<T>)
GridViewExtensions.Contains<T>(IGridView<T>, Int32, Int32)
GridViewExtensions.Contains<T>(IGridView<T>, Point)
GridViewExtensions.ExtendToString<T>(IGridView<T>, String, String, Func<T, String>, String, String, String, String)
GridViewExtensions.ExtendToString<T>(IGridView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
GridViewExtensions.Fill<T>(ISettableGridView<T>, T)
GridViewExtensions.Positions<T>(IGridView<T>)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX