Mercurial > hg > octave-lyh
comparison libinterp/octave-value/ov-struct.cc @ 15782:10ed43563df5
doc: overhaul struct docstring
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 13 Dec 2012 15:40:51 -0500 |
parents | c33594eefda7 |
children | 12005245b645 |
comparison
equal
deleted
inserted
replaced
15781:c33594eefda7 | 15782:10ed43563df5 |
---|---|
1747 return false; | 1747 return false; |
1748 } | 1748 } |
1749 | 1749 |
1750 DEFUN (struct, args, , | 1750 DEFUN (struct, args, , |
1751 "-*- texinfo -*-\n\ | 1751 "-*- texinfo -*-\n\ |
1752 @deftypefn {Built-in Function} {} struct (\"field\", @var{value}, \"field\", @var{value}, @dots{})\n\ | 1752 @deftypefn {Built-in Function} {} struct (@var{field1}, @var{value1}, @var{field2}, @var{value2}, @dots{})\n\ |
1753 \n\ | 1753 \n\ |
1754 Create a structure and initialize its value.\n\ | 1754 Create a scalar or array structure and initialize its values. The\n\ |
1755 @var{field1}, @var{field2}, @dots{} variables are strings giving the\n\ | |
1756 names of the fields and the @var{value1}, @var{value2}, @dots{}\n\ | |
1757 variables can be any type.\n\ | |
1755 \n\ | 1758 \n\ |
1756 If the values are cell arrays, create a structure array and initialize\n\ | 1759 If the values are cell arrays, create a structure array and initialize\n\ |
1757 its values. The dimensions of each cell array of values must match.\n\ | 1760 its values. The dimensions of each cell array of values must match.\n\ |
1758 Singleton cells and non-cell values are repeated so that they fill\n\ | 1761 Singleton cells and non-cell values are repeated so that they fill\n\ |
1759 the entire array. If the cells are empty, create an empty structure\n\ | 1762 the entire array. If the cells are empty, create an empty structure\n\ |
1760 array with the specified field names.\n\ | 1763 array with the specified field names.\n\ |
1761 \n\ | 1764 \n\ |
1762 If the argument is an object, return the underlying struct.\n\ | 1765 If the argument is an object, return the underlying struct.\n\ |
1766 \n\ | |
1767 Observe that the syntax is optimized for struct @strong{arrays}. Consider the\n\ | |
1768 following examples:\n\ | |
1769 \n\ | |
1770 @example\n\ | |
1771 @group\n\ | |
1772 struct (\"foo\", 1)\n\ | |
1773 @result{} scalar structure containing the fields:\n\ | |
1774 foo = 1\n\ | |
1775 \n\ | |
1776 struct (\"foo\", @{@})\n\ | |
1777 @result{} 0x0 struct array containing the fields:\n\ | |
1778 foo\n\ | |
1779 \n\ | |
1780 struct (\"foo\", @{ @{@} @})\n\ | |
1781 @result{} scalar structure containing the fields:\n\ | |
1782 foo = @{@}(0x0)\n\ | |
1783 \n\ | |
1784 struct (\"foo\", @{1, 2, 3@})\n\ | |
1785 @result{} 1x3 struct array containing the fields:\n\ | |
1786 foo\n\ | |
1787 \n\ | |
1788 @end group\n\ | |
1789 @end example\n\ | |
1790 \n\ | |
1791 @noindent\n\ | |
1792 The first case is an ordinary scalar struct, one field, one value. The\n\ | |
1793 second produces an empty struct array with one field and no values, since\n\ | |
1794 s being passed an empty cell array of struct array values. When the value is\n\ | |
1795 a cell array containing a single entry, this becomes a scalar struct with\n\ | |
1796 that single entry as the value of the field. That single entry happens\n\ | |
1797 to be an empty cell array.\n\ | |
1798 \n\ | |
1799 Finally, if the value is a non-scalar cell array, then @code{struct}\n\ | |
1800 produces a struct @strong{array}.\n\ | |
1763 @end deftypefn") | 1801 @end deftypefn") |
1764 { | 1802 { |
1765 octave_value retval; | 1803 octave_value retval; |
1766 | 1804 |
1767 int nargin = args.length (); | 1805 int nargin = args.length (); |