ElementCountMethod
Example 1: Disambiguates between binary (Infix) version of - (minus) operator and unary (Prefix) version
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Infix)).ElementCount())
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Prefix)).ElementCount())
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Infix)).ElementCount());
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Prefix)).ElementCount());
WriteLn(uc.GetItemOf('-', uc.Properties(ItemIsEnum.Infix)).ElementCount());
WriteLn(uc.GetItemOf('-', uc.Properties(ItemIsEnum.Prefix)).ElementCount());
cout << uc.GetItemOf("-", uc.Properties(ItemIsEnum::Infix)).ElementCount() << endl;
cout << uc.GetItemOf("-", uc.Properties(ItemIsEnum::Prefix)).ElementCount() << endl;
Console::WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum::Infix)).ElementCount());
Console::WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum::Prefix)).ElementCount());
Example 2: Dispaying the number of elements in an array
Dim MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}")
Dim MyArrayB = uc.DefineVariable("MyArrayB[15]")
Dim FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z")
Dim FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b")
Dim FunctionC = uc.DefineFunction("FuncC(x, y ...)", uc.PinAddr(AddressOf MyAverageCB))
Dim FunctionD = uc.DefineFunction("FuncD() = 1+1")
Dim SyntaxA = uc.DefineSyntax("This ::= That")
Dim SyntaxB = uc.DefineSyntax("This {etc} and {more} ::= Whatever({etc})")
Console.WriteLine("Elements in MyArrayA: " + MyArrayA.ElementCount())
Console.WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount())
Console.WriteLine("Params in FuncA(): " + FunctionA.ElementCount())
Console.WriteLine("Params in FuncB(): " + FunctionB.ElementCount())
Console.WriteLine("Params in FuncC(): " + FunctionC.ElementCount())
Console.WriteLine("Params in FuncD(): " + FunctionD.ElementCount())
Console.WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount())
Console.WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount())
Console.WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount())
Console.WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount())
var MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
var MyArrayB = uc.DefineVariable("MyArrayB[15]");
var FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
var FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
var FunctionC = uc.DefineFunction("FuncC(x, y ...)", uc.PinAddr(MyAverageCB));
var FunctionD = uc.DefineFunction("FuncD() = 1+1");
var SyntaxA = uc.DefineSyntax("This ::= That");
var SyntaxB = uc.DefineSyntax("This {etc} and {more} ::= Whatever({etc})");
Console.WriteLine("Elements in MyArrayA: " + MyArrayA.ElementCount());
Console.WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount());
Console.WriteLine("Params in FuncA(): " + FunctionA.ElementCount());
Console.WriteLine("Params in FuncB(): " + FunctionB.ElementCount());
Console.WriteLine("Params in FuncC(): " + FunctionC.ElementCount());
Console.WriteLine("Params in FuncD(): " + FunctionD.ElementCount());
Console.WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount());
Console.WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount());
Console.WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount());
Console.WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount());
WriteLn('Elements in MyArrayA: ' + MyArrayA.ElementCount());
WriteLn('Elements in MyArrayB: ' + MyArrayB.ElementCount());
WriteLn('Params in FuncA(): ' + FunctionA.ElementCount());
WriteLn('Params in FuncB(): ' + FunctionB.ElementCount());
WriteLn('Params in FuncC(): ' + FunctionC.ElementCount());
WriteLn('Params in FuncD(): ' + FunctionD.ElementCount());
WriteLn('Operands in ! operator: ' + uc.GetItemOf('!').ElementCount());
WriteLn('Operands in > operator: ' + uc.GetItemOf('>').ElementCount());
WriteLn('Params in SyntaxA: ' + SyntaxA.ElementCount());
WriteLn('Params in SyntaxB: ' + SyntaxB.ElementCount());
auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
auto MyArrayB = uc.DefineVariable("MyArrayB[15]");
auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", MyAverageCB);
auto FunctionD = uc.DefineFunction("FuncD() = 1+1");
auto SyntaxA = uc.DefineSyntax("This ::= That");
auto SyntaxB = uc.DefineSyntax("This {etc} and {more} ::= Whatever({etc})");
cout << "Elements in MyArrayA: " << MyArrayA.ElementCount() << endl;
cout << "Elements in MyArrayB: " << MyArrayB.ElementCount() << endl;
cout << "Params in FuncA(): " << FunctionA.ElementCount() << endl;
cout << "Params in FuncB(): " << FunctionB.ElementCount() << endl;
cout << "Params in FuncC(): " << FunctionC.ElementCount() << endl;
cout << "Params in FuncD(): " << FunctionD.ElementCount() << endl;
cout << "Operands in ! operator: " << uc.GetItemOf("!").ElementCount() << endl;
cout << "Operands in > operator: " << uc.GetItemOf(">").ElementCount() << endl;
cout << "Params in SyntaxA: " << SyntaxA.ElementCount() << endl;
cout << "Params in SyntaxB: " << SyntaxB.ElementCount() << endl;
auto MyArrayA = uc.DefineVariable("MyArrayA[] = {10, 20, 30, 40, 50}");
auto MyArrayB = uc.DefineVariable("MyArrayB[15]");
auto FunctionA = uc.DefineFunction("FuncA(x, y, z) = x + y + z");
auto FunctionB = uc.DefineFunction("FuncB(x, y, a = 12, b = 34) = x+y+a+b");
auto FunctionC = uc.DefineFunction("FuncC(x, y ...)", ucPinAddr(MyAverageCB));
auto FunctionD = uc.DefineFunction("FuncD() = 1+1");
auto SyntaxA = uc.DefineSyntax("This ::= That");
auto SyntaxB = uc.DefineSyntax("This {etc} and {more} ::= Whatever({etc})");
Console::WriteLine("Elements in MyArrayA: " + MyArrayA.ElementCount());
Console::WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount());
Console::WriteLine("Params in FuncA(): " + FunctionA.ElementCount());
Console::WriteLine("Params in FuncB(): " + FunctionB.ElementCount());
Console::WriteLine("Params in FuncC(): " + FunctionC.ElementCount());
Console::WriteLine("Params in FuncD(): " + FunctionD.ElementCount());
Console::WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount());
Console::WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount());
Console::WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount());
Console::WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount());
Example 3: Determining properties of an expression part
Sub OpItemTestCB(ByVal ExprPartPtr As IntPtr)
Dim ExprPart As New uCalc.Callback(ExprPartPtr)
Console.WriteLine("Name: " + ExprPart.OpItem().Name())
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name())
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount())
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_))
End Sub
Sub HandleTest()
uc.DefineFunction("AAA() As Double", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(AddressOf OpItemTestCB)):
uc.EvalStr("AAA()")
uc.EvalStr("BBB(9, 8, 7)")
uc.EvalStr("5 CCC 4")
End Sub
static void OpItemTestCB(IntPtr ExprPartPtr) {
var ExprPart = New uCalc.Callback(ExprPartPtr);
Console.WriteLine("Name: " + ExprPart.OpItem().Name());
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", uc.PinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
procedure OpItemTestCB(ExprPartPtr: System.Pointer);
begin
WriteLn('Name: ' + ExprPart.OpItem().Name());
WriteLn('Data type: ' + ExprPart.OpItem().GetDataType().Name());
WriteLn('Param count: ' + ExprPart.OpItem().ElementCount());
WriteLn('Is operator? ' + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_));
End;
procedure HandleTest();
begin
uc.DefineFunction('AAA() As Double', OpItemTestCB);
uc.DefineFunction('BBB(x, y, z) As String', OpItemTestCB);
uc.DefineOperator('{x} CCC {y} As Int32', 0, GroupingEnum.GroupLeftToRight, OpItemTestCB);
uc.EvalStr('AAA()');
uc.EvalStr('BBB(9, 8, 7)');
uc.EvalStr('5 CCC 4');
End;
void _stdcall OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
cout << "Name: " << ExprPart.OpItem().Name() << endl;
cout << "Data type: " << ExprPart.OpItem().GetDataType().Name() << endl;
cout << "Param count: " << ExprPart.OpItem().ElementCount() << endl;
cout << "Is operator? " << ExprPart.OpItem().IsProperty(ItemIsEnum::Operator) << endl;
}
void HandleTest() {
uc.DefineFunction("AAA() As Double", OpItemTestCB);
uc.DefineFunction("BBB(x, y, z) As String", OpItemTestCB);
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, OpItemTestCB);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
static void OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
Console::WriteLine("Name: " + ExprPart.OpItem().Name());
Console::WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console::WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console::WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum::Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", ucPinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", ucPinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, ucPinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="ElementCount")> _
Private Function ElementCount__(ByVal ItemHandle As IntPtr) As Int32
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ElementCount")]
protected static extern Int32 ElementCount_(IntPtr ItemHandle);
{DLLImport}function ElementCount__(ItemHandle: System.Pointer): Int32; cdecl; external uCalcDLL name 'ElementCount';
typedef int32_t (* __ElementCount)(void *ItemHandle);
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "ElementCount")]
static Int32 ElementCount_(void * ItemHandle);