Show / Hide Table of Contents

Class DiffAwareGridView<T>

A grid view wrapper useful for recording diffs (change-sets) of changes to a grid view, and applying/removing those change-sets of values from the grid view. Only works with grid views of value types.

Inheritance
object
SettableGridViewBase<T>
DiffAwareGridView<T>
Implements
ISettableGridView<T>
IGridView<T>
Inherited Members
SettableGridViewBase<T>.Fill(T)
SettableGridViewBase<T>.Clear()
SettableGridViewBase<T>.Count
SettableGridViewBase<T>.this[int, int]
SettableGridViewBase<T>.this[int]
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public class DiffAwareGridView<T> : SettableGridViewBase<T>, ISettableGridView<T>, IGridView<T> where T : struct
Type Parameters
Name Description
T

Type of value in the grid view. Must be a value type.

Remarks

Generally, this class is useful with values types/primitive types wherein values are completely replaced when they are modified. It allows applying a series of change sets in forward or reverse order; and as such can be extremely useful for debugging or situations where you want to record intermediate states of an algorithm.

Constructors

View Source

DiffAwareGridView(ISettableGridView<T>, bool)

Constructs a diff-aware grid view that wraps around an existing grid view.

Declaration
public DiffAwareGridView(ISettableGridView<T> baseGrid, bool autoCompress = true)
Parameters
Type Name Description
ISettableGridView<T> baseGrid

The grid view whose changes are to be recorded in diffs.

bool autoCompress

Whether or not to automatically compress diffs when the currently applied diff is changed.

View Source

DiffAwareGridView(int, int, bool)

Constructs a diff-aware grid view, whose base grid will be a new ArrayView<T>.

Declaration
public DiffAwareGridView(int width, int height, bool autoCompress = true)
Parameters
Type Name Description
int width

Width of the base grid view that will be created.

int height

Height of the base grid view that will be created.

bool autoCompress

Whether or not to automatically compress diffs when the currently applied diff is changed.

Fields

View Source

AutoCompress

Whether or not to automatically compress diffs when the currently applied diff is changed.

Declaration
public bool AutoCompress
Field Value
Type Description
bool

Properties

View Source

BaseGrid

The grid view whose changes are being recorded in diffs.

Declaration
public IGridView<T> BaseGrid { get; }
Property Value
Type Description
IGridView<T>
View Source

CurrentDiffIndex

The index of the diff whose ending state is currently reflected in BaseGrid. Returns -1 if none of the diffs in the list have been applied (eg. the grid view is in the state it was in at the DiffAwareGridView<T>'s creation.

Declaration
public int CurrentDiffIndex { get; }
Property Value
Type Description
int
View Source

Diffs

All diffs recorded for the current grid view, and their changes.

Declaration
public IReadOnlyList<Diff<T>> Diffs { get; }
Property Value
Type Description
IReadOnlyList<Diff<T>>
View Source

Height

The height of the grid being represented.

Declaration
public override int Height { get; }
Property Value
Type Description
int
Overrides
SettableGridViewBase<T>.Height
View Source

this[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
Property Value
Type Description
T
Overrides
SettableGridViewBase<T>.this[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.

View Source

Width

The width of the grid being represented.

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

Methods

View Source

ApplyNextDiff()

Applies the next recorded diff, or throws exception if there is no future diffs recorded.

Declaration
public void ApplyNextDiff()
View Source

ApplyNextDiffOrFinalize()

Convenience method that calls ApplyNextDiff() if there are existing diffs to apply, and FinalizeCurrentDiff() if there are no existing diffs to apply. Returns whether or not an existing diff was applied.

Declaration
public bool ApplyNextDiffOrFinalize()
Returns
Type Description
bool

True if an existing diff is applied, false if a new one was created.

View Source

ClearHistory()

Erase recorded diffs without modifying state of grid view.

Declaration
public void ClearHistory()
View Source

FinalizeCurrentDiff()

Finalizes the current diff so that no more changes can be added to it; future changes will create a new diff. Throws exceptions if there are diffs that are not currently applied.

Declaration
public void FinalizeCurrentDiff()
View Source

RevertToPreviousDiff()

Reverts the current diff's changes, so that the grid view will be in the state it was in at the end of the previous diff. Throws exception if no diffs are applied.

Declaration
public void RevertToPreviousDiff()
View Source

SetBaseline(IGridView<T>)

Sets the baseline values (eg. values before any diffs are recorded) to the values from the given grid view. Only valid to do before any diffs are recorded.

Declaration
public void SetBaseline(IGridView<T> baseline)
Parameters
Type Name Description
IGridView<T> baseline

Baseline values to use. Must have same width/height as BaseGrid.

View Source

SetHistory(IEnumerable<Diff<T>>)

Overwrite any history present and replace it with the history given. This does not modify the underlying grid view; the history must be valid with respect to its current state.

Declaration
public void SetHistory(IEnumerable<Diff<T>> history)
Parameters
Type Name Description
IEnumerable<Diff<T>> history

The history to apply.

Remarks

Generally, you will not call this function, however it can be useful for serialization and copying histories between objects. Assumes the grid view is in a state that reflects all of the diffs in the history being applied.

View Source

SetHistory(IEnumerable<Diff<T>>, int)

Overwrite any history present and replace it with the history given. This does not modify the underlying grid view; the history must be valid with respect to its current state.

Declaration
public void SetHistory(IEnumerable<Diff<T>> history, int currentIndex)
Parameters
Type Name Description
IEnumerable<Diff<T>> history

The history to apply.

int currentIndex

The index of the given history that is applied to the BaseGrid. Set to the length of the list - 1 if all diffs have been applied, or -1 if none of them have.

Remarks

Generally, you will not call this function, however it can be useful for serialization and copying histories between objects.

Implements

ISettableGridView<T>
IGridView<T>

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?, EventHandler<ValueChangedEventArgs<TProperty>>?)
GridViewExtensions.Bounds<T>(IGridView<T>)
GridViewExtensions.Contains<T>(IGridView<T>, Point)
GridViewExtensions.Contains<T>(IGridView<T>, int, int)
GridViewExtensions.ExtendToString<T>(IGridView<T>, int, string, string, Func<T, string>?, string, string, string, string)
GridViewExtensions.ExtendToString<T>(IGridView<T>, string, string, Func<T, string>?, string, string, string, string)
GridViewExtensions.Positions<T>(IGridView<T>)
GridViewExtensions.ApplyOverlay<T>(ISettableGridView<T>, IGridView<T>)
GridViewExtensions.ApplyOverlay<T>(ISettableGridView<T>, Func<Point, T>)
  • View Source
In this article
Back to top Generated by DocFX