From 35be561d99c4ee8f544db4016849d94bf26b4df6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 29 Jan 2019 15:30:17 -0500 Subject: [PATCH] [Matlab] Eliminate unnecessary copy-constructor-like option --- .../matlab/toolbox/@Kinetics/Kinetics.m | 21 +------ .../matlab/toolbox/@ThermoPhase/ThermoPhase.m | 31 +++------- .../matlab/toolbox/@Transport/Transport.m | 62 +++++++------------ 3 files changed, 37 insertions(+), 77 deletions(-) diff --git a/interfaces/matlab/toolbox/@Kinetics/Kinetics.m b/interfaces/matlab/toolbox/@Kinetics/Kinetics.m index 2112866d3..e086090ed 100644 --- a/interfaces/matlab/toolbox/@Kinetics/Kinetics.m +++ b/interfaces/matlab/toolbox/@Kinetics/Kinetics.m @@ -9,12 +9,9 @@ function k = Kinetics(r, ph, neighbor1, neighbor2, neighbor3, neighbor4) % 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. @@ -38,19 +35,7 @@ ineighbor2 = -1; 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 diff --git a/interfaces/matlab/toolbox/@ThermoPhase/ThermoPhase.m b/interfaces/matlab/toolbox/@ThermoPhase/ThermoPhase.m index 2bcefdbe1..cbc8ecb5c 100644 --- a/interfaces/matlab/toolbox/@ThermoPhase/ThermoPhase.m +++ b/interfaces/matlab/toolbox/@ThermoPhase/ThermoPhase.m @@ -2,30 +2,19 @@ function t = ThermoPhase(r) % 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'); diff --git a/interfaces/matlab/toolbox/@Transport/Transport.m b/interfaces/matlab/toolbox/@Transport/Transport.m index 6f80d486c..f0c26018a 100644 --- a/interfaces/matlab/toolbox/@Transport/Transport.m +++ b/interfaces/matlab/toolbox/@Transport/Transport.m @@ -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'``. @@ -14,8 +11,7 @@ function tr = Transport(r, th, model, loglevel) % 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: @@ -28,35 +24,25 @@ function tr = Transport(r, th, model, loglevel) % 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 -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; - end - tr.id = trans_get(thermo_hndl(th), -1, tr.model, loglevel) ; - tr = class(tr, 'Transport'); - 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 + 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; + end + tr.id = trans_get(thermo_hndl(th), -1, tr.model, loglevel) ; + tr = class(tr, 'Transport'); end