NameMethod

Applies to:Fast Math Parser
Class:uCalc.DataType
Returns the name of the data type
Syntax
Name()
Remarks
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: 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:="Name_Overload_DataType")> _

Private Function Name_Overload_DataType__(ByVal DataTypeHandle As IntPtr) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="Name_Overload_DataType")]

protected static extern  IntPtr Name_Overload_DataType_(IntPtr DataTypeHandle);
            
{DLLImport}function Name_Overload_DataType__(DataTypeHandle: System.Pointer):  PAnsiChar; cdecl; external uCalcDLL name 'Name_Overload_DataType';

            
typedef const char * (* __Name_Overload_DataType)(void *DataTypeHandle); 

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

static STR_RETURN Name_Overload_DataType_(void *  DataTypeHandle);
            
Prev | Next