Gutenberg

Class StackMachineDocumentRenderer<T>

A handy base class for IDocumentRenderer<T> implementations which manage annotations in a stack.

Inheritance
  • Object
  • StackMachineDocumentRenderer<T>
Implements
Declaration
public abstract class StackMachineDocumentRenderer<T> : Object, IDocumentRenderer<T>
Type Parameters
Name Description

T

The type of annotations in the input Document<T>.

Constructors

StackMachineDocumentRenderer()

Declaration
protected StackMachineDocumentRenderer()

Properties

CurrentAnnotation

Get the topmost annotation from the stack, or return a default value.

Declaration
protected T CurrentAnnotation { get; }
Property Value
Type Description

T

HasAnnotation

Returns true if there are annotations in the stack.

Declaration
protected bool HasAnnotation { get; }
Property Value
Type Description

Boolean

Stack

The stack of annotations.

Declaration
protected Stack<T> Stack { get; }
Property Value
Type Description

Stack<T>

Methods

NewLine(CancellationToken)

Write a line break into the output stream.

Declaration
public abstract ValueTask NewLine(CancellationToken cancellationToken = null)
Parameters
Type Name Description

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will complete when the line break has been written to the output stream.

OnBeforePopAnnotation(T, CancellationToken)

Called when value is about to be popped off the Stack.

Declaration
protected virtual ValueTask OnBeforePopAnnotation(T value, CancellationToken cancellationToken = null)
Parameters
Type Name Description

T

value

The value.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will be awaited before popping the value off the Stack.

Remarks

If the stack is mutated (by an override of this method) before the returned ValueTask completes, the value which is on top of the stack after the ValueTask resolves will be popped (and passed to OnPopAnnotation(T, CancellationToken)) instead.

OnBeforePushAnnotation(T, CancellationToken)

Called when value is about to be pushed onto the Stack.

Declaration
protected virtual ValueTask OnBeforePushAnnotation(T value, CancellationToken cancellationToken = null)
Parameters
Type Name Description

T

value

The value.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will be awaited before pushing the value on to the Stack.

OnPopAnnotation(T, CancellationToken)

Called immediately after value has been popped off the Stack.

Declaration
protected virtual ValueTask OnPopAnnotation(T value, CancellationToken cancellationToken = null)
Parameters
Type Name Description

T

value

The value.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will be awaited before returning from PopAnnotation(CancellationToken).

OnPushAnnotation(T, CancellationToken)

Called immediately after value has been pushed onto the Stack.

Declaration
protected virtual ValueTask OnPushAnnotation(T value, CancellationToken cancellationToken = null)
Parameters
Type Name Description

T

value

The value.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will be awaited before returning from PushAnnotation(T, CancellationToken).

PopAnnotation(CancellationToken)

Discard the value of a previous call to PushAnnotation(T, CancellationToken).

Declaration
public virtual ValueTask PopAnnotation(CancellationToken cancellationToken = null)
Parameters
Type Name Description

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will complete when the value has been popped from the stack.

PushAnnotation(T, CancellationToken)

Accept an annotation.

Declaration
public virtual ValueTask PushAnnotation(T value, CancellationToken cancellationToken = null)
Parameters
Type Name Description

T

value

The annotation to push onto the stack.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will complete when the value has been pushed onto the stack.

Text(ReadOnlyMemory<Char>, CancellationToken)

Write some text into the output stream.

Declaration
public abstract ValueTask Text(ReadOnlyMemory<char> memory, CancellationToken cancellationToken = null)
Parameters
Type Name Description

ReadOnlyMemory<Char>

memory

The text to write to the output stream.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will complete when the text has been written to the output stream.

WhiteSpace(Int32, CancellationToken)

Write the given amount of blank space into the output stream.

Declaration
public abstract ValueTask WhiteSpace(int amount, CancellationToken cancellationToken = null)
Parameters
Type Name Description

Int32

amount

The amount of white space to write.

CancellationToken

cancellationToken

A CancellationToken.

Returns
Type Description

ValueTask

A ValueTask which will complete when the white space has been written to the output stream.

Implements

IDocumentRenderer<T>