Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VectorForEachDefinition.cs
1using System.Collections;
2using System.Collections.Generic;
3using System.Threading.Tasks;
7
9{
14 {
15 private readonly string variableName;
16
25 : base(Elements.LeftOperand, Elements.RightOperand, Start, Length, Expression)
26 {
27 this.variableName = Elements.VariableName;
28 }
29
33 public string VariableName => this.variableName;
34
41 {
42 IElement S = this.left.Evaluate(Variables);
43 LinkedList<IElement> Elements2 = new LinkedList<IElement>();
44
45 if (!(S is ICollection<IElement> Elements))
46 {
47 if (S is IVector Vector)
48 Elements = Vector.VectorElements;
49 else if (!S.IsScalar)
50 Elements = S.ChildElements;
51 else if (S.AssociatedObjectValue is IEnumerable Enumerable)
52 {
53 IEnumerator e = Enumerable.GetEnumerator();
54
55 while (e.MoveNext())
56 {
57 Variables[this.variableName] = e.Current;
58 Elements2.AddLast(this.right.Evaluate(Variables));
59 }
60
61 return this.Encapsulate(Elements2);
62 }
63 else
64 Elements = new IElement[] { S };
65 }
66
67 foreach (IElement Element in Elements)
68 {
69 Variables[this.variableName] = Element;
70 Elements2.AddLast(this.right.Evaluate(Variables));
71 }
72
73 return this.Encapsulate(Elements2);
74 }
75
81 public override async Task<IElement> EvaluateAsync(Variables Variables)
82 {
83 if (!this.isAsync)
84 return this.Evaluate(Variables);
85
86 IElement S = await this.left.EvaluateAsync(Variables);
87 LinkedList<IElement> Elements2 = new LinkedList<IElement>();
88
89 if (!(S is ICollection<IElement> Elements))
90 {
91 if (S is IVector Vector)
92 Elements = Vector.VectorElements;
93 else if (!S.IsScalar)
94 Elements = S.ChildElements;
95 else if (S.AssociatedObjectValue is IEnumerable Enumerable)
96 {
97 IEnumerator e = Enumerable.GetEnumerator();
98
99 while (e.MoveNext())
100 {
101 Variables[this.variableName] = e.Current;
102 Elements2.AddLast(await this.right.EvaluateAsync(Variables));
103 }
104
105 return this.Encapsulate(Elements2);
106 }
107 else
108 Elements = new IElement[] { S };
109 }
110
111 foreach (IElement Element in Elements)
112 {
113 Variables[this.variableName] = Element;
114 Elements2.AddLast(await this.right.EvaluateAsync(Variables));
115 }
116
117 return this.Encapsulate(Elements2);
118 }
119
125 protected virtual IElement Encapsulate(LinkedList<IElement> Elements)
126 {
127 return VectorDefinition.Encapsulate(Elements, true, this);
128 }
129
130 }
131}
Base class for all types of elements.
Definition: Element.cs:13
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode RightOperand
Right operand.
ScriptNode LeftOperand
Left operand.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
virtual IElement Encapsulate(LinkedList< IElement > Elements)
Encapsulates the calculated elements.
VectorForEachDefinition(ForEach Elements, int Start, int Length, Expression Expression)
Creates a vector using a FOREACH statement.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:49
bool IsScalar
If the element represents a scalar value.
Definition: IElement.cs:41
Basic interface for vectors.
Definition: IVector.cs:9