classdef NonCodeInfoData < rtw.pil.DataInterface
%NONCODEINFODATA Represents Non-CodeInfo data to be
%                transferred between host and target.

%   Copyright 2010-2019 The MathWorks, Inc.

    methods
        function this = NonCodeInfoData(dtypeId, dimensions, mf0ModelInstance) 
            assert(isa(dtypeId, 'rtw.connectivity.CodeInfoTypeEnum'), 'dtypeId must be an rtw.connectivity.CodeInfoTypeEnum');
            assert(isa(dimensions, 'double'), 'dimensions must be of type double');
            % map DTypeId and dimensions to embedded.type and            
            % call super class constructor                          
            
            numType = [];
            switch dtypeId
                case rtw.connectivity.CodeInfoTypeEnum.TypeDouble
                    numType = coder.types.Double;
                case rtw.connectivity.CodeInfoTypeEnum.TypeSingle
                    numType = coder.types.Single;
                case rtw.connectivity.CodeInfoTypeEnum.TypeInt8
                    numType = coder.types.Int(8,1);
                case rtw.connectivity.CodeInfoTypeEnum.TypeUInt8
                    numType = coder.types.Int(8,0);
                case rtw.connectivity.CodeInfoTypeEnum.TypeInt16
                    numType = coder.types.Int(16,1);
                case rtw.connectivity.CodeInfoTypeEnum.TypeUInt16
                    numType = coder.types.Int(16,0);
                case rtw.connectivity.CodeInfoTypeEnum.TypeInt32
                    numType = coder.types.Int(32,1);
                case rtw.connectivity.CodeInfoTypeEnum.TypeUInt32
                    numType = coder.types.Int(32,0);
                case rtw.connectivity.CodeInfoTypeEnum.TypeInt64
                    numType = coder.types.Int(64,1);
                case rtw.connectivity.CodeInfoTypeEnum.TypeUInt64
                    numType = coder.types.Int(64,0);
                case rtw.connectivity.CodeInfoTypeEnum.TypeBoolean
                    numType = coder.types.Bool;
                otherwise
                    rtw.connectivity.ProductInfo.error('target', 'SimulinkTypeUtilsUnknownTypeId', dtypeId);                        
            end            
            if ~isscalar(dimensions) || dimensions ~= 1
                type = coder.types.Matrix;
                type.BaseType = numType;   
                type.Dimensions = dimensions;                
            else
                type = numType;
            end         
            % create DataInterface
            GraphicalName = '';
            Implementation = RTW.DataImplementation.empty;
            Timing = RTW.TimingInterface.empty;            
            dataInterface = RTW.DataInterface('NonCodeInfoData', GraphicalName, Implementation, Timing);      
            dataInterface.Type = type;
            
            if ~isempty(mf0ModelInstance)
                % serialize the interface to MF0, better that creating the
                % interface from scratch as it preserves relations between
                % properties (i.e. Dimensions/SymbolicDimension/SymbolicWidth)
                dataInterface = dataInterface.serializeMF0(mf0ModelInstance);
            end
            
            this@rtw.pil.DataInterface(dataInterface);                  
            assert(length(this.getTargetDataElements) == 1, 'Non-CodeInfo data must have only a single data element.');            
        end  
        
        function type = getType(this)
           % for NonCodeInfoData, only process the DataInterface type, not the
           % Implementation type
           type = this.getRTWDataInterface.Type;           
        end                
                               
        function isBitFieldMember = isBitFieldMember(~, ~)
            % no support for bitfields
            isBitFieldMember = true;
        end 
        
        function isStructOptimizationAllowed = isStructOptimizationAllowed(~)
            isStructOptimizationAllowed = true;
        end
    end
end
