diff libinterp/octave-value/ov-struct.cc @ 15781:c33594eefda7

Add fieldnames.m which extensds fieldnames() to work on Java objects. Deprecate javafields. Rename old C++ fieldnames to __fieldnames__. * scripts/deprecated/javafields.m: Moved from scripts/java. Added deprecated warning. * scripts/java/javafields.m: Moved to scripts/deprecated. * scripts/general/fieldnames.m: New m-file which accepts Java, structure, or Octave objects as inputs. * libinterp/octave-value/ov-struct.cc(Ffieldnames): Renamed fieldnames to __fieldnames__ to avoid class with fieldnames.m. * scripts/deprecated/module.mk: Added javafields to deprecated build. * scripts/general/module.mk: Added fieldnames.m to build. * scripts/java/module.mk: Removed javafields.m from build.
author Rik <rik@octave.org>
date Thu, 13 Dec 2012 10:57:04 -0800
parents 18f168880226
children 10ed43563df5
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc	Thu Dec 13 10:47:24 2012 -0800
+++ b/libinterp/octave-value/ov-struct.cc	Thu Dec 13 10:57:04 2012 -0800
@@ -1925,49 +1925,33 @@
   return retval;
 }
 
-DEFUN (fieldnames, args, ,
+DEFUN (__fieldnames__, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Built-in Function} {} fieldnames (@var{struct})\n\
-Return a cell array of strings naming the elements of the structure\n\
-@var{struct}.  It is an error to call @code{fieldnames} with an\n\
-argument that is not a structure.\n\
+@deftypefn  {Built-in Function} {} __fieldnames__ (@var{struct})\n\
+@deftypefnx {Built-in Function} {} __fieldnames__ (@var{obj})\n\
+Internal function.\n\
+\n\
+Implements @code{fieldnames()} for structures and Octave objects.\n\
+@seealso{fieldnames}\n\
 @end deftypefn")
 {
   octave_value retval;
 
-  int nargin = args.length ();
-
-  if (nargin == 1)
-    {
-      octave_value arg = args(0);
-
-      if (arg.is_map () || arg.is_object ())
-        {
-          octave_map m = arg.map_value ();
-
-          string_vector keys = m.fieldnames ();
-
-          if (keys.length () == 0)
-            retval = Cell (0, 1);
-          else
-            retval = Cell (keys);
-        }
-      else
-        gripe_wrong_type_arg ("fieldnames", args(0));
-    }
+  // Input validation has already been done in fieldnames.m.
+  octave_value arg = args(0);
+
+  octave_map m = arg.map_value ();
+
+  string_vector keys = m.fieldnames ();
+
+  if (keys.length () == 0)
+    retval = Cell (0, 1);
   else
-    print_usage ();
+    retval = Cell (keys);
 
   return retval;
 }
 
-/*
-## test preservation of fieldname order
-%!test
-%! x(3).d=1;  x(2).a=2; x(1).b=3;  x(2).c=3;
-%! assert (fieldnames (x), {"d"; "a"; "b"; "c"});
-*/
-
 DEFUN (isfield, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} isfield (@var{x}, @var{name})\n\