Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GroupObject.cs
1using System;
5
7{
11 public class GroupObject
12 {
13 private readonly IElement[] aggregates;
14 private readonly Variables variables;
15 private readonly Dictionary<string, object> groupedValues = new Dictionary<string, object>();
16 private readonly int groupCount;
17
25 public GroupObject(object[] GroupByValues, IElement[] Aggregates,
26 ScriptNode[] GroupNames, Variables Variables)
27 {
28 this.variables = Variables;
29 this.aggregates = Aggregates;
30
31 int i;
32
33 this.groupCount = GroupNames.Length;
34 if (GroupByValues.Length != this.groupCount)
35 throw new ArgumentException("Length mismatch.", nameof(GroupByValues));
36
37 string Name;
38 ScriptNode Node;
39 IElement E;
40
41 for (i = 0; i < this.groupCount; i++)
42 {
43 Node = GroupNames[i];
44 if (Node is null)
45 continue;
46
47 if (Node is VariableReference Ref)
48 Name = Ref.VariableName;
49 else
50 {
51 E = Node.Evaluate(Variables); // TODO: Async
52 Name = ScriptNode.ToString(E);
53 }
54
55 if (!string.IsNullOrEmpty(Name))
56 this.groupedValues[Name] = GroupByValues[i];
57 }
58 }
59
65 public object this[string Name]
66 {
67 get
68 {
69 if (this.groupedValues.TryGetValue(Name, out object Value))
70 return Value;
71 else if (this.variables.TryGetVariable(Name, out Variable v))
72 return v.ValueObject;
73 else
74 return null;
75 }
76
77 set
78 {
79 this.groupedValues[Name] = value;
80 }
81 }
82
86 public IElement[] Aggregates => this.aggregates;
87 }
88}
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
override string ToString()
Definition: ScriptNode.cs:359
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Represents a variable reference.
Represents a collection of objects grouped together useing a GROUP BY construct.
Definition: GroupObject.cs:12
GroupObject(object[] GroupByValues, IElement[] Aggregates, ScriptNode[] GroupNames, Variables Variables)
Represents a collection of objects grouped together useing a GROUP BY construct.
Definition: GroupObject.cs:25
IElement[] Aggregates
Aggregates calculated for the group.
Definition: GroupObject.cs:86
Contains information about a variable.
Definition: Variable.cs:10
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21