comparison scripts/general/subsindex.m @ 21072:a9ed4104ecfd

doc: Rewrite documentation for Object Oriented Programming. * octave.texi: Rename "Manipulating Classes" node to "Class Methods" * oop.txi: Rewrite signicant parts of Object Oriented Programming chapter. * examples/code/@FIRfilter/subsasgn.m, examples/code/@FIRfilter/subsref.m, examples/code/@polynomial/get.m, examples/code/@polynomial/subsasgn.m: Enclose property in error messages in double quotes ("%s"). * examples/code/@polynomial/subsref.m: Rename input object to 'p'. Rename variable "ind" to "idx". Enclose property in error messages in double quotes ("%s"). * ov-class.cc (Fsuperiorto, Finferiorto): Improve docstrings. * ov-usr-fcn.cc (Foptimize_subsasgn_calls): Improve docstring. * ov.cc (Fsubsref, Fsubsasgn): Improve docstrings. * display.m: Rewrite docstring. Rename input variable to "obj". Remove unused output variable from function declaration. * subsindex.m: Rename input variable to "obj". Rewrite examples in docstring. Add input validation and BIST tests to m-file.
author Rik <rik@octave.org>
date Thu, 14 Jan 2016 13:30:22 -0800
parents 516bb87ea72e
children b433f9990452
comparison
equal deleted inserted replaced
21071:f25c14056b7c 21072:a9ed4104ecfd
15 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {} {@var{idx} =} subsindex (@var{a}) 20 ## @deftypefn {} {@var{idx} =} subsindex (@var{obj})
21 ## Convert an object to an index vector. 21 ## Convert an object to an index vector.
22 ## 22 ##
23 ## When @var{a} is a class object defined with a class constructor, then 23 ## When @var{obj} is a class object defined with a class constructor, then
24 ## @code{subsindex} is the overloading method that allows the conversion of 24 ## @code{subsindex} is the overloading method that allows the conversion of
25 ## this class object to a valid indexing vector. It is important to note that 25 ## this class object to a valid indexing vector. It is important to note that
26 ## @code{subsindex} must return a zero-based real integer vector of the class 26 ## @code{subsindex} must return a zero-based real integer vector of the class
27 ## @qcode{"double"}. For example, if the class constructor 27 ## @qcode{"double"}. For example, if the class constructor were
28 ## 28 ##
29 ## @example 29 ## @example
30 ## @group 30 ## @group
31 ## function b = myclass (a) 31 ## function obj = myclass (a)
32 ## b = class (struct ("a", a), "myclass"); 32 ## obj = class (struct ("a", a), "myclass");
33 ## endfunction 33 ## endfunction
34 ## @end group 34 ## @end group
35 ## @end example 35 ## @end example
36 ## 36 ##
37 ## @noindent 37 ## @noindent
38 ## then the @code{subsindex} function 38 ## then the @code{subsindex} function
39 ## 39 ##
40 ## @example 40 ## @example
41 ## @group 41 ## @group
42 ## function idx = subsindex (a) 42 ## function idx = subsindex (obj)
43 ## idx = double (a.a) - 1.0; 43 ## idx = double (obj.a) - 1.0;
44 ## endfunction 44 ## endfunction
45 ## @end group 45 ## @end group
46 ## @end example 46 ## @end example
47 ## 47 ##
48 ## @noindent 48 ## @noindent
49 ## can then be used as follows 49 ## could be used as follows
50 ## 50 ##
51 ## @example 51 ## @example
52 ## @group 52 ## @group
53 ## a = myclass (1:4); 53 ## a = myclass (1:4);
54 ## b = 1:10; 54 ## b = 1:10;
58 ## @end example 58 ## @end example
59 ## 59 ##
60 ## @seealso{class, subsref, subsasgn} 60 ## @seealso{class, subsref, subsasgn}
61 ## @end deftypefn 61 ## @end deftypefn
62 62
63 function idx = subsindex (a) 63 function idx = subsindex (obj)
64 error ("subsindex: not defined for class \"%s\"", class (a)); 64
65 if (nargin != 1)
66 print_usage ();
67 endif
68
69 ## Only way to get here is if subsindex has not been overloaded by a class.
70 error ('subsindex: not defined for class "%s"', class (obj));
71
65 endfunction 72 endfunction
66 73
74
75 %!error <not defined for class "double"> subsindex (1)
76
77 ## Test input validation
78 %!error subsindex ()
79 %!error subsindex (1, 2)
80