Type inspection
The SPL code generation APIs include various type inspection functions,
which are supplied by the SPL::CodeGen::Type module.
These functions work on the type names that are returned by the
getSPLType methods that are provided by objects accessible from the
$model variable that represents the operator instance model. Some examples
include functions for querying traits of a type, such as isOrdered,
isNumeric, isFloatingpoint, and isOptional;
checking the exact value of a type, such as isBoolean, isInt16,
and isRString; and accessing information about subtypes within a composite type,
such as getElementType, getKeyType,
getAttributeTypes, and getUnderlyingType. The following is an
example that finds all floating point attribute names in a tuple type for a port.
<%
my $inputPort = $model->getInputPortAt(0);
my $tupleType = $inputPort->getSPLTupleType();
my @names = SPL::CodeGen::Type::getAttributeNames($tupleType);
my @types = SPL::CodeGen::Type::getAttributeTypes($tupleType);
my @floatingPointAttributes;
for (my $i = 0; $i < scalar(@names); ++$i) {
if(SPL::CodeGen::Type::isFloatingpoint($types[$i])) {
push @floatingPointAttributes, $names[$i];
}
}
%>