OpItemMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Returns the function or operator Item of the current expression part
Syntax
OpItem()
Remarks
If several functions and/or operators are mapped to the same callback function, you can use this to let you determine which one is currently being called, based on properties you can check.
Example 1: 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)): ' 0 should work
   uc.EvalStr("AAA()")
   ' Output
   ' Name: aaa
   ' Data type: double
   ' Param count: 0
   ' Is Operator_? 0

   uc.EvalStr("BBB(9, 8, 7)")
   ' Output
   ' Name: bbb
   ' Data type: string
   ' Param count: 3
   ' Is Operator_? 0

   uc.EvalStr("5 CCC 4")
   ' Output
   ' Name: ccc
   ' Data type: Int32
   ' Param count: 2
   ' Is Operator_? 1
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)); // 0 should work
   uc.EvalStr("AAA()");
   // Output
   // Name: aaa
   // Data type: double
   // Param count: 0
   // Is operator? 0
   
   uc.EvalStr("BBB(9, 8, 7)");
   // Output
   // Name: bbb
   // Data type: string
   // Param count: 3
   // Is operator? 0
   
   uc.EvalStr("5 CCC 4");
   // Output
   // Name: ccc
   // Data type: Int32
   // Param count: 2
   // Is operator? 1
   
}

          

procedure OpItemTestCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   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); // 0 should work
   uc.EvalStr('AAA()');
   // Output
// Name: aaa
// Data type: double
// Param count: 0
// Is Operator_? 0

   uc.EvalStr('BBB(9, 8, 7)');
   // Output
// Name: bbb
// Data type: string
// Param count: 3
// Is Operator_? 0

   uc.EvalStr('5 CCC 4');
   // Output
// Name: ccc
// Data type: Int32
// Param count: 2
// Is Operator_? 1

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); // 0 should work
   uc.EvalStr("AAA()");
   // Output
   // Name: aaa
   // Data type: double
   // Param count: 0
   // Is operator? 0
   
   uc.EvalStr("BBB(9, 8, 7)");
   // Output
   // Name: bbb
   // Data type: string
   // Param count: 3
   // Is operator? 0
   
   uc.EvalStr("5 CCC 4");
   // Output
   // Name: ccc
   // Data type: int
   // Param count: 2
   // Is operator? 1
   
}

          

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)); // 0 should work
   uc.EvalStr("AAA()");
   // Output
   // Name: aaa
   // Data type: double
   // Param count: 0
   // Is operator? 0
   
   uc.EvalStr("BBB(9, 8, 7)");
   // Output
   // Name: bbb
   // Data type: string
   // Param count: 3
   // Is operator? 0
   
   uc.EvalStr("5 CCC 4");
   // Output
   // Name: ccc
   // Data type: int
   // Param count: 2
   // Is operator? 1
   
}

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

Private Function OpItem__(ByVal ExprPartHandle As IntPtr) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="OpItem")]

protected static extern IntPtr OpItem_(IntPtr ExprPartHandle);
            
{DLLImport}function OpItem__(ExprPartHandle: System.Pointer): System.Pointer; cdecl; external uCalcDLL name 'OpItem';

            
typedef uCalcPtr (* __OpItem)(void *ExprPartHandle); 

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

static uCalcPtr OpItem_(void *  ExprPartHandle);
            
Prev | Next