Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NumberFunctions.cs
Go to the documentation of this file.
1using System;
2using System.Xml;
5
7
8internal sealed class NumberFunctions : ValueQuery
9{
10 private readonly Query _arg;
11
12 private readonly Function.FunctionType _ftype;
13
14 public override XPathResultType StaticType => XPathResultType.Number;
15
21
23 : base(other)
24 {
25 _arg = Query.Clone(other._arg);
26 _ftype = other._ftype;
27 }
28
29 public override void SetXsltContext(XsltContext context)
30 {
31 if (_arg != null)
32 {
33 _arg.SetXsltContext(context);
34 }
35 }
36
37 internal static double Number(bool arg)
38 {
39 if (!arg)
40 {
41 return 0.0;
42 }
43 return 1.0;
44 }
45
46 internal static double Number(string arg)
47 {
49 }
50
63
65 {
66 if (_arg == null)
67 {
68 return XmlConvert.ToXPathDouble(nodeIterator.Current.Value);
69 }
70 object obj = _arg.Evaluate(nodeIterator);
71 switch (GetXPathType(obj))
72 {
73 case XPathResultType.NodeSet:
74 {
76 if (xPathNavigator != null)
77 {
78 return Number(xPathNavigator.Value);
79 }
80 break;
81 }
82 case XPathResultType.String:
83 return Number((string)obj);
84 case XPathResultType.Boolean:
85 return Number((bool)obj);
86 case XPathResultType.Number:
87 return (double)obj;
88 case (XPathResultType)4:
89 return Number(((XPathNavigator)obj).Value);
90 }
91 return double.NaN;
92 }
93
95 {
96 double num = 0.0;
99 while ((xPathNavigator = _arg.Advance()) != null)
100 {
101 num += Number(xPathNavigator.Value);
102 }
103 return num;
104 }
105
107 {
108 return Math.Floor((double)_arg.Evaluate(nodeIterator));
109 }
110
112 {
113 return Math.Ceiling((double)_arg.Evaluate(nodeIterator));
114 }
115
121
122 public override XPathNodeIterator Clone()
123 {
124 return new NumberFunctions(this);
125 }
126}
override void SetXsltContext(XsltContext context)
double Floor(XPathNodeIterator nodeIterator)
readonly Function.FunctionType _ftype
double Sum(XPathNodeIterator nodeIterator)
NumberFunctions(Function.FunctionType ftype, Query arg)
double Number(XPathNodeIterator nodeIterator)
override XPathResultType StaticType
double Ceiling(XPathNodeIterator nodeIterator)
double Round(XPathNodeIterator nodeIterator)
override XPathNodeIterator Clone()
override object Evaluate(XPathNodeIterator nodeIterator)
object Evaluate(XPathNodeIterator nodeIterator)
XPathResultType GetXPathType(object value)
Definition Query.cs:147
virtual void SetXsltContext(XsltContext context)
Definition Query.cs:52
XPathNavigator Advance()
static Query Clone(Query input)
Definition Query.cs:66
static double Ceiling(double a)
static double Floor(double d)
static double ToXPathDouble(object o)
static double XPathRound(double value)