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;
4using Waher.Script;
8
10{
15 {
16 private readonly ChunkedList<IElement> elements = new ChunkedList<IElement>();
17
22 {
23 }
24
30 {
31 this.elements.Add(Element);
32 }
33
37 public object Tag { get; set; }
38
42 public bool IsLiteral => false;
43
48
52 public object AssociatedObjectValue => this.elements;
53
57 public bool IsScalar => false;
58
62 public ICollection<IElement> ChildElements => this.elements;
63
71 {
73 Result.elements.AddRange(Elements);
74 return Result;
75 }
76
83 public IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
84 {
86 Result.elements.AddRange(Elements);
87 return Result;
88 }
89
96 public virtual bool TryConvertTo(Type DesiredType, out object Value)
97 {
98 Value = null;
99 return false;
100 }
101
103 public override bool Equals(object obj)
104 {
105 if (!(obj is SemanticElementVector Typed) ||
106 this.elements.Count != Typed.elements.Count)
107 {
108 return false;
109 }
110
111 IEnumerator<IElement> e1 = null;
112 IEnumerator<IElement> e2 = null;
113
114 try
115 {
116 e1 = this.elements.GetEnumerator();
117 e2 = Typed.elements.GetEnumerator();
118
119 while (e1.MoveNext() && e2.MoveNext())
120 {
121 if (!e1.Current.Equals(e2.Current))
122 return false;
123 }
124 }
125 finally
126 {
127 e1?.Dispose();
128 e2?.Dispose();
129 }
130
131 return true;
132 }
133
135 public override int GetHashCode()
136 {
137 int Result = this.elements.Count.GetHashCode();
138
139 foreach (IElement Element in this.elements)
140 Result ^= Result << 5 ^ Element.GetHashCode();
141
142 return Result;
143 }
144
146 public override string ToString()
147 {
148 return Expression.ToExpressionString(this.elements);
149 }
150
162 public virtual int CompareTo(object obj)
163 {
164 return this.ToString().CompareTo(obj?.ToString() ?? string.Empty);
165 }
166
170 public int Dimension => this.elements.Count;
171
175 public ICollection<IElement> VectorElements => this.elements;
176
182 public IElement GetElement(int Index) => this.elements[Index];
183
189 public void SetElement(int Index, IElement Value)
190 {
191 this.elements[Index] = Value;
192 }
193 }
194}
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.
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
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.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void AddRange(IEnumerable< T > Collection)
Adds a range of elements (last) to the list.
Base class for all types of elements.
Definition: Element.cs:14
abstract override int GetHashCode()
Calculates a hash code of the element.
Class managing a script expression.
Definition: Expression.cs:41
static string ToExpressionString(object Value)
Converts an object to a string, that can be parsed as part of an expression.
Definition: Expression.cs:5052
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:21
Basic interface for vectors.
Definition: IVector.cs:9
Basic interface for all types of sets.
Definition: ISet.cs:10