Mercurial > octave-nkf
comparison libinterp/octave-value/ov-struct.cc @ 18537:f958e8cd6348
maint: Periodic merge of gui-release to default.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 01 Mar 2014 22:11:32 -0800 |
parents | bcd71a2531d3 ea0d4dea1a17 |
children | fcd87f68af4f |
comparison
equal
deleted
inserted
replaced
18528:9c8321ea6f58 | 18537:f958e8cd6348 |
---|---|
1761 return false; | 1761 return false; |
1762 } | 1762 } |
1763 | 1763 |
1764 DEFUN (struct, args, , | 1764 DEFUN (struct, args, , |
1765 "-*- texinfo -*-\n\ | 1765 "-*- texinfo -*-\n\ |
1766 @deftypefn {Built-in Function} {} struct (@var{field1}, @var{value1}, @var{field2}, @var{value2}, @dots{})\n\ | 1766 @deftypefn {Built-in Function} {@var{s} =} struct ()\n\ |
1767 @deftypefnx {Built-in Function} {@var{s} =} struct (@var{field1}, @var{value1}, @var{field2}, @var{value2}, @dots{})\n\ | |
1768 @deftypefnx {Built-in Function} {@var{s} =} struct (@var{obj})\n\ | |
1767 \n\ | 1769 \n\ |
1768 Create a scalar or array structure and initialize its values. The\n\ | 1770 Create a scalar or array structure and initialize its values. The\n\ |
1769 @var{field1}, @var{field2}, @dots{} variables are strings giving the\n\ | 1771 @var{field1}, @var{field2}, @dots{} variables are strings specifying the\n\ |
1770 names of the fields and the @var{value1}, @var{value2}, @dots{}\n\ | 1772 names of the fields and the @var{value1}, @var{value2}, @dots{}\n\ |
1771 variables can be any type.\n\ | 1773 variables can be of any type.\n\ |
1772 \n\ | 1774 \n\ |
1773 If the values are cell arrays, create a structure array and initialize\n\ | 1775 If the values are cell arrays, create a structure array and initialize\n\ |
1774 its values. The dimensions of each cell array of values must match.\n\ | 1776 its values. The dimensions of each cell array of values must match.\n\ |
1775 Singleton cells and non-cell values are repeated so that they fill\n\ | 1777 Singleton cells and non-cell values are repeated so that they fill\n\ |
1776 the entire array. If the cells are empty, create an empty structure\n\ | 1778 the entire array. If the cells are empty, create an empty structure\n\ |
1801 \n\ | 1803 \n\ |
1802 @end group\n\ | 1804 @end group\n\ |
1803 @end example\n\ | 1805 @end example\n\ |
1804 \n\ | 1806 \n\ |
1805 @noindent\n\ | 1807 @noindent\n\ |
1806 The first case is an ordinary scalar struct, one field, one value. The\n\ | 1808 The first case is an ordinary scalar struct---one field, one value. The\n\ |
1807 second produces an empty struct array with one field and no values, since\n\ | 1809 second produces an empty struct array with one field and no values, since\n\ |
1808 s being passed an empty cell array of struct array values. When the value is\n\ | 1810 s being passed an empty cell array of struct array values. When the value is\n\ |
1809 a cell array containing a single entry, this becomes a scalar struct with\n\ | 1811 a cell array containing a single entry, this becomes a scalar struct with\n\ |
1810 that single entry as the value of the field. That single entry happens\n\ | 1812 that single entry as the value of the field. That single entry happens\n\ |
1811 to be an empty cell array.\n\ | 1813 to be an empty cell array.\n\ |
1812 \n\ | 1814 \n\ |
1813 Finally, if the value is a non-scalar cell array, then @code{struct}\n\ | 1815 Finally, if the value is a non-scalar cell array, then @code{struct}\n\ |
1814 produces a struct @strong{array}.\n\ | 1816 produces a struct @strong{array}.\n\ |
1817 @seealso{cell2struct, fieldnames, orderfields, getfield, setfield, rmfield, structfun}\n\ | |
1815 @end deftypefn") | 1818 @end deftypefn") |
1816 { | 1819 { |
1817 octave_value retval; | 1820 octave_value retval; |
1818 | 1821 |
1819 int nargin = args.length (); | 1822 int nargin = args.length (); |
2004 return retval; | 2007 return retval; |
2005 } | 2008 } |
2006 | 2009 |
2007 DEFUN (isfield, args, , | 2010 DEFUN (isfield, args, , |
2008 "-*- texinfo -*-\n\ | 2011 "-*- texinfo -*-\n\ |
2009 @deftypefn {Built-in Function} {} isfield (@var{x}, @var{name})\n\ | 2012 @deftypefn {Built-in Function} {} isfield (@var{x}, \"@var{name}\")\n\ |
2010 Return true if the @var{x} is a structure and it\n\ | 2013 @deftypefnx {Built-in Function} {} isfield (@var{x}, @var{name})\n\ |
2011 includes an element named @var{name}. If @var{name} is a cell\n\ | 2014 Return true if the @var{x} is a structure and it includes an element named\n\ |
2012 array of strings then a logical array of equal dimension is returned.\n\ | 2015 @var{name}. If @var{name} is a cell array of strings then a logical array of\n\ |
2016 equal dimension is returned.\n\ | |
2017 @seealso{fieldnames}\n\ | |
2013 @end deftypefn") | 2018 @end deftypefn") |
2014 { | 2019 { |
2015 octave_value retval; | 2020 octave_value retval; |
2016 | 2021 |
2017 int nargin = args.length (); | 2022 int nargin = args.length (); |
2063 | 2068 |
2064 DEFUN (nfields, args, , | 2069 DEFUN (nfields, args, , |
2065 "-*- texinfo -*-\n\ | 2070 "-*- texinfo -*-\n\ |
2066 @deftypefn {Built-in Function} {} nfields (@var{s})\n\ | 2071 @deftypefn {Built-in Function} {} nfields (@var{s})\n\ |
2067 Return the number of fields of the structure @var{s}.\n\ | 2072 Return the number of fields of the structure @var{s}.\n\ |
2073 @seealso{fieldnames}\n\ | |
2068 @end deftypefn") | 2074 @end deftypefn") |
2069 { | 2075 { |
2070 octave_value retval; | 2076 octave_value retval; |
2071 | 2077 |
2072 int nargin = args.length (); | 2078 int nargin = args.length (); |
2093 %!assert (isfield (struct ("a", 1, "b", 2), {"a", "c"}), [true, false]) | 2099 %!assert (isfield (struct ("a", 1, "b", 2), {"a", "c"}), [true, false]) |
2094 */ | 2100 */ |
2095 | 2101 |
2096 DEFUN (cell2struct, args, , | 2102 DEFUN (cell2struct, args, , |
2097 "-*- texinfo -*-\n\ | 2103 "-*- texinfo -*-\n\ |
2098 @deftypefn {Built-in Function} {} cell2struct (@var{cell}, @var{fields}, @var{dim})\n\ | 2104 @deftypefn {Built-in Function} {} cell2struct (@var{cell}, @var{fields})\n\ |
2105 @deftypefnx {Built-in Function} {} cell2struct (@var{cell}, @var{fields}, @var{dim})\n\ | |
2099 Convert @var{cell} to a structure. The number of fields in @var{fields}\n\ | 2106 Convert @var{cell} to a structure. The number of fields in @var{fields}\n\ |
2100 must match the number of elements in @var{cell} along dimension @var{dim},\n\ | 2107 must match the number of elements in @var{cell} along dimension @var{dim},\n\ |
2101 that is @code{numel (@var{fields}) == size (@var{cell}, @var{dim})}.\n\ | 2108 that is @code{numel (@var{fields}) == size (@var{cell}, @var{dim})}.\n\ |
2102 If @var{dim} is omitted, a value of 1 is assumed.\n\ | 2109 If @var{dim} is omitted, a value of 1 is assumed.\n\ |
2103 \n\ | 2110 \n\ |
2113 Height = 185\n\ | 2120 Height = 185\n\ |
2114 @}\n\ | 2121 @}\n\ |
2115 \n\ | 2122 \n\ |
2116 @end group\n\ | 2123 @end group\n\ |
2117 @end example\n\ | 2124 @end example\n\ |
2125 @seealso{struct2cell, cell2mat, struct}\n\ | |
2118 @end deftypefn") | 2126 @end deftypefn") |
2119 { | 2127 { |
2120 octave_value retval; | 2128 octave_value retval; |
2121 | 2129 |
2122 int nargin = args.length (); | 2130 int nargin = args.length (); |
2229 | 2237 |
2230 DEFUN (rmfield, args, , | 2238 DEFUN (rmfield, args, , |
2231 "-*- texinfo -*-\n\ | 2239 "-*- texinfo -*-\n\ |
2232 @deftypefn {Built-in Function} {@var{s} =} rmfield (@var{s}, \"@var{f}\")\n\ | 2240 @deftypefn {Built-in Function} {@var{s} =} rmfield (@var{s}, \"@var{f}\")\n\ |
2233 @deftypefnx {Built-in Function} {@var{s} =} rmfield (@var{s}, @var{f})\n\ | 2241 @deftypefnx {Built-in Function} {@var{s} =} rmfield (@var{s}, @var{f})\n\ |
2234 Return a copy of the structure (array) @var{s} with the field @var{f}\n\ | 2242 Return a @emph{copy} of the structure (array) @var{s} with the field @var{f}\n\ |
2235 removed. If @var{f} is a cell array of strings or a character array, remove\n\ | 2243 removed. If @var{f} is a cell array of strings or a character array, remove\n\ |
2236 each of the named fields.\n\ | 2244 each of the named fields.\n\ |
2237 @seealso{cellstr, iscellstr, setfield}\n\ | 2245 @seealso{orderfields, fieldnames}\n\ |
2238 @end deftypefn") | 2246 @end deftypefn") |
2239 { | 2247 { |
2240 octave_value retval; | 2248 octave_value retval; |
2241 | 2249 |
2242 int nargin = args.length (); | 2250 int nargin = args.length (); |
2300 structure levels to display.\n\ | 2308 structure levels to display.\n\ |
2301 \n\ | 2309 \n\ |
2302 When called from inside a function with the @qcode{\"local\"} option, the\n\ | 2310 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
2303 variable is changed locally for the function and any subroutines it calls. \n\ | 2311 variable is changed locally for the function and any subroutines it calls. \n\ |
2304 The original variable value is restored when exiting the function.\n\ | 2312 The original variable value is restored when exiting the function.\n\ |
2313 @seealso{print_struct_array_contents}\n\ | |
2305 @end deftypefn") | 2314 @end deftypefn") |
2306 { | 2315 { |
2307 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, -1, | 2316 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, -1, |
2308 std::numeric_limits<int>::max ()); | 2317 std::numeric_limits<int>::max ()); |
2309 } | 2318 } |
2312 "-*- texinfo -*-\n\ | 2321 "-*- texinfo -*-\n\ |
2313 @deftypefn {Built-in Function} {@var{val} =} print_struct_array_contents ()\n\ | 2322 @deftypefn {Built-in Function} {@var{val} =} print_struct_array_contents ()\n\ |
2314 @deftypefnx {Built-in Function} {@var{old_val} =} print_struct_array_contents (@var{new_val})\n\ | 2323 @deftypefnx {Built-in Function} {@var{old_val} =} print_struct_array_contents (@var{new_val})\n\ |
2315 @deftypefnx {Built-in Function} {} print_struct_array_contents (@var{new_val}, \"local\")\n\ | 2324 @deftypefnx {Built-in Function} {} print_struct_array_contents (@var{new_val}, \"local\")\n\ |
2316 Query or set the internal variable that specifies whether to print struct\n\ | 2325 Query or set the internal variable that specifies whether to print struct\n\ |
2317 array contents. If true, values of struct array elements are printed.\n\ | 2326 array contents.\n\ |
2318 This variable does not affect scalar structures. Their elements\n\ | 2327 \n\ |
2319 are always printed. In both cases, however, printing will be limited to\n\ | 2328 If true, values of struct array elements are printed.\n\ |
2329 This variable does not affect scalar structures whose elements are always\n\ | |
2330 printed. In both cases, however, printing will be limited to\n\ | |
2320 the number of levels specified by @var{struct_levels_to_print}.\n\ | 2331 the number of levels specified by @var{struct_levels_to_print}.\n\ |
2321 \n\ | 2332 \n\ |
2322 When called from inside a function with the @qcode{\"local\"} option, the\n\ | 2333 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
2323 variable is changed locally for the function and any subroutines it calls. \n\ | 2334 variable is changed locally for the function and any subroutines it calls. \n\ |
2324 The original variable value is restored when exiting the function.\n\ | 2335 The original variable value is restored when exiting the function.\n\ |
2336 @seealso{struct_levels_to_print}\n\ | |
2325 @end deftypefn") | 2337 @end deftypefn") |
2326 { | 2338 { |
2327 return SET_INTERNAL_VARIABLE (print_struct_array_contents); | 2339 return SET_INTERNAL_VARIABLE (print_struct_array_contents); |
2328 } | 2340 } |