Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XorEvaluator.cs
5
7{
12 {
13 private ulong integerResult = 0;
14 private bool integerSigned = false;
15 private bool booleanResult = false;
16 private bool isBoolean = false;
17 private bool isInteger = false;
18 private bool first = true;
19
25 : base(Node.Argument)
26 {
27 }
28
32 public override void RestartEvaluator()
33 {
34 this.integerResult = 0;
35 this.booleanResult = false;
36 this.isInteger = false;
37 this.isBoolean = false;
38 this.first = true;
39 }
40
45 public override void AggregateElement(IElement Element)
46 {
47 if (this.first)
48 {
49 this.first = false;
50
51 if (Element is BooleanValue B)
52 {
53 this.isBoolean = true;
54 this.booleanResult = B.Value;
55 }
56 else if (Element is DoubleNumber D)
57 {
58 this.isInteger = true;
59 this.integerResult = Operators.Binary.And.ToUInt64(D.Value,
60 out this.integerSigned, this.Node);
61 }
62 else
63 throw new ScriptRuntimeException("Operands must be integer or Boolean values.", this.Node);
64 }
65 else if (this.isBoolean)
66 {
67 if (Element is BooleanValue B)
68 this.booleanResult ^= B.Value;
69 else
70 throw new ScriptRuntimeException("Operands do not match.", this.Node);
71 }
72 else if (this.isInteger)
73 {
74 if (Element is DoubleNumber D)
75 {
76 ulong Value = Operators.Binary.And.ToUInt64(D.Value, out bool Signed, this.Node);
77
78 this.integerResult ^= Value;
79 this.integerSigned ^= Signed;
80 }
81 else
82 throw new ScriptRuntimeException("Operands do not match.", this.Node);
83 }
84 else
85 throw new ScriptRuntimeException("Operands must be integer or Boolean values.", this.Node);
86 }
87
91 public override IElement GetAggregatedResult()
92 {
93 if (this.first)
94 return ObjectValue.Null;
95 else if (this.isBoolean)
96 return this.booleanResult ? BooleanValue.True : BooleanValue.False;
97 else if (this.isInteger)
98 {
99 if (this.integerSigned)
100 return new DoubleNumber((long)this.integerResult);
101 else
102 return new DoubleNumber(this.integerResult);
103 }
104 else
105 throw new ScriptRuntimeException("Operands must be integer or Boolean values.", this.Node);
106 }
107 }
108}
Base class for all types of elements.
Definition: Element.cs:14
override void AggregateElement(IElement Element)
Aggregates one new element.
Definition: XorEvaluator.cs:45
XorEvaluator(Xor Node)
Xor(v) iterative evaluator
Definition: XorEvaluator.cs:24
override IElement GetAggregatedResult()
Gets the aggregated result.
Definition: XorEvaluator.cs:91
override void RestartEvaluator()
Restarts the evaluator.
Definition: XorEvaluator.cs:32
An interative evaluator of a function or operation defined by a single ScriptNode.
ScriptNode Node
Node being iteratively evaluated.
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:88
Basic interface for all types of elements.
Definition: IElement.cs:21