function hobj=clone(obj)
% MATLAB Code Generation Library function.
% Implement clone function for unwrapped System objects.
% 
% Copyright 2015-2016 The MathWorks, Inc.
%#codegen

coder.inline('always');
coder.internal.allowEnumInputs;
coder.internal.allowHalfInputs;

eml_invariant(coder.const(isa(obj, 'matlab.system.SystemAdaptor')), ...
    'MATLAB:system:cloneFailed');

comp = eml_sea_get_obj(obj);
className = coder.const(class(comp)); 
coder.extrinsic('eml_try_catch');

eml_invariant(coder.const(feature('SystemObjectsCloneCodegen')), ...
           eml_message('MATLAB:system:cloneFailed'));
       
[~, ~,lockedSfun] = coder.const(@feval,'eml_try_catch','isLocked',comp);
eml_invariant(~lockedSfun, 'MATLAB:system:codeGenUnSupportedLockedClone');

hobjha = str2func(className);
hobj = hobjha();
clonedComp = eml_sea_get_obj(hobj);
coder.const(@feval,'eml_try_catch','matlab.system.coder.copyProps',clonedComp,comp);
