Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NumericExpr.cs
Go to the documentation of this file.
1using System.Xml;
4
6
7internal sealed class NumericExpr : ValueQuery
8{
9 private readonly Operator.Op _op;
10
11 private readonly Query _opnd1;
12
13 private readonly Query _opnd2;
14
15 public override XPathResultType StaticType => XPathResultType.Number;
16
18 {
19 if (opnd1.StaticType != 0)
20 {
22 }
23 if (opnd2.StaticType != 0)
24 {
26 }
27 _op = op;
28 _opnd1 = opnd1;
29 _opnd2 = opnd2;
30 }
31
32 private NumericExpr(NumericExpr other)
33 : base(other)
34 {
35 _op = other._op;
36 _opnd1 = Query.Clone(other._opnd1);
37 _opnd2 = Query.Clone(other._opnd2);
38 }
39
40 public override void SetXsltContext(XsltContext context)
41 {
42 _opnd1.SetXsltContext(context);
43 _opnd2.SetXsltContext(context);
44 }
45
50
51 private static double GetValue(Operator.Op op, double n1, double n2)
52 {
53 return op switch
54 {
57 Operator.Op.MOD => n1 % n2,
58 Operator.Op.DIV => n1 / n2,
59 Operator.Op.MUL => n1 * n2,
60 _ => 0.0,
61 };
62 }
63
64 public override XPathNodeIterator Clone()
65 {
66 return new NumericExpr(this);
67 }
68}
NumericExpr(Operator.Op op, Query opnd1, Query opnd2)
static double GetValue(Operator.Op op, double n1, double n2)
override object Evaluate(XPathNodeIterator nodeIterator)
override XPathResultType StaticType
override void SetXsltContext(XsltContext context)
override XPathNodeIterator Clone()
object Evaluate(XPathNodeIterator nodeIterator)
virtual void SetXsltContext(XsltContext context)
Definition Query.cs:52
static Query Clone(Query input)
Definition Query.cs:66
static double ToXPathDouble(object o)