Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SemanticElementVector.cs
1using System;
2using System.Collections.Generic;
3using Waher.Script;
7
9{
14 {
15 private readonly List<IElement> elements = new List<IElement>();
16
21 {
22 }
23
29 {
30 this.elements.Add(Element);
31 }
32
36 public object Tag { get; set; }
37
41 public bool IsLiteral => false;
42
47
51 public object AssociatedObjectValue => this.elements;
52
56 public bool IsScalar => false;
57
61 public ICollection<IElement> ChildElements => this.elements;
62
69 public IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
70 {
72 Result.elements.AddRange(Elements);
73 return Result;
74 }
75
82 public virtual bool TryConvertTo(Type DesiredType, out object Value)
83 {
84 Value = null;
85 return false;
86 }
87
89 public override bool Equals(object obj)
90 {
91 if (!(obj is SemanticElementVector Typed) ||
92 this.elements.Count != Typed.elements.Count)
93 {
94 return false;
95 }
96
97 IEnumerator<IElement> e1 = this.elements.GetEnumerator();
98 IEnumerator<IElement> e2 = Typed.elements.GetEnumerator();
99
100 while (e1.MoveNext() && e2.MoveNext())
101 {
102 if (!e1.Current.Equals(e2.Current))
103 return false;
104 }
105
106 return true;
107 }
108
110 public override int GetHashCode()
111 {
112 int Result = this.elements.Count.GetHashCode();
113
114 foreach (IElement Element in this.elements)
115 Result ^= Result << 5 ^ Element.GetHashCode();
116
117 return Result;
118 }
119
121 public override string ToString()
122 {
123 return Expression.ToString(this.elements);
124 }
125
137 public virtual int CompareTo(object obj)
138 {
139 return this.ToString().CompareTo(obj?.ToString() ?? string.Empty);
140 }
141
145 public int Dimension => this.elements.Count;
146
150 public ICollection<IElement> VectorElements => this.elements;
151
157 public IElement GetElement(int Index) => this.elements[Index];
158
164 public void SetElement(int Index, IElement Value)
165 {
166 this.elements[Index] = Value;
167 }
168 }
169}
object Tag
Property used by processor, to tag information to an element.
bool IsScalar
If the element represents a scalar value.
ICollection< IElement > VectorElements
An enumeration of vector elements.
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
virtual int CompareTo(object obj)
Compares the current instance with another object of the same type and returns an integer that indica...
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
virtual bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
void SetElement(int Index, IElement Value)
Sets an element in the vector.
void Add(ISemanticElement Element)
Adds a semantic element to the vector.
IElement GetElement(int Index)
Gets an element of the vector.
SemanticElementVector()
Contains a vector of semantic elements.
static readonly SemanticElements Instance
Instance reference to the set of semantic elements.
Base class for all types of elements.
Definition: Element.cs:13
abstract override int GetHashCode()
Calculates a hash code of the element.
Class managing a script expression.
Definition: Expression.cs:39
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Interface for semantic nodes.
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for vectors.
Definition: IVector.cs:9
Basic interface for all types of sets.
Definition: ISet.cs:10