Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UnaryDoubleOperator.cs
1using System;
2using System.Threading.Tasks;
6
7namespace Waher.Script.Model
8{
13 {
23 {
24 }
25
32 {
33 IElement Op = this.op.Evaluate(Variables);
34
35 if (Op.AssociatedObjectValue is double d)
36 return this.Evaluate(d);
37 else
38 return this.Evaluate(Op, Variables);
39 }
40
46 public override async Task<IElement> EvaluateAsync(Variables Variables)
47 {
48 if (!this.isAsync)
49 return base.Evaluate(Variables);
50
51 IElement Op = await this.op.EvaluateAsync(Variables);
52
53 if (Op.AssociatedObjectValue is double d)
54 return await this.EvaluateAsync(d);
55 else
56 return await this.EvaluateAsync(Op, Variables);
57 }
58
66 {
67 object Obj = Operand.AssociatedObjectValue;
68
69 if (Obj is double d)
70 return this.Evaluate(d);
71 else if (Expression.TryConvert(Obj, out d))
72 return this.Evaluate(d);
73 else
74 throw new ScriptRuntimeException("Scalar operands must be double values or physical magnitudes.", this);
75 }
76
83 public override async Task<IElement> EvaluateScalarAsync(IElement Operand, Variables Variables)
84 {
85 object Obj = Operand.AssociatedObjectValue;
86
87 if (Obj is double d)
88 return await this.EvaluateAsync(d);
89 else if (Expression.TryConvert(Obj, out d))
90 return await this.EvaluateAsync(d);
91 else
92 throw new ScriptRuntimeException("Scalar operands must be double values or physical magnitudes.", this);
93 }
94
100 public abstract IElement Evaluate(double Operand);
101
107 public virtual Task<IElement> EvaluateAsync(double Operand)
108 {
109 return Task.FromResult<IElement>(this.Evaluate(Operand));
110 }
111 }
112}
Class managing a script expression.
Definition: Expression.cs:39
static bool TryConvert(object Value, Type DesiredType, out object Result)
Tries to convert an object Value to an object of type DesiredType .
Definition: Expression.cs:5268
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
Base class for unary double operators.
abstract IElement Evaluate(double Operand)
Evaluates the double operator.
virtual Task< IElement > EvaluateAsync(double Operand)
Evaluates the double operator.
UnaryDoubleOperator(ScriptNode Operand, int Start, int Length, Expression Expression)
Base class for binary double operators.
override async Task< IElement > EvaluateScalarAsync(IElement Operand, Variables Variables)
Evaluates the operator on scalar operands.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override IElement EvaluateScalar(IElement Operand, Variables Variables)
Evaluates the operator on scalar operands.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
bool isAsync
If subtree is asynchroneous.
Base class for unary scalar operators.
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