Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SimulationNodeChildren.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
6
8{
13 {
14 private ISimulationNode[] children;
15
22 : base(Parent, Model)
23 {
24 }
25
29 public ISimulationNode[] Children => this.children;
30
35 public override async Task FromXml(XmlElement Definition)
36 {
37 if (this.ParseChildren)
38 {
39 List<ISimulationNode> Children = new List<ISimulationNode>();
40
41 if (!(this.children is null))
42 Children.AddRange(this.children);
43
44 foreach (XmlNode N in Definition.ChildNodes)
45 {
46 if (N is XmlElement E)
47 Children.Add(await Factory.Create(E, this, this.Model ?? this as Model));
48 }
49
50 this.children = Children.ToArray();
51 }
52 else
53 this.children = new ISimulationNode[0];
54 }
55
60 protected void AddChild(ISimulationNode Child)
61 {
62 if (this.children is null)
63 this.children = new ISimulationNode[] { Child };
64 else
65 {
66 int c = this.children.Length;
67 Array.Resize<ISimulationNode>(ref this.children, c + 1);
68 this.children[c] = Child;
69 }
70 }
71
75 public virtual bool ParseChildren => true;
76
82 public override async Task ForEach(ForEachCallbackMethod Method, bool DepthFirst)
83 {
84 if (!DepthFirst)
85 await Method(this);
86
87 if (!(this.children is null))
88 {
89 foreach (ISimulationNode Child in this.children)
90 await Child.ForEach(Method, DepthFirst);
91 }
92
93 if (DepthFirst)
94 await Method(this);
95 }
96
101 public override async Task ExportMarkdown(StreamWriter Output)
102 {
103 if (!(this.children is null))
104 {
105 foreach (ISimulationNode Child in this.children)
106 await Child.ExportMarkdown(Output);
107 }
108 }
109
114 public override async Task ExportXml(XmlWriter Output)
115 {
116 if (!(this.children is null))
117 {
118 foreach (ISimulationNode Child in this.children)
119 await Child.ExportXml(Output);
120 }
121 }
122 }
123}
Factory of simulation objects.
Definition: Factory.cs:14
static async Task< ISimulationNode > Create(XmlElement Definition, ISimulationNode Parent, Model Model)
Creates a simulation objected, based on its XML definition.
Definition: Factory.cs:69
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for simulation nodes with children
override async Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
override async Task ForEach(ForEachCallbackMethod Method, bool DepthFirst)
Evaluates Method on each node in the subtree defined by the current node.
override async Task ExportXml(XmlWriter Output)
Exports XML
void AddChild(ISimulationNode Child)
Adds a child node.
override async Task ExportMarkdown(StreamWriter Output)
Exports Markdown
virtual bool ParseChildren
If children are to be parsed by FromXml(XmlElement)
SimulationNodeChildren(ISimulationNode Parent, Model Model)
Abstract base class for simulation nodes
Abstract base class for simulation nodes
ISimulationNode Parent
Parent node in the simulation model.
Basic interface for simulator nodes with child nodes.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
Task ForEach(ForEachCallbackMethod Method, bool DepthFirst)
Evaluates Method on each node in the subtree defined by the current node.
Task ExportMarkdown(StreamWriter Output)
Exports Markdown
Task ExportXml(XmlWriter Output)
Exports XML
delegate Task ForEachCallbackMethod(ISimulationNode Node)
Callback method for iteration across the simulation model.