Mercurial > hg > octave-jordi
diff libinterp/octave-value/ov-struct.cc @ 20938:b17fda023ca6
maint: Use new C++ archetype in more files.
Place input validation first in files.
Move declaration of retval down in function to be closer to point of usage.
Eliminate else clause after if () error.
Use "return ovl()" where it makes sense.
* find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc,
graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc,
load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc,
ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc,
rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc,
strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc,
syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc,
__glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc,
symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc,
ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc:
Use new C++ archetype in more files.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 18 Dec 2015 15:37:22 -0800 (2015-12-18) |
parents | 384ff5aa9437 |
children | 072559bd31f2 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -1845,7 +1845,7 @@ if (args.length () != 1) print_usage (); - return octave_value (args(0).is_map ()); + return ovl (args(0).is_map ()); } DEFUN (__fieldnames__, args, , @@ -1887,12 +1887,10 @@ @seealso{fieldnames}\n\ @end deftypefn") { - octave_value retval; - if (args.length () != 2) print_usage (); - retval = false; + octave_value retval = false; if (args(0).is_map ()) { @@ -1900,7 +1898,6 @@ // FIXME: should this work for all types that can do // structure reference operations? - if (args(1).is_string ()) { std::string key = args(1).string_value (); @@ -1939,17 +1936,13 @@ @seealso{fieldnames}\n\ @end deftypefn") { - octave_value retval; - if (args.length () != 1) print_usage (); - if (args(0).is_map ()) - retval = static_cast<double> (args(0).nfields ()); - else + if (! args(0).is_map ()) error ("numfields: argument must be a struct"); - return retval; + return ovl (static_cast<double> (args(0).nfields ())); } /* @@ -1992,8 +1985,6 @@ @seealso{struct2cell, cell2mat, struct}\n\ @end deftypefn") { - octave_value retval; - int nargin = args.length (); if (nargin < 2 || nargin > 3) @@ -2005,11 +1996,6 @@ if (! (args(1).is_cellstr () || args(1).is_char_matrix ())) error ("cell2struct: FIELDS must be a cell array of strings or a character matrix"); - const Cell vals = args(0).cell_value (); - const Array<std::string> fields = args(1).cellstr_value (); - - octave_idx_type ext = 0; - int dim = 0; if (nargin == 3) @@ -2023,7 +2009,10 @@ if (dim < 0) error ("cell2struct: DIM must be a valid dimension"); - ext = vals.ndims () > dim ? vals.dims ()(dim) : 1; + const Cell vals = args(0).cell_value (); + const Array<std::string> fields = args(1).cellstr_value (); + + octave_idx_type ext = vals.ndims () > dim ? vals.dims ()(dim) : 1; if (ext != fields.numel ()) error ("cell2struct: number of FIELDS does not match dimension"); @@ -2055,9 +2044,7 @@ map.setfield (fields(i), vals.index (ia).reshape (rdv)); } - retval = map; - - return retval; + return ovl (map); } /* @@ -2093,8 +2080,6 @@ @seealso{orderfields, fieldnames, isfield}\n\ @end deftypefn") { - octave_value retval; - if (args.length () != 2) print_usage (); @@ -2114,9 +2099,7 @@ error ("rmfield: structure does not contain field %s", key.c_str ()); } - retval = m; - - return retval; + return ovl (m); } /*