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:

Integer constant Description
ATIME_VAR Time of the alarm
BIT32_VAR Bit pattern
BOOL_VAR Bit
BLOB_VAR Blob (binary large object)
CHAR_VAR Character
DPIDENTIFIER_VAR Designation
DYN_BIT32_VAR Dyn. bit pattern field
DYN_BOOL_VAR Dyn. bit field
DYN_BLOB_VAR Dyn. Blob
DYN_CHAR_VAR Dyn. character field
DYN_DPIDENTIFIER_VAR Dyn. identifier field
DYN_FLOAT_VAR Dyn. floating-point field
DYN_INT_VAR Dyn. integer field
DYN_LANGSTRING_VAR Dyn. multilingual text
DYN_STRING_VAR Dyn. text field
DYN_TIME_VAR Dyn. time field
DYN_UINT_VAR Dyn. nat. field
DYN_ATIME_VAR Dyn. time of the alarm
DYN_DYN_ATIME_VAR Dynamic field dyn. time of the alarm
DYN_SHAPE_VAR Dyn. pointer for graphics elements
DYN_DYN_SHAPE_VAR Dynamic field dyn. pointer for graphics elements
VA_LIST_VAR An arbitrary number of parameters
FILE_VAR File variable
FLOAT_VAR Floating-point number
INT_VAR Integer
LANGSTRING_VAR Multilingual text
STRING_VAR Text
TIME_VAR Time
MIXED_VAR Mixed variable. Contrary to anytype, the variable type mixed gets each time a new type.
MAPPING_VAR

Mapping variable. Mappings save arbitrary key and value pairs. The keys and values are saved in two arrays (one for keys and one for values). A mapping with key:value pairs "one": 1, "two":2, "three":3 looks internally as follows:

key value

"one" 1

"two" 2

"three" 3.

DYN_MAPPING_VAR Dynamic mapping field
DYN_MIXED_VAR Dynamic mixed field (each mixed element can be of different data type).
UINT_VAR Natural number

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