Mercurial > hg > octave-nkf
comparison 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 |
comparison
equal
deleted
inserted
replaced
15780:f25101b1e37f | 15781:c33594eefda7 |
---|---|
1923 print_usage (); | 1923 print_usage (); |
1924 | 1924 |
1925 return retval; | 1925 return retval; |
1926 } | 1926 } |
1927 | 1927 |
1928 DEFUN (fieldnames, args, , | 1928 DEFUN (__fieldnames__, args, , |
1929 "-*- texinfo -*-\n\ | 1929 "-*- texinfo -*-\n\ |
1930 @deftypefn {Built-in Function} {} fieldnames (@var{struct})\n\ | 1930 @deftypefn {Built-in Function} {} __fieldnames__ (@var{struct})\n\ |
1931 Return a cell array of strings naming the elements of the structure\n\ | 1931 @deftypefnx {Built-in Function} {} __fieldnames__ (@var{obj})\n\ |
1932 @var{struct}. It is an error to call @code{fieldnames} with an\n\ | 1932 Internal function.\n\ |
1933 argument that is not a structure.\n\ | 1933 \n\ |
1934 Implements @code{fieldnames()} for structures and Octave objects.\n\ | |
1935 @seealso{fieldnames}\n\ | |
1934 @end deftypefn") | 1936 @end deftypefn") |
1935 { | 1937 { |
1936 octave_value retval; | 1938 octave_value retval; |
1937 | 1939 |
1938 int nargin = args.length (); | 1940 // Input validation has already been done in fieldnames.m. |
1939 | 1941 octave_value arg = args(0); |
1940 if (nargin == 1) | 1942 |
1941 { | 1943 octave_map m = arg.map_value (); |
1942 octave_value arg = args(0); | 1944 |
1943 | 1945 string_vector keys = m.fieldnames (); |
1944 if (arg.is_map () || arg.is_object ()) | 1946 |
1945 { | 1947 if (keys.length () == 0) |
1946 octave_map m = arg.map_value (); | 1948 retval = Cell (0, 1); |
1947 | |
1948 string_vector keys = m.fieldnames (); | |
1949 | |
1950 if (keys.length () == 0) | |
1951 retval = Cell (0, 1); | |
1952 else | |
1953 retval = Cell (keys); | |
1954 } | |
1955 else | |
1956 gripe_wrong_type_arg ("fieldnames", args(0)); | |
1957 } | |
1958 else | 1949 else |
1959 print_usage (); | 1950 retval = Cell (keys); |
1960 | 1951 |
1961 return retval; | 1952 return retval; |
1962 } | 1953 } |
1963 | |
1964 /* | |
1965 ## test preservation of fieldname order | |
1966 %!test | |
1967 %! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; | |
1968 %! assert (fieldnames (x), {"d"; "a"; "b"; "c"}); | |
1969 */ | |
1970 | 1954 |
1971 DEFUN (isfield, args, , | 1955 DEFUN (isfield, args, , |
1972 "-*- texinfo -*-\n\ | 1956 "-*- texinfo -*-\n\ |
1973 @deftypefn {Built-in Function} {} isfield (@var{x}, @var{name})\n\ | 1957 @deftypefn {Built-in Function} {} isfield (@var{x}, @var{name})\n\ |
1974 Return true if the @var{x} is a structure and it\n\ | 1958 Return true if the @var{x} is a structure and it\n\ |