Class SentenceSnapshot
The values of one Sentence and its execution-order index, taken off a carrier once and held as plain values: the sentence index, the block text, the file path and the six integers of the character segment with their three presence flags. A snapshot holds no reference to the carrier or to the sentence it was taken from, so it keeps nothing of the play alive, and nothing reaches into it: CharIndexSegment is a new object on every read, and GetSentence() builds its sentence on a copy of the segment, so whatever a reader does to the objects it was given never changes the snapshot.
Of(ISentenceCarrier) interns the snapshots by carrier: the same carrier always answers the same snapshot object while the carrier is alive (a weak table keyed by the carrier), so every record of one sentence -- the step records built from it and the syntax-piece record of the piece -- carries the same snapshot reference, and that reference is the key under which the result recording hands a sentence its piece id (the plan's P3); the sentence index stays a diagnostic column. The snapshot is the sentence as it was when the carrier was first seen: a sentence is not written after it is built, so a snapshot does not go stale.
Persisted as one record (WriteBin(BinaryWriter), SentenceSnapshot(BinaryReader)).public sealed class SentenceSnapshot : ISentenceCarrier, IGetSentence, ISentenceIndexed, IWriteBin
- Inheritance
-
SentenceSnapshot
- Implements
- Inherited Members
- Extension Methods
Constructors
SentenceSnapshot(BinaryReader)
Reads the record WriteBin(BinaryWriter) wrote. The version byte is judged before a byte of the payload is read; the integers of an absent segment, begin or end are read past and not interpreted.
public SentenceSnapshot(BinaryReader reader)
Parameters
readerBinaryReaderThe reader positioned at the record's first byte.
Exceptions
- InvalidDataException
The record's version is not this build's.
- EndOfStreamException
The stream ends inside the record.
SentenceSnapshot(BinaryReader, Func<string, string>)
SentenceSnapshot(BinaryReader), with the file path passed through
internPath once read: a reader that rebuilds many snapshots hands them
one string a path, as a live play's sentences share theirs.
public SentenceSnapshot(BinaryReader reader, Func<string, string> internPath)
Parameters
readerBinaryReaderThe reader positioned at the record's first byte.
internPathFunc<string, string>Answers the string to keep for a file path read (the same string for equal paths); null keeps the one decoded. Not called for a sentence without a path.
Exceptions
- InvalidDataException
The record's version is not this build's.
- EndOfStreamException
The stream ends inside the record.
SentenceSnapshot(int, string, string, FileLineCharIndexSegment)
Initializes a snapshot from its values. The segment's begin and end are copied as integers; the segment object itself is not kept, and a null one is a sentence without a segment.
public SentenceSnapshot(int sentenceIndex, string blockText, string filePath, FileLineCharIndexSegment charIndexSegment)
Parameters
sentenceIndexintThe execution-order index of the sentence; -1 for none.
blockTextstringThe sentence's block text; null for none.
filePathstringThe sentence's file path; null for none.
charIndexSegmentFileLineCharIndexSegmentThe sentence's character segment; null for none.
Properties
BlockText
The sentence's BlockText; null when the carrier had no sentence or the sentence no text (an empty text stays empty).
public string BlockText { get; }
Property Value
CharIndexSegment
The sentence's CharIndexSegment as a new object on every read: the snapshot holds the segment's six integers and three presence flags, not an object, so a write to the segment answered here changes nothing. Null when the sentence had no segment; a segment without a begin or an end answers nulls there.
public FileLineCharIndexSegment CharIndexSegment { get; }
Property Value
FilePath
The sentence's FilePath; null when the carrier had no sentence or the sentence no path (an empty path stays empty).
public string FilePath { get; }
Property Value
SentenceIndex
0-based ordinal in pipeline execution order.
public int SentenceIndex { get; }
Property Value
Methods
GetSentence()
The snapshot as a Sentence: built once, on the first call, from the three values and a copy of the segment, and the same object on every later call. Never null: a snapshot of three nulls answers a sentence of three nulls, whose FirstIndexedFileLine is null. A write to the object answered (its segment, its path) stays on that object and never reaches the snapshot.
public Sentence GetSentence()
Returns
- Sentence
The sentence.
Of(ISentenceCarrier)
Internal Use Only. The snapshot of carrier's sentence: the one
interned for the carrier, taken the first time the carrier is seen – its
SentenceIndex and the three values of the sentence its
GetSentence() answers; a carrier without a sentence takes a
snapshot of three nulls – and the same object on every later call for the same carrier.
Null for a null carrier; a snapshot answers itself. The key is the source command of a
step, never the step: a MachiningStep is a carrier too, but a snapshot taken of
it is the step's own, not the one its records carry (MachiningStepRecord.Of
passes the step's source command).
public static SentenceSnapshot Of(ISentenceCarrier carrier)
Parameters
carrierISentenceCarrierThe carrier of the sentence; null answers null.
Returns
- SentenceSnapshot
The carrier's snapshot.
TryGetFileLineIndex(out int, out int)
The file and the line the sentence begins at: true, with the begin position's file and line indices, when the segment has a begin whose file index is not negative. False otherwise – no segment, no begin, or a begin with a negative file index – with both indices -1: the result recording leaves its two address columns NULL for such a sentence and does not index it by address.
public bool TryGetFileLineIndex(out int fileIndex, out int lineIndex)
Parameters
fileIndexintThe 0-based file index of the begin; -1 when false.
lineIndexintThe 0-based line index of the begin; -1 when false.
Returns
- bool
True when the sentence has an address.
WriteBin(BinaryWriter)
Writes the snapshot as one record: the version byte, SentenceIndex (int32), a presence byte and the string of BlockText, a presence byte and the string of FilePath (a null string writes its presence byte 0 and no string, so an empty string is told from null; a string is Write(string)'s length-prefixed UTF-8), then the segment, fixed in size: a presence byte for the segment, a presence byte for its begin and the begin's file, line and character indices (int32), a presence byte for its end and the end's three indices – an absent segment, begin or end writes 0 for its presence byte and its integers.
public void WriteBin(BinaryWriter writer)
Parameters
writerBinaryWriterThe writer to write to.