100 lines
1.9 KiB
C#
100 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace CPF.ReoGrid.Formula
|
|
{
|
|
internal class STNode : IEnumerable<STNode>, IEnumerable, ICloneable
|
|
{
|
|
public List<STNode> Children { get; set; }
|
|
|
|
public STNodeType Type { get; set; }
|
|
|
|
public int Start { get; set; }
|
|
|
|
public int Length { get; set; }
|
|
|
|
public STNode(STNodeType type, int start, int len) : this(type, start, len, null)
|
|
{
|
|
}
|
|
|
|
public STNode(STNodeType type, int start, int len, List<STNode> children)
|
|
{
|
|
this.Start = start;
|
|
this.Type = type;
|
|
this.Length = len;
|
|
this.Children = children;
|
|
}
|
|
|
|
public STNode this[int index]
|
|
{
|
|
get
|
|
{
|
|
return this.Children[index];
|
|
}
|
|
set
|
|
{
|
|
this.Children[index] = value;
|
|
}
|
|
}
|
|
|
|
private IEnumerator<STNode> GetEnum()
|
|
{
|
|
bool flag = this.Children != null && this.Children.Count > 0;
|
|
if (flag)
|
|
{
|
|
foreach (STNode child in this.Children)
|
|
{
|
|
yield return child;
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator<STNode> GetEnumerator()
|
|
{
|
|
return this.GetEnum();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return this.GetEnum();
|
|
}
|
|
|
|
internal static void RecursivelyIterate(STNode node, Action<STNode> iterator)
|
|
{
|
|
bool flag = node.Children != null && node.Children.Count > 0;
|
|
if (flag)
|
|
{
|
|
foreach (STNode node2 in node)
|
|
{
|
|
STNode.RecursivelyIterate(node2, iterator);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
iterator(node);
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("Node[{0}-{1}]", this.Start, this.Start + this.Length);
|
|
}
|
|
|
|
public virtual object Clone()
|
|
{
|
|
STNode stnode = new STNode(this.Type, this.Start, this.Length);
|
|
bool flag = this.Children != null && this.Children.Count > 0;
|
|
if (flag)
|
|
{
|
|
stnode.Children = new List<STNode>();
|
|
foreach (STNode stnode2 in this.Children)
|
|
{
|
|
stnode.Children.Add((STNode)stnode2.Clone());
|
|
}
|
|
}
|
|
return stnode;
|
|
}
|
|
}
|
|
}
|