Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
In.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
9
11{
15 public class In : BinaryOperator
16 {
25 public In(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
26 : base(Left, Right, Start, Length, Expression)
27 {
28 }
29
36 {
37 IElement Left = this.left.Evaluate(Variables);
38 IElement Right = this.right.Evaluate(Variables);
39
40 return this.Evaluate(Left, Right);
41 }
42
48 public override async Task<IElement> EvaluateAsync(Variables Variables)
49 {
50 if (!this.isAsync)
51 return this.Evaluate(Variables);
52
53 IElement Left = await this.left.EvaluateAsync(Variables);
54 IElement Right = await this.right.EvaluateAsync(Variables);
55
56 return this.Evaluate(Left, Right);
57 }
64 public virtual IElement Evaluate(IElement Left, IElement Right)
65 {
66 if (Right is ISet Set)
67 return this.Evaluate(Left, Set);
68 else if (Right is IVector Vector)
69 return this.Evaluate(Left, Vector);
70 else if (Right.IsScalar)
71 throw new ScriptRuntimeException("Right operand in an IN operation must be a set.", this);
72 else
73 {
74 if (Left.IsScalar)
75 {
76 LinkedList<IElement> Elements = new LinkedList<IElement>();
77
78 foreach (IElement E in Right.ChildElements)
79 Elements.AddLast(this.Evaluate(Left, E));
80
81 return Right.Encapsulate(Elements, this);
82 }
83 else
84 {
85 ICollection<IElement> LeftChildren = Left.ChildElements;
86 ICollection<IElement> RightChildren = Right.ChildElements;
87
88 if (LeftChildren.Count == RightChildren.Count)
89 {
90 LinkedList<IElement> Elements = new LinkedList<IElement>();
91 IEnumerator<IElement> eLeft = LeftChildren.GetEnumerator();
92 IEnumerator<IElement> eRight = RightChildren.GetEnumerator();
93
94 try
95 {
96 while (eLeft.MoveNext() && eRight.MoveNext())
97 Elements.AddLast(this.Evaluate(eLeft.Current, eRight.Current));
98 }
99 finally
100 {
101 eLeft.Dispose();
102 eRight.Dispose();
103 }
104
105 return Left.Encapsulate(Elements, this);
106 }
107 else
108 {
109 LinkedList<IElement> LeftResult = new LinkedList<IElement>();
110
111 foreach (IElement LeftChild in LeftChildren)
112 {
113 LinkedList<IElement> RightResult = new LinkedList<IElement>();
114
115 foreach (IElement RightChild in RightChildren)
116 RightResult.AddLast(this.Evaluate(LeftChild, RightChild));
117
118 LeftResult.AddLast(Right.Encapsulate(RightResult, this));
119 }
120
121 return Left.Encapsulate(LeftResult, this);
122 }
123 }
124 }
125 }
126
133 public virtual IElement Evaluate(IElement Left, ISet Right)
134 {
135 if (Right.Contains(Left))
136 return BooleanValue.True;
137 else
138 return BooleanValue.False;
139 }
140
147 public virtual IElement Evaluate(IElement Left, IVector Right)
148 {
149 foreach (IElement Element in Right.ChildElements)
150 {
151 if (Left.Equals(Element))
152 return BooleanValue.True;
153 }
154
155 return BooleanValue.False;
156 }
157
158 }
159}
Base class for all types of elements.
Definition: Element.cs:13
virtual ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: Element.cs:62
Base class for all types of sets.
Definition: Set.cs:14
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
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
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: In.cs:35
In(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
In operator
Definition: In.cs:25
virtual IElement Evaluate(IElement Left, IElement Right)
Evaluates the operator.
Definition: In.cs:64
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: In.cs:48
virtual IElement Evaluate(IElement Left, IVector Right)
Evaluates the operator.
Definition: In.cs:147
virtual IElement Evaluate(IElement Left, ISet Right)
Evaluates the operator.
Definition: In.cs:133
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:49
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Definition: IElement.cs:41
Basic interface for vectors.
Definition: IVector.cs:9
Basic interface for all types of sets.
Definition: ISet.cs:10
bool Contains(IElement Element)
Checks if the set contains an element.