classdef (Sealed) TET < handle
    %TET provides the global settings for the Tabular Expression Toolbox
    %   TET provides the system through which all global settings are
    %   accssed and changed.  It also provides a convient place for some
    %   globals used in the TET.

    properties (Access = private)
        variableParser = ca.mcscert.jtet.parsers.VariableParser
    end

    methods
        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.EnumerationType(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)
        function obj = TET
        end
    end
    methods (Static)
      function singleObj = getInstance
         persistent localObj
         if isempty(localObj) || ~isvalid(localObj)
            localObj = TET;
         end
         singleObj = localObj;
      end
   end

end

