GetDataTypeMethod

Applies to:Fast Math Parser
Class:uCalc.Item
Returns the data type of a uCalc.Item
Syntax
GetDataType()
Remarks
The returned data type object can be used to determine the type name, size, etc.
Example 1: Displaying the data type name and size of a variable

Dim MyVariable = uc.DefineVariable("MyVariable")
Console.WriteLine("MyVariable type: " + MyVariable.GetDataType().Name()) ' Returns "MyVariable type: double"
Console.WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize()) ' Returns "MyVariable size: 8"

          

var MyVariable = uc.DefineVariable("MyVariable");
Console.WriteLine("MyVariable type: " + MyVariable.GetDataType().Name()); // Returns "MyVariable type: double";
Console.WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize()); // Returns "MyVariable size: 8";

          

//var MyVariable = uc.DefineVariable('MyVariable');
      WriteLn('MyVariable type: ' + MyVariable.GetDataType().Name()); // Returns 'MyVariable type: double';
      WriteLn('MyVariable size: ' + MyVariable.GetDataType().ByteSize()); // Returns 'MyVariable size: 8';

          

auto MyVariable = uc.DefineVariable("MyVariable");
cout << "MyVariable type: " << MyVariable.GetDataType().Name() << endl; // Returns "MyVariable type: double";
cout << "MyVariable size: " << MyVariable.GetDataType().ByteSize() << endl; // Returns "MyVariable size: 8";

          

auto MyVariable = uc.DefineVariable("MyVariable");
Console::WriteLine("MyVariable type: " + MyVariable.GetDataType().Name()); // Returns "MyVariable type: double";
Console::WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize()); // Returns "MyVariable size: 8";

          
Example 2: 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 3: Displaying the data types of arguments when the data types are not known in advance

Sub DisplayArgsCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Dim x As Int32
   for x = 1 To ExprPart.ArgCount()
      Console.WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name())
   Next
   ' Output
   ' 5  Type: double
   ' 3+2i  Type: complex
   ' Hello  Type: string
   ' true  Type: bool
   ' false  Type: bool
   ' 9  Type: int16
End Sub

Sub DisplayArgs()
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", uc.PinAddr(AddressOf DisplayArgsCB))
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))")
End Sub

          

static void DisplayArgsCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   for (Int32 x = 1; x <= ExprPart.ArgCount(); x++) {
      Console.WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name());
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

static void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", uc.PinAddr(DisplayArgsCB));
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

          

procedure DisplayArgsCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   for x := 1 to ExprPart.ArgCount() do
begin
   WriteLn(ExprPart.ArgStr(x) + '  Type: ' + ExprPart.ArgObj(x).GetDataType().Name());
End;
   // Output
// 5  Type: double
// 3+2i  Type: complex
// Hello  Type: string
// true  Type: bool
// false  Type: bool
// 9  Type: int16

End;

procedure DisplayArgs();
begin
   
   uc.DefineFunction('DisplayArgs(Arg As AnyType ...)', DisplayArgsCB);
   uc.Eval('DisplayArgs(5, 3+2*#i, "Hello", True, False, Int16(5+4.1))');
End;

          

void _stdcall DisplayArgsCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      cout << ExprPart.ArgStr(x) << "  Type: " << ExprPart.ArgObj(x).GetDataType().Name() << endl;
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", DisplayArgsCB);
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

          

static void DisplayArgsCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      Console::WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name());
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

static void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", ucPinAddr(DisplayArgsCB));
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

          
Example 4: 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)");
}

          
Example 5: 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
   
}

          
Example 6: 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:="GetDataType")> _

Private Function GetDataType__(ByVal ItemHandle As IntPtr) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="GetDataType")]

protected static extern IntPtr GetDataType_(IntPtr ItemHandle);
            
{DLLImport}function GetDataType__(ItemHandle: System.Pointer): System.Pointer; cdecl; external uCalcDLL name 'GetDataType';

            
typedef uCalcPtr (* __GetDataType)(void *ItemHandle); 

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

static uCalcPtr GetDataType_(void *  ItemHandle);
            
Prev | Next