Mercurial > hg > octave-nkf
changeset 18606:fcd87f68af4f
Deprecate nfields and replace with numfields.
* NEWS: Announce deprecation of nfields and addition of new function numfields.
* container.txi: Add numfields to the manual.
* oct-map.cc (octave_map::cat): Change %!tests to use numfields.
* ov-struct.cc (Fnumfields): Function renamed from nfields.
* scripts/deprecated/nfields.m: Add m-file which warns about nfields deprecation.
* scripts/deprecated/module.mk: Add nfields.m to build system.
* fieldnames.m: Change seealso link to point to numfields.
* __isequal__.m: Use numfields to simplify code.
* imwrite.m: Replace 'isempty (fieldnames (fmt))' with 'numfields (fmt) > 0'
for clarity.
* imageIO.m: Replace 'isempty (fieldnames (fmt))' with 'numfields (fmt) > 0'
for clarity.
* importdata.m: Use numfields to simplify code.
* assert.m: Use numfields to simplify code.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 02 Mar 2014 12:56:11 -0800 |
parents | f958e8cd6348 |
children | 7b60d0d9f0f2 |
files | NEWS doc/interpreter/container.txi libinterp/corefcn/oct-map.cc libinterp/octave-value/ov-struct.cc scripts/deprecated/module.mk scripts/deprecated/nfields.m scripts/general/fieldnames.m scripts/general/private/__isequal__.m scripts/image/imwrite.m scripts/image/private/imageIO.m scripts/io/importdata.m scripts/testfun/assert.m |
diffstat | 12 files changed, 69 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -4,9 +4,17 @@ ** Other new functions added in 4.2: dir_in_loadpath + numfields ** Deprecated functions. + The following functions have been deprecated in Octave 4.2 and will + be removed from Octave 4.6 (or whatever version is the second major + release after 4.2): + + find_dir_in_path + nfields + The following functions were deprecated in Octave 3.8 and have been removed from Octave 4.2. @@ -19,14 +27,6 @@ java_get read_readline_init_file java_invoke saving_history - - The following functions have been deprecated in Octave 4.2 and will - be removed from Octave 4.6 (or whatever version is the second major - release after 4.2): - - find_dir_in_path - - The following keywords were deprecated in Octave 3.8 and have been removed from Octave 4.2
--- a/doc/interpreter/container.txi +++ b/doc/interpreter/container.txi @@ -507,7 +507,7 @@ Other functions that can manipulate the fields of a structure are given below. -@DOCSTRING(nfields) +@DOCSTRING(numfields) @DOCSTRING(fieldnames)
--- a/libinterp/corefcn/oct-map.cc +++ b/libinterp/corefcn/oct-map.cc @@ -811,9 +811,9 @@ %! sr = [s,s]; %! sc = [s;s]; %! sm = [s,s;s,s]; -%! assert (nfields (sr), 0); -%! assert (nfields (sc), 0); -%! assert (nfields (sm), 0); +%! assert (numfields (sr), 0); +%! assert (numfields (sc), 0); +%! assert (numfields (sm), 0); %! assert (size (sr), [1, 2]); %! assert (size (sc), [2, 1]); %! assert (size (sm), [2, 2]);
--- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -2066,9 +2066,9 @@ return retval; } -DEFUN (nfields, args, , +DEFUN (numfields, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} nfields (@var{s})\n\ +@deftypefn {Built-in Function} {} numfields (@var{s})\n\ Return the number of fields of the structure @var{s}.\n\ @seealso{fieldnames}\n\ @end deftypefn")
--- a/scripts/deprecated/module.mk +++ b/scripts/deprecated/module.mk @@ -2,7 +2,8 @@ deprecated_FCN_FILES = \ deprecated/find_dir_in_path.m \ - deprecated/isstr.m + deprecated/isstr.m \ + deprecated/nfields.m FCN_FILES += $(deprecated_FCN_FILES)
new file mode 100644 --- /dev/null +++ b/scripts/deprecated/nfields.m @@ -0,0 +1,44 @@ +## Copyright (C) 2014 Rik Wehbring +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} nfields (@var{s}) +## Return the number of fields of the structure @var{s}. +## +## @strong{Warning:} @code{nfields} is scheduled for removal in version 4.6. +## Use @code{numfields} instead. +## @seealso{numfields, fieldnames} +## @end deftypefn + +function retval = nfields (varargin) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "nfields is obsolete and will be removed from a future version of Octave; please use numfields instead"); + endif + + if (nargin < 1) + print_usage (); + endif + + retval = numfields (varargin{:}); + +endfunction +
--- a/scripts/general/fieldnames.m +++ b/scripts/general/fieldnames.m @@ -33,7 +33,7 @@ ## When the input is a Java object @var{javaobj} or Java classname ## @var{jclassname} the name are the public data elements of the object or ## class. -## @seealso{nfields, isfield, orderfields, struct, methods} +## @seealso{numfields, isfield, orderfields, struct, methods} ## @end deftypefn function names = fieldnames (obj)
--- a/scripts/general/private/__isequal__.m +++ b/scripts/general/private/__isequal__.m @@ -95,9 +95,9 @@ if (isstruct (x)) ## Test the number of fields. fn_x = fieldnames (x); - l_fn_x = length (fn_x); + l_fn_x = numfields (x); fn_v = cellfun ("fieldnames", varargin, "uniformoutput", false); - t = all (l_fn_x == cellfun ("length", fn_v)); + t = all (l_fn_x == cellfun ("numfields", varargin)); ## Test that all the names are equal. idx = 0;
--- a/scripts/image/imwrite.m +++ b/scripts/image/imwrite.m @@ -100,7 +100,7 @@ fmt = imformats (ext); ## When there is no match, fmt will be a 1x1 structure with ## no fields, so we can't just use `isempty (fmt)'. - if (isempty (fieldnames (fmt))) + if (numfields (fmt) > 0) if (isempty (ext)) error ("imwrite: no extension found for %s to identify the image format", filename);
--- a/scripts/image/private/imageIO.m +++ b/scripts/image/private/imageIO.m @@ -84,13 +84,13 @@ foo = []; # the function we will use ## We check if the call to imformats (ext) worked using - ## "isempty (fieldnames (fmt))" because when it fails, the returned + ## "numfields (fmt) > 0 because when it fails, the returned ## struct is not considered empty. ## try the second input argument if (! isempty (varargin) && ischar (varargin{1})) fmt = imformats (varargin{1}); - if (! isempty (fieldnames (fmt))) + if (numfields (fmt) > 0) foo = fmt.(fieldname); varargin(1) = []; # remove format name from arguments endif @@ -104,7 +104,7 @@ ext = ext(2:end); endif fmt = imformats (ext); - if (! isempty (fieldnames (fmt))) + if (numfields (fmt) > 0) foo = fmt.(fieldname); endif endif
--- a/scripts/io/importdata.m +++ b/scripts/io/importdata.m @@ -146,8 +146,7 @@ ## i.e., output = output.onlyFieldLeft ## Update the list of fields - fields = fieldnames (output); - if (numel (fields) == 1) + if (numfields (output) == 1) output = output.(fields{1}); endif endif
--- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -148,7 +148,7 @@ err.reason{end+1} = ["Expected struct, but observed " class(cond)]; elseif (ndims (cond) != ndims (expected) || any (size (cond) != size (expected)) - || rows (fieldnames (cond)) != rows (fieldnames (expected))) + || numfields (cond) != numfields (expected)) err.index{end+1} = "."; err.observed{end+1} = ["O(" sprintf("%dx", size(cond))(1:end-1) ")"];