| | | 1 | | namespace MoreStructures.RecImmTrees.Conversions; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}"/> |
| | | 5 | | /// <br/> |
| | | 6 | | /// Provides concrete properties and defaults for new line, identation and stringifiers. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <typeparam name="TEdge">The type of edges of the specific structure.</typeparam> |
| | | 9 | | /// <typeparam name="TNode">The type of nodes of the specific structure.</typeparam> |
| | | 10 | | public abstract class StringifierBase<TEdge, TNode> |
| | | 11 | | : IStringifier<TEdge, TNode> |
| | | 12 | | where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode> |
| | | 13 | | where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode> |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.NewLine"/> |
| | | 17 | | /// By default is <see cref="Environment.NewLine"/>. |
| | | 18 | | /// </summary> |
| | 11228 | 19 | | public string NewLine { get; init; } = Environment.NewLine; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.Indent"/> |
| | | 23 | | /// By default is 4 spaces. |
| | | 24 | | /// </summary> |
| | 50011741 | 25 | | public string Indent { get; init; } = new string(' ', 4); |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.PathSeparator"/> |
| | | 29 | | /// By default is a single space. |
| | | 30 | | /// </summary> |
| | 92 | 31 | | public string PathSeparator { get; init; } = " "; |
| | | 32 | | |
| | | 33 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.RootStringifier"/> |
| | 204 | 34 | | public Func<TNode, string> RootStringifier { get; init; } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.EdgeAndNodeStringifier"/> |
| | 11204 | 37 | | public Func<TEdge, TNode, string> EdgeAndNodeStringifier { get; init; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Builds an instance of an <see cref="IStringifier{TEdge, TNode}"/> with the provided stringifiers, |
| | | 41 | | /// for the root and for all other nodes in the three, and with default new line and indent. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="rootStringifier"><inheritdoc cref="RootStringifier" path="/summary"/></param> |
| | | 44 | | /// <param name="edgeAndNodeStringifier"><inheritdoc cref="EdgeAndNodeStringifier" path="/summary"/></param> |
| | 32 | 45 | | protected StringifierBase( |
| | 32 | 46 | | Func<TNode, string> rootStringifier, Func<TEdge, TNode, string> edgeAndNodeStringifier) |
| | 32 | 47 | | { |
| | 32 | 48 | | RootStringifier = rootStringifier; |
| | 32 | 49 | | EdgeAndNodeStringifier = edgeAndNodeStringifier; |
| | 32 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.Stringify(TNode)"/> |
| | | 53 | | public abstract string Stringify(TNode node); |
| | | 54 | | |
| | | 55 | | /// <inheritdoc cref="IStringifier{TEdge, TNode}.Stringify(TreePath{TEdge, TNode})"/> |
| | | 56 | | public abstract string Stringify(TreePath<TEdge, TNode> path); |
| | | 57 | | } |