getType()

Query of the data type of any Control expression.

Synopsis

int getType(expression);

Parameters

Parameter Description
expression Control expression to be examined

Return value

If the CONTROL expression is of the examined data type, the function returns the data type as an integer constant. Otherwise it returns 0.

Description

The data type of any CONTROL expression can be queried with the function getType(). The following constants are available for this:

The following constants are also available for querying the data type of CONTROL expressions:

Integer constant Description
ANYTYPE_VAR Type anytype before the first assignment
DYN_ANYTYPE_VAR Dynamic field with elements of any data type
DYN_DYN_ANYTYPE_VAR Dynamic field from dynamic fields of elements of any data type
DYN_DYN_BIT32_VAR Dynamic field dyn. bit pattern fields
DYN_DYN_BOOL_VAR Dynamic field dyn. bit fields
DYN_DYN_BLOB_VAR Dynamic field dyn blob fields
DYN_DYN_CHAR_VAR Dynamic field of dynamic character fields
DYN_DYN_DPIDENTIFIER_VAR Dynamic field of dynamic identifier fields
DYN_DYN_ERRCLASS_VAR Dynamic field of error classes
DYN_DYN_FLOAT_VAR Dynamic field dyn. floating-point number fields
DYN_DYN_INT_VAR Dynamic field dyn. bit integer fields
DYN_DYN_LANGSTRING_VAR Dynamic field dyn. multilingual texts
DYN_DYN_STRING_VAR Dynamic field dyn. bit pattern fields
DYN_DYN_TIME_VAR Dynamic field dyn. time fields
DYN_DYN_UINT_VAR Dynamic field of dyn. fields of positive integers
DYN_ERRCLASS_VAR Dyn. error classes
DYN_DYN_MAPPING_VAR Dynamic field of dynamic mapping fields
DYN_DYN_MIXED_VAR Dynamic field of dynamic mixed fields
ERRCLASS_VAR Error classes

When this function is used for anytype or shared_ptr, they are dereferenced and then the type is evaluated. In case they do not contain or point at any other variable, their own type is used.

Example

The function checks the data types of the variables a, b and c and outputs these types as well as compares the types with FLOAT_VAR and STRING_VAR. If the data type is the expected one, the example outputs "correct" and if it is a wrong type, it outputs "wrong".

main(mapping event)
{
  int a = 1;
  float b = 2.5;
  string c = "4";

  DebugTN(INT_VAR, FLOAT_VAR, STRING_VAR);

  DebugTN("___Results___");

  DebugTN("a", getType(a), "Expected " + INT_VAR);
  DebugTN("b", getType(b), "Expected " + FLOAT_VAR);
  DebugTN("c", getType(c), "Expected " + STRING_VAR);
  DebugTN("a+b", getType(a + b), "Expected " + FLOAT_VAR);
  DebugTN("a+c", getType(a + c), "Expected " + STRING_VAR);
  DebugTN("b+c", getType(b + c), "Expected " + STRING_VAR);

 if( getType(a + c) == STRING_VAR)
  {
    DebugTN("correct");
  }
  else
  {
    DebugTN("wrong");
  }
}

The function outputs:

WCCOAui1:2017.08.31 12:36:34.489[327680][458752][524288]

WCCOAui1:2017.08.31 12:36:34.489["___Results___"]

WCCOAui1:2017.08.31 12:36:34.489["a"][327680]["Expected 327680"]

WCCOAui1:2017.08.31 12:36:34.489["b"][458752]["Expected 458752"]

WCCOAui1:2017.08.31 12:36:34.489["c"][524288]["Expected 524288"]

WCCOAui1:2017.08.31 12:36:34.489["a+b"][458752]["Expected 458752"]

WCCOAui1:2017.08.31 12:36:34.489["a+c"][524288]["Expected 524288"]

WCCOAui1:2017.08.31 12:36:34.489["b+c"][524288]["Expected 524288"]

WCCOAui1:2017.08.31 12:36:34.489["correct"]

Assignment

Miscellaneous functions

Availability

CTRL