Skip to content

Commit

Permalink
[Matlab] Eliminate unnecessary copy-constructor-like option
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Feb 4, 2019
1 parent 9f5dfbd commit 35be561
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 74 deletions.
21 changes: 3 additions & 18 deletions interfaces/matlab/toolbox/@Kinetics/Kinetics.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
% a reaction mechanism.
%
% :param r:
% If ``r`` is an instance of class :mat:func:`Kinetics`, a copy of the instance
% is returned. In this case, ``r`` should be the only argument. Otherwise, ``r``
% must be an instance of class :mat:func:`XML_Node`.
% An instance of class :mat:func:`XML_Node`.
% :param ph:
% If ``r`` is an instance of :mat:func:`XML_Node`, ``ph`` is an instance of class
% :mat:func:`ThermoPhase`. Otherwise, optional.
% An instance of class :mat:func:`ThermoPhase`.
% :param neighbor1:
% Instance of class :mat:func:`ThermoPhase` or :mat:func:`Solution` representing a
% neighboring phase.
Expand All @@ -38,19 +35,7 @@
ineighbor3 = -1;
ineighbor4 = -1;

% if only one argument is supplied, and it is an instance of
% 'Kinetics', return a copy of this instance
if nargin == 1
if isa(r, 'Kinetics')
k = r;
return
else
error('wrong number of arguments')
end
end

% if more than one argument, first one must be an XML_Node
% instance representing the XML tree
% First argument must be an XML_Node instance representing the XML tree
if ~isa(r, 'XML_Node')
error('first argument must be an XML_Node object')
end
Expand Down
31 changes: 10 additions & 21 deletions interfaces/matlab/toolbox/@ThermoPhase/ThermoPhase.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@
% THERMOPHASE ThermoPhase class constructor.
% t = ThermoPhase(r)
% :param r:
% If ``r`` is an instance of class :mat:func:`ThermoPhase`,
% a copy of the instance is returned. Otherwise, ``r`` must
% be an instance of class :mat:func:`XML_Node`.
% An instance of class :mat:func:`XML_Node`.
% :return:
% Instance of class :mat:func:`ThermoPhase`
%

if nargin == 1
if isa(r, 'ThermoPhase')
% create a copy
t = r;
return
elseif isa(r, 'XML_Node')
t.owner = 1;
hr = xml_hndl(r);
t.tp_id = thermo_get(hr, 0);
if t.tp_id < 0
error(geterr);
end
else
t.owner = 0;
t.tp_id = r;
end
t = class(t, 'ThermoPhase');
else
if nargin ~= 1
error('ThermoPhase expects 1 input argument.');
end

t.owner = 1;
hr = xml_hndl(r);
t.tp_id = thermo_get(hr, 0);
if t.tp_id < 0
error(geterr);
end
t = class(t, 'ThermoPhase');
56 changes: 21 additions & 35 deletions interfaces/matlab/toolbox/@Transport/Transport.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
function tr = Transport(r, th, model, loglevel)
% TRANSPORT Transport class constructor.
% tr = Transport(r, th, model, loglevel)
% Create a new instance of class :mat:func:`Transport`. One, three,
% or four arguments may be supplied. If one argument is given,
% it must be an instance of class :mat:func:`Transport`, and
% a copy will be returned. If three or four arguments are given,
% the first two must be an instance of class :mat:func:`XML_Node`
% Create a new instance of class :mat:func:`Transport`. Three or four arguments
% may be supplied. The first two must be an instance of class:mat:func:`XML_Node`
% and an instance of class :mat:func:`ThermoPhase` respectively.
% The third argument is the type of modeling desired, specified
% by the string ``'default'``, ``'Mix'`` or ``'Multi'``.
Expand All @@ -14,8 +11,7 @@
% the logging level desired.
%
% :param r:
% Either an instance of class :mat:func:`Transport` or an
% instance of class :mat:func:`XML_Node`
% An instance of class :mat:func:`XML_Node`
% :param th:
% Instance of class :mat:func:`ThermoPhase`
% :param model:
Expand All @@ -28,35 +24,25 @@
%

tr.id = 0;
if nargin == 1
if isa(r, 'Transport')
tr = r;
else
error(['Unless the first argument is an instance of class ' ...
'Transport, there must be more than one argument'])
end
if nargin == 3
loglevel = 4;
end
if ~isa(r, 'XML_Node')
error(['The first argument must be an instance of class XML_Node'])
elseif ~isa(th, 'ThermoPhase')
error('The second argument must be an instance of class ThermoPhase')
else
if nargin == 3
loglevel = 4;
end
if ~isa(r, 'XML_Node')
error(['The first argument must either be an instance of class ' ...
'Transport or XML_Node'])
elseif ~isa(th, 'ThermoPhase')
error('The second argument must be an instance of class ThermoPhase')
else
tr.th = th;
if strcmp(model, 'default')
try
node = child(r, 'transport');
tr.model = attrib(node, 'model');
catch
tr.model = 'None';
end
else
tr.model = model;
tr.th = th;
if strcmp(model, 'default')
try
node = child(r, 'transport');
tr.model = attrib(node, 'model');
catch
tr.model = 'None';
end
tr.id = trans_get(thermo_hndl(th), -1, tr.model, loglevel) ;
tr = class(tr, 'Transport');
else
tr.model = model;
end
tr.id = trans_get(thermo_hndl(th), -1, tr.model, loglevel) ;
tr = class(tr, 'Transport');
end

0 comments on commit 35be561

Please sign in to comment.