From 59ea261751d8b7635f1239335ccfeda271463dc0 Mon Sep 17 00:00:00 2001 From: Matthew Dawson Date: Fri, 5 Sep 2014 14:13:06 -0400 Subject: [PATCH] Add support for registering a Simulink Enumeration with jTET. To support enumerations, jTET needs to know about the contents of the enumeration. TET now provides a function to do show, taking in the name of an enumeration, and registering the various details with jTET automatically. --- TET.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/TET.m b/TET.m index 7204df2..020eed2 100644 --- a/TET.m +++ b/TET.m @@ -12,6 +12,35 @@ classdef (Sealed) TET < handle function variableParser = getVariableParser(obj) variableParser = obj.variableParser; end + + %% Register an enumeration type with the TET. + % + % This function registers a Simulink compatibile enumeration type + % with the TET. This allows the enumerated value to be used in + % tables. + % Note: the enumeration must derive from Simulink.IntEnumType + % to be used in the Simulink model. + % Note: each enumerated value must have a distinct value, + % otherwise the type checker may allow invalid tables. + % + % obj - This object + % enum - A string representing the enumeration type name. + function type = registerEnumeration(obj, enum) + enumValues = enumeration(enum); + [~, enumConstants] = enumeration(enum); + if size(enumValues, 1) ~= size(enumConstants, 1) + throw(MException('TET:registerEnumeration', ... + 'Enumeration constants share the same concrete value')); + end + + type = ca.mcscert.jtet.expression.EnumerationVariableType(enum); + typeEnumConstants = type.enumerationValues; + for i=1:size(enumConstants, 1) + java.lang.String(enumConstants{i}) + typeEnumConstants.add(java.lang.String(enumConstants{i})); + end + obj.variableParser.addCustomType(enum, type); + end end methods (Access = private) -- GitLab