function flag = createUniqueSComponent(dummysize,dummytype,dummyisreal,packageName,className,varargin)
%MATLAB Code Generation Library function.

%#codegen
%   Copyright 2002-2016 The MathWorks, Inc.

coder.allowpcode('plain');
eml_allow_mx_inputs;
coder.internal.allowEnumInputs;
eml_transient;
coder.inline('always');

eml_invariant(nargin > 4, 'MATLAB:minrhs'); % At least 5 inputs
packageClassName = coder.const([packageName, '.', className]);

% Is this a valid System object?
eml_invariant(coder.const(feval('matlab.system.isSystemObjectName',packageClassName)), ...
           'MATLAB:system:codeGenNotValidSystemObjectName', packageClassName);

% Error if a System object doesn't support code generation
coder.extrinsic('matlab.system.isCodeGenSupported');
eml_invariant(coder.const(matlab.system.isCodeGenSupported(packageClassName, eml_option('SEA'))), ...
           'MATLAB:system:noCodegen', packageClassName);

coder.const(dummysize); % needed so that dummy is not ignored
coder.const(dummytype); % needed so that dummy is not ignored
coder.const(dummyisreal); % needed so that dummy is not ignored

% Check that arguments are constants, error out if they are not.
% Doing so here prevents the user from receiving a confusing error
% when the object is created, below.

coder.extrinsic('num2str');
for ix = 1:length(varargin)
    eml_invariant(eml_is_const(varargin{ix}),...
        'MATLAB:system:codeGenConstructorArgNotConst', coder.const(num2str(ix)));
end
[~, createErr, obj] = coder.const(@feval,'eml_try_catch',packageClassName, varargin{:});

eml_assert(isempty(createErr), createErr);

flag = eml_sea_set_obj(obj);

