Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Contains.cs
1using System;
2using System.Collections.Generic;
8
10{
15 {
25 : base(new ScriptNode[] { Vector, Item }, new ArgumentType[] { ArgumentType.Normal, ArgumentType.Scalar },
27 {
28 }
29
33 public override string FunctionName => nameof(Contains);
34
38 public override string[] DefaultArgumentNames
39 {
40 get { return new string[] { "Vector", "Item" }; }
41 }
42
50 {
51 IElement Vector = Arguments[0];
52 IElement Item = Arguments[1];
53
54 if (Vector.AssociatedObjectValue is string s1 && Item.AssociatedObjectValue is string s2)
55 return s1.Contains(s2) ? BooleanValue.True : BooleanValue.False;
56 else
57 {
58 ICollection<IElement> ChildElements;
59
60 if (Vector is IVector V)
61 ChildElements = V.VectorElements;
62 else if (Vector is ISet S)
63 ChildElements = S.ChildElements;
64 else
65 throw new ScriptRuntimeException("Expected string arguments, or the first argument to be a vector or a set.", this);
66
67 if (ChildElements is IElement[] V2)
68 return Array.IndexOf(V2, Item) >= 0 ? BooleanValue.True : BooleanValue.False;
69
70 foreach (IElement Element in ChildElements)
71 {
72 if (Item.Equals(Element))
73 return BooleanValue.True;
74 }
75
76 return BooleanValue.False;
77 }
78 }
79
80 }
81}
Base class for all types of elements.
Definition: Element.cs:13
virtual ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: Element.cs:62
Class managing a script expression.
Definition: Expression.cs:39
override string FunctionName
Name of the function
Definition: Contains.cs:33
Contains(ScriptNode Vector, ScriptNode Item, int Start, int Length, Expression Expression)
Contains(Vector,Item)
Definition: Contains.cs:24
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function on a vector argument.
Definition: Contains.cs:49
override string[] DefaultArgumentNames
Default Argument names
Definition: Contains.cs:39
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
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
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for vectors.
Definition: IVector.cs:9
Basic interface for all types of sets.
Definition: ISet.cs:10
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9