GetItemOfMethod

Applies to:uCalc Transform
Class:uCalc
Returns the uCalc.Item object associated with the given name
Syntax
GetItemOf(ItemName, Properties, SkipExpansion)
Parameters
ItemName
String
Name of uCalc.Item that you want to get
Properties
Int64
(Default = 0)
Properties to help pinpoint the right Item, in case several items share the same name
SkipExpansion
BOOLEAN
(Default = 0)
Some items are define as a syntax construct alias of another item. By default the symbol is expanded first. However, use this option if the alias is the object you're actually after.
Returns
Type: Item
Returns the uCalc.Item object associated with the given name
Remarks
If there is no match, an item whose IsProperty ItemIsEnum.NotFound value is true is returned.

In case multiple items share the same name, you can narrow it down using properties. For instance, the + operator has a binary and unary versions. You can specify Prefix if you wanted the unary one.

Note: A ItemIsEnum member should not be passed directly as the second argument. Instead Properties, with one or more ItemIsEnum members should be passed.

Example 1: Disambiguates between binary (Infix) version of - (minus) operator and unary (Prefix) version

Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Infix)).ElementCount()) ' Returns 2
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Prefix)).ElementCount()) ' Returns 1

          

Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Infix)).ElementCount()); // Returns 2;
Console.WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum.Prefix)).ElementCount()); // Returns 1;

          

      WriteLn(uc.GetItemOf('-', uc.Properties(ItemIsEnum.Infix)).ElementCount()); // Returns 2;
      WriteLn(uc.GetItemOf('-', uc.Properties(ItemIsEnum.Prefix)).ElementCount()); // Returns 1;

          

cout << uc.GetItemOf("-", uc.Properties(ItemIsEnum::Infix)).ElementCount() << endl; // Returns 2;
cout << uc.GetItemOf("-", uc.Properties(ItemIsEnum::Prefix)).ElementCount() << endl; // Returns 1;

          

Console::WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum::Infix)).ElementCount()); // Returns 2;
Console::WriteLine(uc.GetItemOf("-", uc.Properties(ItemIsEnum::Prefix)).ElementCount()); // Returns 1;

          
Example 2: Defining another Abs function using the same callback address of existing one

uc.Define("Function: MyAbs(x)", uc.GetItemOf("Abs").FunctionAddress())
Console.WriteLine(uc.Eval("MyAbs(-123)")) ' Returns 123

          

uc.Define("Function: MyAbs(x)", uc.GetItemOf("Abs").FunctionAddress());
Console.WriteLine(uc.Eval("MyAbs(-123)")); // Returns 123;

          

      uc.Define('Function: MyAbs(x)', (void *)uc.GetItemOf('Abs').FunctionAddress());
      WriteLn(uc.Eval('MyAbs(-123)')); // Returns 123;

          

uc.Define("Function: MyAbs(x)", (void *)uc.GetItemOf("Abs").FunctionAddress());
cout << uc.Eval("MyAbs(-123)") << endl; // Returns 123;

          

uc.Define("Function: MyAbs(x)", (void *)uc.GetItemOf("Abs").FunctionAddress());
Console::WriteLine(uc.Eval("MyAbs(-123)")); // Returns 123;

          
Example 3: Determining whether items are functions, or arrays, etc.

uc.DefineVariable("MyVar")
' Note: Some properties may end with an underscore (_) if the original property name is a reserved word in the compiler.
' True or False, or 1 or 0 may be returned depending on the compiler and/or settings 
Console.WriteLine("Cos is a function? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Function_)) ' Returns "Cos is a function? 1"
Console.WriteLine("Cos is a variable? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Variable)) ' Returns "Cos is a variable? 0"
Console.WriteLine("Cos is an operator? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Operator_)) ' Returns "Cos is an operator? 0"
Console.WriteLine("MyVar is a function? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Function_)) ' Returns "MyVar is a function? 0"
Console.WriteLine("MyVar is a variable? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Variable)) ' Returns "MyVar is a variable? 1"
Console.WriteLine("MyVar is an operator? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Operator_)) ' Returns "MyVar is an operator? 0"
Console.WriteLine("+ is a function? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Function_)) ' Returns "+ is a function? 0"
Console.WriteLine("+ is a variable? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Variable)) ' Returns "+ is a variable? 0"
Console.WriteLine("+ is an operator? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Operator_)) ' Returns "+ is an operator? 1"
Console.WriteLine("Cos doesn't exist? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.NotFound)) ' Returns "Cos doesn't exist? 0"
Console.WriteLine("XYZABC doesn't exist? " + uc.GetItemOf("XYZABC").IsProperty(ItemIsEnum.NotFound)) ' Returns "XYZABC doesn't exist? 1"

          

uc.DefineVariable("MyVar");
// Note: Some properties may end with an underscore (_) if the original property name is a reserved word in the compiler.
// True or False, or 1 or 0 may be returned depending on the compiler and/or settings 
Console.WriteLine("Cos is a function? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Function)); // Returns "Cos is a function? 1";
Console.WriteLine("Cos is a variable? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Variable)); // Returns "Cos is a variable? 0";
Console.WriteLine("Cos is an operator? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.Operator)); // Returns "Cos is an operator? 0";
Console.WriteLine("MyVar is a function? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Function)); // Returns "MyVar is a function? 0";
Console.WriteLine("MyVar is a variable? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Variable)); // Returns "MyVar is a variable? 1";
Console.WriteLine("MyVar is an operator? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum.Operator)); // Returns "MyVar is an operator? 0";
Console.WriteLine("+ is a function? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Function)); // Returns "+ is a function? 0";
Console.WriteLine("+ is a variable? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Variable)); // Returns "+ is a variable? 0";
Console.WriteLine("+ is an operator? " + uc.GetItemOf("+").IsProperty(ItemIsEnum.Operator)); // Returns "+ is an operator? 1";
Console.WriteLine("Cos doesn't exist? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum.NotFound)); // Returns "Cos doesn't exist? 0";
Console.WriteLine("XYZABC doesn't exist? " + uc.GetItemOf("XYZABC").IsProperty(ItemIsEnum.NotFound)); // Returns "XYZABC doesn't exist? 1";

          

      uc.DefineVariable('MyVar');
      // Note: Some properties may end with an underscore (_) if the original property name is a reserved word in the compiler.
      // True or False, or 1 or 0 may be returned depending on the compiler and/or settings 
      WriteLn('Cos is a function? ' + uc.GetItemOf('Cos').IsProperty(ItemIsEnum.Function_)); // Returns 'Cos is a function? 1';
      WriteLn('Cos is a variable? ' + uc.GetItemOf('Cos').IsProperty(ItemIsEnum.Variable)); // Returns 'Cos is a variable? 0';
      WriteLn('Cos is an operator? ' + uc.GetItemOf('Cos').IsProperty(ItemIsEnum.Operator_)); // Returns 'Cos is an operator? 0';
      WriteLn('MyVar is a function? ' + uc.GetItemOf('MyVar').IsProperty(ItemIsEnum.Function_)); // Returns 'MyVar is a function? 0';
      WriteLn('MyVar is a variable? ' + uc.GetItemOf('MyVar').IsProperty(ItemIsEnum.Variable)); // Returns 'MyVar is a variable? 1';
      WriteLn('MyVar is an operator? ' + uc.GetItemOf('MyVar').IsProperty(ItemIsEnum.Operator_)); // Returns 'MyVar is an operator? 0';
      WriteLn('+ is a function? ' + uc.GetItemOf('+').IsProperty(ItemIsEnum.Function_)); // Returns '+ is a function? 0';
      WriteLn('+ is a variable? ' + uc.GetItemOf('+').IsProperty(ItemIsEnum.Variable)); // Returns '+ is a variable? 0';
      WriteLn('+ is an operator? ' + uc.GetItemOf('+').IsProperty(ItemIsEnum.Operator_)); // Returns '+ is an operator? 1';
      WriteLn('Cos doesn"t exist? ' + uc.GetItemOf('Cos').IsProperty(ItemIsEnum.NotFound)); // Returns 'Cos doesn"t exist? 0';
      WriteLn('XYZABC doesn"t exist? ' + uc.GetItemOf('XYZABC').IsProperty(ItemIsEnum.NotFound)); // Returns 'XYZABC doesn"t exist? 1';

          

uc.DefineVariable("MyVar");
// Note: Some properties may end with an underscore (_) if the original property name is a reserved word in the compiler.
// True or False, or 1 or 0 may be returned depending on the compiler and/or settings 
cout << "Cos is a function? " << uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Function) << endl; // Returns "Cos is a function? 1";
cout << "Cos is a variable? " << uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Variable) << endl; // Returns "Cos is a variable? 0";
cout << "Cos is an operator? " << uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Operator) << endl; // Returns "Cos is an operator? 0";
cout << "MyVar is a function? " << uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Function) << endl; // Returns "MyVar is a function? 0";
cout << "MyVar is a variable? " << uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Variable) << endl; // Returns "MyVar is a variable? 1";
cout << "MyVar is an operator? " << uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Operator) << endl; // Returns "MyVar is an operator? 0";
cout << "+ is a function? " << uc.GetItemOf("+").IsProperty(ItemIsEnum::Function) << endl; // Returns "+ is a function? 0";
cout << "+ is a variable? " << uc.GetItemOf("+").IsProperty(ItemIsEnum::Variable) << endl; // Returns "+ is a variable? 0";
cout << "+ is an operator? " << uc.GetItemOf("+").IsProperty(ItemIsEnum::Operator) << endl; // Returns "+ is an operator? 1";
cout << "Cos doesn't exist? " << uc.GetItemOf("Cos").IsProperty(ItemIsEnum::NotFound) << endl; // Returns "Cos doesn't exist? 0";
cout << "XYZABC doesn't exist? " << uc.GetItemOf("XYZABC").IsProperty(ItemIsEnum::NotFound) << endl; // Returns "XYZABC doesn't exist? 1";

          

uc.DefineVariable("MyVar");
// Note: Some properties may end with an underscore (_) if the original property name is a reserved word in the compiler.
// True or False, or 1 or 0 may be returned depending on the compiler and/or settings 
Console::WriteLine("Cos is a function? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Function)); // Returns "Cos is a function? 1";
Console::WriteLine("Cos is a variable? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Variable)); // Returns "Cos is a variable? 0";
Console::WriteLine("Cos is an operator? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum::Operator)); // Returns "Cos is an operator? 0";
Console::WriteLine("MyVar is a function? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Function)); // Returns "MyVar is a function? 0";
Console::WriteLine("MyVar is a variable? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Variable)); // Returns "MyVar is a variable? 1";
Console::WriteLine("MyVar is an operator? " + uc.GetItemOf("MyVar").IsProperty(ItemIsEnum::Operator)); // Returns "MyVar is an operator? 0";
Console::WriteLine("+ is a function? " + uc.GetItemOf("+").IsProperty(ItemIsEnum::Function)); // Returns "+ is a function? 0";
Console::WriteLine("+ is a variable? " + uc.GetItemOf("+").IsProperty(ItemIsEnum::Variable)); // Returns "+ is a variable? 0";
Console::WriteLine("+ is an operator? " + uc.GetItemOf("+").IsProperty(ItemIsEnum::Operator)); // Returns "+ is an operator? 1";
Console::WriteLine("Cos doesn't exist? " + uc.GetItemOf("Cos").IsProperty(ItemIsEnum::NotFound)); // Returns "Cos doesn't exist? 0";
Console::WriteLine("XYZABC doesn't exist? " + uc.GetItemOf("XYZABC").IsProperty(ItemIsEnum::NotFound)); // Returns "XYZABC doesn't exist? 1";

          
Example 4: returning data type names for the different definitions of the "+" operator

Dim PlusOperator = uc.GetItemOf("+")

while PlusOperator.ItemHandle <>  0 

   Console.WriteLine("Def: " + PlusOperator.Text() + "  Type: " + PlusOperator.GetDataType().Name())
   PlusOperator = PlusOperator.NextOverload()
End while

' Output
' Def: Operator_: 70 +{x}  Type: double
' Def: Operator_: 50 {x} + {y}  Type: double
' Def: Operator_: 50 {x As Int32} + {y As Int32} As Int32  Type: Int32
' Def: Operator_: 50 {x As String} + {y As String} As String  Type: string
' Def: Operator_: 50 {x} + {y As Complex} As Complex  Type: complex
' Def: Operator_: 50 {x As Complex} + {y} As Complex  Type: complex
' Def: Operator_: 50 {x As Complex} + {y As Complex} As Complex  Type: complex

          

var PlusOperator = uc.GetItemOf("+");

while (PlusOperator.ItemHandle != null) {
   Console.WriteLine("Def: " + PlusOperator.Text() + "  Type: " + PlusOperator.GetDataType().Name());
   PlusOperator = PlusOperator.NextOverload();
}
// Output
// Def: Operator: 70 +{x}  Type: double
// Def: Operator: 50 {x} + {y}  Type: double
// Def: Operator: 50 {x As Int32} + {y As Int32} As Int32  Type: Int32
// Def: Operator: 50 {x As String} + {y As String} As String  Type: string
// Def: Operator: 50 {x} + {y As Complex} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y As Complex} As Complex  Type: complex

          

//var PlusOperator = uc.GetItemOf('+');

      while PlusOperator.ItemHandle <>  0  do
begin
    
         WriteLn('Def: ' + PlusOperator.Text() + '  Type: ' + PlusOperator.GetDataType().Name());
         PlusOperator = PlusOperator.NextOverload();

End;
      // Output
// Def: Operator_: 70 +{x}  Type: double
// Def: Operator_: 50 {x} + {y}  Type: double
// Def: Operator_: 50 {x As Int32} + {y As Int32} As Int32  Type: Int32
// Def: Operator_: 50 {x As String} + {y As String} As String  Type: string
// Def: Operator_: 50 {x} + {y As Complex} As Complex  Type: complex
// Def: Operator_: 50 {x As Complex} + {y} As Complex  Type: complex
// Def: Operator_: 50 {x As Complex} + {y As Complex} As Complex  Type: complex

          

auto PlusOperator = uc.GetItemOf("+");

while (PlusOperator.ItemHandle != NULL) {
   cout << "Def: " << PlusOperator.Text() << "  Type: " << PlusOperator.GetDataType().Name() << endl;
   PlusOperator = PlusOperator.NextOverload();
}
// Output
// Def: Operator: 70 +{x}  Type: double
// Def: Operator: 50 {x} + {y}  Type: double
// Def: Operator: 50 {x As Int} + {y As Int} As Int  Type: int
// Def: Operator: 50 {x As String} + {y As String} As String  Type: string
// Def: Operator: 50 {x} + {y As Complex} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y As Complex} As Complex  Type: complex

          

auto PlusOperator = uc.GetItemOf("+");

while (PlusOperator.ItemHandle != 0) {
   Console::WriteLine("Def: " + PlusOperator.Text() + "  Type: " + PlusOperator.GetDataType().Name());
   PlusOperator = PlusOperator.NextOverload();
}
// Output
// Def: Operator: 70 +{x}  Type: double
// Def: Operator: 50 {x} + {y}  Type: double
// Def: Operator: 50 {x As Int} + {y As Int} As Int  Type: int
// Def: Operator: 50 {x As String} + {y As String} As String  Type: string
// Def: Operator: 50 {x} + {y As Complex} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y} As Complex  Type: complex
// Def: Operator: 50 {x As Complex} + {y As Complex} As Complex  Type: complex

          
Example 5: Finding the precedence level of an operator

Console.Write("The precedence level of the 'And' operator is: ")
Console.WriteLine(uc.GetItemOf("And").Precedence()) ' Returns 30
uc.DefineOperator("{a} && {b} As Bool = a And b", uc.GetItemOf("And").Precedence())
Console.WriteLine(uc.EvalStr("1 > 0 && 2 > 0")) ' Returns "true"
Console.WriteLine(uc.EvalStr("1 > 2 && 2 > 0")) ' Returns "false"

          

Console.Write("The precedence level of the 'And' operator is: ");
Console.WriteLine(uc.GetItemOf("And").Precedence()); // Returns 30;
uc.DefineOperator("{a} && {b} As Bool = a And b", uc.GetItemOf("And").Precedence());
Console.WriteLine(uc.EvalStr("1 > 0 && 2 > 0")); // Returns "true";
Console.WriteLine(uc.EvalStr("1 > 2 && 2 > 0")); // Returns "false";

          

      Write('The precedence level of the "And" operator is: ');
      WriteLn(uc.GetItemOf('And').Precedence()); // Returns 30;
      uc.DefineOperator('{a} && {b} As Bool = a And b', uc.GetItemOf('And').Precedence());
      WriteLn(uc.EvalStr('1 > 0 && 2 > 0')); // Returns 'true';
      WriteLn(uc.EvalStr('1 > 2 && 2 > 0')); // Returns 'false';

          

cout << "The precedence level of the 'And' operator is: ";
cout << uc.GetItemOf("And").Precedence() << endl; // Returns 30;
uc.DefineOperator("{a} && {b} As Bool = a And b", uc.GetItemOf("And").Precedence());
cout << uc.EvalStr("1 > 0 && 2 > 0") << endl; // Returns "true";
cout << uc.EvalStr("1 > 2 && 2 > 0") << endl; // Returns "false";

          

Console::Write("The precedence level of the 'And' operator is: ");
Console::WriteLine(uc.GetItemOf("And").Precedence()); // Returns 30;
uc.DefineOperator("{a} && {b} As Bool = a And b", uc.GetItemOf("And").Precedence());
Console::WriteLine(uc.EvalStr("1 > 0 && 2 > 0")); // Returns "true";
Console::WriteLine(uc.EvalStr("1 > 2 && 2 > 0")); // Returns "false";

          
Example 6: Inspecting the parts of a syntax construct

uc.DefineSyntax("This {etc} ::= That")
' Note that the SkipExpansion arg is set to true for this Syntax construct
Console.WriteLine(uc.GetItemOf("This", 0, true).Text()) ' Returns "ChangeMulti ~~ Syntax: This {etc} ::= That"
Console.WriteLine(uc.GetItemOf("This", 0, true).ReplacementText()) ' Returns "That"

          

uc.DefineSyntax("This {etc} ::= That");
// Note that the SkipExpansion arg is set to true for this Syntax construct
Console.WriteLine(uc.GetItemOf("This", 0, true).Text()); // Returns "ChangeMulti ~~ Syntax: This {etc} ::= That";
Console.WriteLine(uc.GetItemOf("This", 0, true).ReplacementText()); // Returns "That";

          

      uc.DefineSyntax('This {etc} ::= That');
      // Note that the SkipExpansion arg is set to true for this Syntax construct
      WriteLn(uc.GetItemOf('This', 0, true).Text()); // Returns 'ChangeMulti ~~ Syntax: This {etc} ::= That';
      WriteLn(uc.GetItemOf('This', 0, true).ReplacementText()); // Returns 'That';

          

uc.DefineSyntax("This {etc} ::= That");
// Note that the SkipExpansion arg is set to true for this Syntax construct
cout << uc.GetItemOf("This", 0, true).Text() << endl; // Returns "ChangeMulti ~~ Syntax: This {etc} ::= That";
cout << uc.GetItemOf("This", 0, true).ReplacementText() << endl; // Returns "That";

          

uc.DefineSyntax("This {etc} ::= That");
// Note that the SkipExpansion arg is set to true for this Syntax construct
Console::WriteLine(uc.GetItemOf("This", 0, true).Text()); // Returns "ChangeMulti ~~ Syntax: This {etc} ::= That";
Console::WriteLine(uc.GetItemOf("This", 0, true).ReplacementText()); // Returns "That";

          
Example 7: 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()) ' Returns "Elements in MyArrayA: 5"
Console.WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount()) ' Returns "Elements in MyArrayB: 15"
Console.WriteLine("Params in FuncA(): " + FunctionA.ElementCount()) ' Returns "Params in FuncA(): 3"
Console.WriteLine("Params in FuncB(): " + FunctionB.ElementCount()) ' Returns "Params in FuncB(): 4"
Console.WriteLine("Params in FuncC(): " + FunctionC.ElementCount()) ' Returns "Params in FuncC(): -1"
Console.WriteLine("Params in FuncD(): " + FunctionD.ElementCount()) ' Returns "Params in FuncD(): 0"
Console.WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount()) ' Returns "Operands in ! operator: 1"
Console.WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount()) ' Returns "Operands in > operator: 2"
Console.WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount()) ' Returns "Params in SyntaxA: 0"
Console.WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount()) ' Returns "Params in SyntaxB: 2"

          

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()); // Returns "Elements in MyArrayA: 5";
Console.WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount()); // Returns "Elements in MyArrayB: 15";
Console.WriteLine("Params in FuncA(): " + FunctionA.ElementCount()); // Returns "Params in FuncA(): 3";
Console.WriteLine("Params in FuncB(): " + FunctionB.ElementCount()); // Returns "Params in FuncB(): 4";
Console.WriteLine("Params in FuncC(): " + FunctionC.ElementCount()); // Returns "Params in FuncC(): -1";
Console.WriteLine("Params in FuncD(): " + FunctionD.ElementCount()); // Returns "Params in FuncD(): 0";
Console.WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount()); // Returns "Operands in ! operator: 1";
Console.WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount()); // Returns "Operands in > operator: 2";
Console.WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount()); // Returns "Params in SyntaxA: 0";
Console.WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount()); // Returns "Params in SyntaxB: 2";

          

//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 ...)', MyAverageCB);
//var FunctionD = uc.DefineFunction('FuncD() = 1+1');
//var SyntaxA = uc.DefineSyntax('This ::= That');
//var SyntaxB = uc.DefineSyntax('This {etc} and {more} ::= Whatever({etc})');

         WriteLn('Elements in MyArrayA: ' + MyArrayA.ElementCount()); // Returns 'Elements in MyArrayA: 5';
         WriteLn('Elements in MyArrayB: ' + MyArrayB.ElementCount()); // Returns 'Elements in MyArrayB: 15';
         WriteLn('Params in FuncA(): ' + FunctionA.ElementCount()); // Returns 'Params in FuncA(): 3';
         WriteLn('Params in FuncB(): ' + FunctionB.ElementCount()); // Returns 'Params in FuncB(): 4';
         WriteLn('Params in FuncC(): ' + FunctionC.ElementCount()); // Returns 'Params in FuncC(): -1';
         WriteLn('Params in FuncD(): ' + FunctionD.ElementCount()); // Returns 'Params in FuncD(): 0';
         WriteLn('Operands in ! operator: ' + uc.GetItemOf('!').ElementCount()); // Returns 'Operands in ! operator: 1';
         WriteLn('Operands in > operator: ' + uc.GetItemOf('>').ElementCount()); // Returns 'Operands in > operator: 2';
         WriteLn('Params in SyntaxA: ' + SyntaxA.ElementCount()); // Returns 'Params in SyntaxA: 0';
         WriteLn('Params in SyntaxB: ' + SyntaxB.ElementCount()); // Returns 'Params in SyntaxB: 2';

          

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; // Returns "Elements in MyArrayA: 5";
cout << "Elements in MyArrayB: " << MyArrayB.ElementCount() << endl; // Returns "Elements in MyArrayB: 15";
cout << "Params in FuncA(): " << FunctionA.ElementCount() << endl; // Returns "Params in FuncA(): 3";
cout << "Params in FuncB(): " << FunctionB.ElementCount() << endl; // Returns "Params in FuncB(): 4";
cout << "Params in FuncC(): " << FunctionC.ElementCount() << endl; // Returns "Params in FuncC(): -1";
cout << "Params in FuncD(): " << FunctionD.ElementCount() << endl; // Returns "Params in FuncD(): 0";
cout << "Operands in ! operator: " << uc.GetItemOf("!").ElementCount() << endl; // Returns "Operands in ! operator: 1";
cout << "Operands in > operator: " << uc.GetItemOf(">").ElementCount() << endl; // Returns "Operands in > operator: 2";
cout << "Params in SyntaxA: " << SyntaxA.ElementCount() << endl; // Returns "Params in SyntaxA: 0";
cout << "Params in SyntaxB: " << SyntaxB.ElementCount() << endl; // Returns "Params in SyntaxB: 2";

          

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()); // Returns "Elements in MyArrayA: 5";
Console::WriteLine("Elements in MyArrayB: " + MyArrayB.ElementCount()); // Returns "Elements in MyArrayB: 15";
Console::WriteLine("Params in FuncA(): " + FunctionA.ElementCount()); // Returns "Params in FuncA(): 3";
Console::WriteLine("Params in FuncB(): " + FunctionB.ElementCount()); // Returns "Params in FuncB(): 4";
Console::WriteLine("Params in FuncC(): " + FunctionC.ElementCount()); // Returns "Params in FuncC(): -1";
Console::WriteLine("Params in FuncD(): " + FunctionD.ElementCount()); // Returns "Params in FuncD(): 0";
Console::WriteLine("Operands in ! operator: " + uc.GetItemOf("!").ElementCount()); // Returns "Operands in ! operator: 1";
Console::WriteLine("Operands in > operator: " + uc.GetItemOf(">").ElementCount()); // Returns "Operands in > operator: 2";
Console::WriteLine("Params in SyntaxA: " + SyntaxA.ElementCount()); // Returns "Params in SyntaxA: 0";
Console::WriteLine("Params in SyntaxB: " + SyntaxB.ElementCount()); // Returns "Params in SyntaxB: 2";

          
Example 8: Renames the Cos function (which is in Radian) to CosR and defines Cos in Degrees

uc.DefineConstant("pi = Atan(1) * 4")

' Original Cos behavior with Radian
Console.WriteLine(uc.Eval("Cos(pi)")) ' Returns -1
Console.WriteLine(uc.Eval("Cos(180)")) ' Returns -0.59846

' Cos is renamed to CosR so that Cos can now be defined in Degree
uc.GetItemOf("Cos").Rename("CosR")
uc.DefineFunction("Cos(x) = CosR(x*pi/180)")

' Now Cos is in Degree
Console.WriteLine(uc.Eval("Cos(pi)")) ' Returns 0.998497
Console.WriteLine(uc.Eval("Cos(180)")) ' Returns -1

' This is the original function now named CosR
Console.WriteLine(uc.Eval("CosR(pi)")) ' Returns -1
Console.WriteLine(uc.Eval("CosR(180)")) ' Returns -0.59846
' Note: Some functions may be overloaded, such as the Cos function in
' this example, which has a definition for Double and another for Complex.
' This example renames only the Double precision version.

          

uc.DefineConstant("pi = Atan(1) * 4");

// Original Cos behavior with Radian
Console.WriteLine(uc.Eval("Cos(pi)")); // Returns -1;
Console.WriteLine(uc.Eval("Cos(180)")); // Returns -0.59846;

// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.GetItemOf("Cos").Rename("CosR");
uc.DefineFunction("Cos(x) = CosR(x*pi/180)");

// Now Cos is in Degree
Console.WriteLine(uc.Eval("Cos(pi)")); // Returns 0.998497;
Console.WriteLine(uc.Eval("Cos(180)")); // Returns -1;

// This is the original function now named CosR
Console.WriteLine(uc.Eval("CosR(pi)")); // Returns -1;
Console.WriteLine(uc.Eval("CosR(180)")); // Returns -0.59846;
// Note: Some functions may be overloaded, such as the Cos function in
// this example, which has a definition for Double and another for Complex.
// This example renames only the Double precision version.

//+++E: Temp - Using Overwrite to ..
uc.Define("Overwrite ~~ Function: ");

          

         uc.DefineConstant('pi = Atan(1) * 4');

         // Original Cos behavior with Radian
         WriteLn(uc.Eval('Cos(pi)')); // Returns -1;
         WriteLn(uc.Eval('Cos(180)')); // Returns -0.59846;

         // Cos is renamed to CosR so that Cos can now be defined in Degree
         uc.GetItemOf('Cos').Rename('CosR');
         uc.DefineFunction('Cos(x) = CosR(x*pi/180)');

         // Now Cos is in Degree
         WriteLn(uc.Eval('Cos(pi)')); // Returns 0.998497;
         WriteLn(uc.Eval('Cos(180)')); // Returns -1;

         // This is the original Function_ now named CosR
         WriteLn(uc.Eval('CosR(pi)')); // Returns -1;
         WriteLn(uc.Eval('CosR(180)')); // Returns -0.59846;
         // Note: Some functions may be overloaded, such as the Cos Function_ in
         // this example, which has a definition for Double and another for Complex.
         // This example renames only the Double precision version.

          

uc.DefineConstant("pi = Atan(1) * 4");

// Original Cos behavior with Radian
cout << uc.Eval("Cos(pi)") << endl; // Returns -1;
cout << uc.Eval("Cos(180)") << endl; // Returns -0.59846;

// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.GetItemOf("Cos").Rename("CosR");
uc.DefineFunction("Cos(x) = CosR(x*pi/180)");

// Now Cos is in Degree
cout << uc.Eval("Cos(pi)") << endl; // Returns 0.998497;
cout << uc.Eval("Cos(180)") << endl; // Returns -1;

// This is the original function now named CosR
cout << uc.Eval("CosR(pi)") << endl; // Returns -1;
cout << uc.Eval("CosR(180)") << endl; // Returns -0.59846;
// Note: Some functions may be overloaded, such as the Cos function in
// this example, which has a definition for Double and another for Complex.
// This example renames only the Double precision version.

//+++E: Temp - Using Overwrite to ..
uc.Define("Overwrite ~~ Function: ");

          

uc.DefineConstant("pi = Atan(1) * 4");

// Original Cos behavior with Radian
Console::WriteLine(uc.Eval("Cos(pi)")); // Returns -1;
Console::WriteLine(uc.Eval("Cos(180)")); // Returns -0.59846;

// Cos is renamed to CosR so that Cos can now be defined in Degree
uc.GetItemOf("Cos").Rename("CosR");
uc.DefineFunction("Cos(x) = CosR(x*pi/180)");

// Now Cos is in Degree
Console::WriteLine(uc.Eval("Cos(pi)")); // Returns 0.998497;
Console::WriteLine(uc.Eval("Cos(180)")); // Returns -1;

// This is the original function now named CosR
Console::WriteLine(uc.Eval("CosR(pi)")); // Returns -1;
Console::WriteLine(uc.Eval("CosR(180)")); // Returns -0.59846;
// Note: Some functions may be overloaded, such as the Cos function in
// this example, which has a definition for Double and another for Complex.
// This example renames only the Double precision version.

//+++E: Temp - Using Overwrite to ..
uc.Define("Overwrite ~~ Function: ");

          
Example 9: Dealing with various data types in a callback

Sub MyFunctionCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Dim ucc = ExprPart.GetuCalc()

   Console.WriteLine(ExprPart.ArgInt32(1)) ' Returns 1230
   Console.WriteLine(ExprPart.ArgInt64(2)) ' Returns 2

   Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))) ' Returns -1
   Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))) ' Returns 123
End Sub

Sub MyFunctionCallback()
   uc.DefineVariable("x As Int = 123")
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)")
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", uc.PinAddr(AddressOf MyFunctionCB))
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)")
End Sub

          

static void MyFunctionCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   var ucc = ExprPart.GetuCalc();
   
   Console.WriteLine(ExprPart.ArgInt32(1)); // Returns 1230;
   Console.WriteLine(ExprPart.ArgInt64(2)); // Returns 2;
   
   Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
}

static void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", uc.PinAddr(MyFunctionCB));
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

          

procedure MyFunctionCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
//var ucc = ExprPart.GetuCalc();

   WriteLn(ExprPart.ArgInt32(1)); // Returns 1230;
   WriteLn(ExprPart.ArgInt64(2)); // Returns 2;

   WriteLn(ucc.GetItemOf('Int8').GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   WriteLn(ucc.GetItemOf('Int').GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
End;

procedure MyFunctionCallback();
begin
   
   uc.DefineVariable('x As Int = 123');
   uc.DefineVariable('xPtr As Int Ptr = AddressOf(x)');
   uc.DefineFunction('MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)', MyFunctionCB);
   uc.Eval('MyFunc(x*10, 1+1, 255, xPtr)');
End;

          

void _stdcall MyFunctionCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   auto ucc = ExprPart.GetuCalc();
   
   cout << ExprPart.ArgInt32(1) << endl; // Returns 1230;
   cout << ExprPart.ArgInt64(2) << endl; // Returns 2;
   
   cout << ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)) << endl; // Returns -1;
   cout << ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)) << endl; // Returns 123;
}

void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunctionCB);
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

          

static void MyFunctionCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   auto ucc = ExprPart.GetuCalc();
   
   Console::WriteLine(ExprPart.ArgInt32(1)); // Returns 1230;
   Console::WriteLine(ExprPart.ArgInt64(2)); // Returns 2;
   
   Console::WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   Console::WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
}

static void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", ucPinAddr(MyFunctionCB));
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="GetItemOf")> _

Private Function GetItemOf__(ByVal uCalcHandle As IntPtr,ByVal ItemName As String , ByVal Properties As Int64  , ByVal SkipExpansion As Int32  ) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="GetItemOf")]

protected static extern IntPtr GetItemOf_(IntPtr uCalcHandle, string ItemName ,  Int64 Properties  ,  bool SkipExpansion  );
            
{DLLImport}function GetItemOf__(uCalcHandle: System.Pointer;ItemName: AnsiString ; Properties: Int64  ; SkipExpansion: Integer): System.Pointer; cdecl; external uCalcDLL name 'GetItemOf';

            
typedef uCalcPtr (* __GetItemOf)(void *uCalcHandle, CONSTCHAR ItemName  ,  int64_t Properties  ,  bool SkipExpansion  ); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "GetItemOf")]

static uCalcPtr GetItemOf_(void *  uCalcHandle, MARSHALSTR ItemName  ,  Int64 Properties  ,  bool SkipExpansion);
            
See also
Prev | Next