-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNodeCore.cs
More file actions
34 lines (31 loc) · 1.14 KB
/
NodeCore.cs
File metadata and controls
34 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace WarHub.ArmouryModel.Source
{
/// <summary>
/// The base class for all Cores. Defines methods to
/// create inheritance-supporting <see cref="ToNode(SourceNode)"/> method.
/// </summary>
public abstract record NodeCore : ICore<SourceNode>
{
private int spanLength;
/// <summary>
/// Create a Node from this Core.
/// </summary>
/// <param name="parent">Optional parent of the created Node.</param>
/// <returns>The newly created Node.</returns>
public abstract SourceNode ToNode(SourceNode? parent = null);
/// <summary>
/// Returns span length this node represents.
/// </summary>
public int GetSpanLength()
{
if (spanLength > 0) return spanLength;
return spanLength = 1 + CalculateDescendantSpanLength();
}
/// <summary>
/// Returns a calculated span length of all of this node's descendants.
/// This doesn't include span of the node itself.
/// </summary>
/// <returns></returns>
protected abstract int CalculateDescendantSpanLength();
}
}