# HG changeset patch # User Rik # Date 1393793771 28800 # Node ID fcd87f68af4f225f911daf47e2642fc0f6f1d12a # Parent f958e8cd6348e2ed77f34b539d421b5986a71516 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. diff -r f958e8cd6348 -r fcd87f68af4f NEWS --- a/NEWS Sat Mar 01 22:11:32 2014 -0800 +++ b/NEWS Sun Mar 02 12:56:11 2014 -0800 @@ -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 diff -r f958e8cd6348 -r fcd87f68af4f doc/interpreter/container.txi --- a/doc/interpreter/container.txi Sat Mar 01 22:11:32 2014 -0800 +++ b/doc/interpreter/container.txi Sun Mar 02 12:56:11 2014 -0800 @@ -507,7 +507,7 @@ Other functions that can manipulate the fields of a structure are given below. -@DOCSTRING(nfields) +@DOCSTRING(numfields) @DOCSTRING(fieldnames) diff -r f958e8cd6348 -r fcd87f68af4f libinterp/corefcn/oct-map.cc --- a/libinterp/corefcn/oct-map.cc Sat Mar 01 22:11:32 2014 -0800 +++ b/libinterp/corefcn/oct-map.cc Sun Mar 02 12:56:11 2014 -0800 @@ -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]); diff -r f958e8cd6348 -r fcd87f68af4f libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Sat Mar 01 22:11:32 2014 -0800 +++ b/libinterp/octave-value/ov-struct.cc Sun Mar 02 12:56:11 2014 -0800 @@ -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") diff -r f958e8cd6348 -r fcd87f68af4f scripts/deprecated/module.mk --- a/scripts/deprecated/module.mk Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/deprecated/module.mk Sun Mar 02 12:56:11 2014 -0800 @@ -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) diff -r f958e8cd6348 -r fcd87f68af4f scripts/deprecated/nfields.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/nfields.m Sun Mar 02 12:56:11 2014 -0800 @@ -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 +## . + +## -*- 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 + diff -r f958e8cd6348 -r fcd87f68af4f scripts/general/fieldnames.m --- a/scripts/general/fieldnames.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/general/fieldnames.m Sun Mar 02 12:56:11 2014 -0800 @@ -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) diff -r f958e8cd6348 -r fcd87f68af4f scripts/general/private/__isequal__.m --- a/scripts/general/private/__isequal__.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/general/private/__isequal__.m Sun Mar 02 12:56:11 2014 -0800 @@ -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; diff -r f958e8cd6348 -r fcd87f68af4f scripts/image/imwrite.m --- a/scripts/image/imwrite.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/image/imwrite.m Sun Mar 02 12:56:11 2014 -0800 @@ -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); diff -r f958e8cd6348 -r fcd87f68af4f scripts/image/private/imageIO.m --- a/scripts/image/private/imageIO.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/image/private/imageIO.m Sun Mar 02 12:56:11 2014 -0800 @@ -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 diff -r f958e8cd6348 -r fcd87f68af4f scripts/io/importdata.m --- a/scripts/io/importdata.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/io/importdata.m Sun Mar 02 12:56:11 2014 -0800 @@ -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 diff -r f958e8cd6348 -r fcd87f68af4f scripts/testfun/assert.m --- a/scripts/testfun/assert.m Sat Mar 01 22:11:32 2014 -0800 +++ b/scripts/testfun/assert.m Sun Mar 02 12:56:11 2014 -0800 @@ -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) ")"];