# HG changeset patch # User John W. Eaton # Date 1443902727 14400 # Node ID 2f8500ca91d3cc16e88ec3d36fd09052089fb9f5 # Parent c547458dc10e48169594b6dcdb1b99aa5490388c eliminate error_state from example files * addtwomatrices.cc, celldemo.cc, embedded.cc, fortrandemo.cc, funcdemo.cc, globaldemo.cc, helloworld.cc, make_int.cc, paramdemo.cc, stringdemo.cc, structdemo.cc, unwinddemo.cc: Eliminate use of global error_state variable. diff -r c547458dc10e -r 2f8500ca91d3 examples/code/addtwomatrices.cc --- a/examples/code/addtwomatrices.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/addtwomatrices.cc Sat Oct 03 16:05:27 2015 -0400 @@ -2,17 +2,11 @@ DEFUN_DLD (addtwomatrices, args, , "Add A to B") { - int nargin = args.length (); - - if (nargin != 2) + if (args.length () != 2) print_usage (); - else - { - NDArray A = args(0).array_value (); - NDArray B = args(1).array_value (); - if (! error_state) - return octave_value (A + B); - } - return octave_value_list (); + NDArray A = args(0).array_value (); + NDArray B = args(1).array_value (); + + return octave_value (A + B); } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/celldemo.cc --- a/examples/code/celldemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/celldemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -4,19 +4,16 @@ DEFUN_DLD (celldemo, args, , "Cell Demo") { octave_value_list retval; - int nargin = args.length (); + + if (args.length () != 1) + print_usage (); - if (nargin != 1) - print_usage (); - else + Cell c = args(0).cell_value (); + + for (octave_idx_type i = 0; i < c.numel (); i++) { - Cell c = args(0).cell_value (); - if (! error_state) - for (octave_idx_type i = 0; i < c.numel (); i++) - { - retval(i) = c(i); // using operator syntax - //retval(i) = c.elem (i); // using method syntax - } + retval(i) = c(i); // using operator syntax + //retval(i) = c.elem (i); // using method syntax } return retval; diff -r c547458dc10e -r 2f8500ca91d3 examples/code/embedded.cc --- a/examples/code/embedded.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/embedded.cc Sat Oct 03 16:05:27 2015 -0400 @@ -21,7 +21,7 @@ octave_value_list out = feval ("gcd", in, 1); - if (! error_state && out.length () > 0) + if (out.length () > 0) std::cout << "GCD of [" << in(0).int_value () << ", " diff -r c547458dc10e -r 2f8500ca91d3 examples/code/fortrandemo.cc --- a/examples/code/fortrandemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/fortrandemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -11,25 +11,22 @@ DEFUN_DLD (fortrandemo, args, , "Fortran Demo") { octave_value_list retval; - int nargin = args.length (); - if (nargin != 1) + if (args.length () != 1) print_usage (); - else - { - NDArray a = args(0).array_value (); - if (! error_state) - { - double *av = a.fortran_vec (); - octave_idx_type na = a.numel (); - OCTAVE_LOCAL_BUFFER (char, ctmp, 128); + + NDArray a = args(0).array_value (); + + double *av = a.fortran_vec (); + octave_idx_type na = a.numel (); - F77_XFCN (fortransub, FORTSUB, - (na, av, ctmp F77_CHAR_ARG_LEN (128))); + OCTAVE_LOCAL_BUFFER (char, ctmp, 128); - retval(1) = std::string (ctmp); - retval(0) = a; - } - } + F77_XFCN (fortransub, FORTSUB, + (na, av, ctmp F77_CHAR_ARG_LEN (128))); + + retval(1) = std::string (ctmp); + retval(0) = a; + return retval; } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/funcdemo.cc --- a/examples/code/funcdemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/funcdemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -4,29 +4,31 @@ DEFUN_DLD (funcdemo, args, nargout, "Function Demo") { octave_value_list retval; + int nargin = args.length (); if (nargin < 2) print_usage (); - else + + octave_value_list newargs; + + for (octave_idx_type i = nargin - 1; i > 0; i--) + newargs(i-1) = args(i); + + if (args(0).is_function_handle () || args(0).is_inline_function ()) { - octave_value_list newargs; - for (octave_idx_type i = nargin - 1; i > 0; i--) - newargs(i-1) = args(i); - if (args(0).is_function_handle () || args(0).is_inline_function ()) - { - octave_function *fcn = args(0).function_value (); - if (! error_state) - retval = feval (fcn, newargs, nargout); - } - else if (args(0).is_string ()) - { - std::string fcn = args(0).string_value (); - if (! error_state) - retval = feval (fcn, newargs, nargout); - } - else - error ("funcdemo: INPUT must be string, inline, or function handle"); + octave_function *fcn = args(0).function_value (); + + retval = feval (fcn, newargs, nargout); } + else if (args(0).is_string ()) + { + std::string fcn = args(0).string_value (); + + retval = feval (fcn, newargs, nargout); + } + else + error ("funcdemo: INPUT must be string, inline, or function handle"); + return retval; } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/globaldemo.cc --- a/examples/code/globaldemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/globaldemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -3,23 +3,20 @@ DEFUN_DLD (globaldemo, args, , "Global Demo") { octave_value retval; - int nargin = args.length (); + + if (args.length () != 1) + print_usage (); - if (nargin != 1) - print_usage (); + std::string s = args(0).string_value (); + + octave_value tmp = get_global_value (s, true); + + if (tmp.is_defined ()) + retval = tmp; else - { - std::string s = args(0).string_value (); - if (! error_state) - { - octave_value tmp = get_global_value (s, true); - if (tmp.is_defined ()) - retval = tmp; - else - retval = "Global variable not found"; + retval = "Global variable not found"; - set_global_value ("a", 42.0); - } - } + set_global_value ("a", 42.0); + return retval; } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/helloworld.cc --- a/examples/code/helloworld.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/helloworld.cc Sat Oct 03 16:05:27 2015 -0400 @@ -3,10 +3,8 @@ DEFUN_DLD (helloworld, args, nargout, "Hello World Help String") { - int nargin = args.length (); - octave_stdout << "Hello World has " - << nargin << " input arguments and " + << args.length () << " input arguments and " << nargout << " output arguments.\n"; return octave_value_list (); diff -r c547458dc10e -r 2f8500ca91d3 examples/code/make_int.cc --- a/examples/code/make_int.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/make_int.cc Sat Oct 03 16:05:27 2015 -0400 @@ -278,8 +278,7 @@ { double d = args(0).double_value (); - if (! error_state) - retval = octave_value (new octave_integer (NINT (d))); + retval = octave_value (new octave_integer (NINT (d))); } else usage ("make_int"); diff -r c547458dc10e -r 2f8500ca91d3 examples/code/paramdemo.cc --- a/examples/code/paramdemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/paramdemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -2,29 +2,33 @@ DEFUN_DLD (paramdemo, args, nargout, "Parameter Check Demo") { - octave_value retval; - int nargin = args.length (); + if (args.length () != 1) + print_usage (); - if (nargin != 1) - print_usage (); - else if (nargout != 0) + if (nargout != 0) error ("paramdemo: OUTPUT argument required"); - else - { - NDArray m = args(0).array_value (); - double min_val = -10.0; - double max_val = 10.0; - octave_stdout << "Properties of input array:\n"; - if (m.any_element_is_negative ()) - octave_stdout << " includes negative values\n"; - if (m.any_element_is_inf_or_nan ()) - octave_stdout << " includes Inf or NaN values\n"; - if (m.any_element_not_one_or_zero ()) - octave_stdout << " includes other values than 1 and 0\n"; - if (m.all_elements_are_int_or_inf_or_nan ()) - octave_stdout << " includes only int, Inf or NaN values\n"; - if (m.all_integers (min_val, max_val)) - octave_stdout << " includes only integers in [-10,10]\n"; - } - return retval; + + NDArray m = args(0).array_value (); + + double min_val = -10.0; + double max_val = 10.0; + + octave_stdout << "Properties of input array:\n"; + + if (m.any_element_is_negative ()) + octave_stdout << " includes negative values\n"; + + if (m.any_element_is_inf_or_nan ()) + octave_stdout << " includes Inf or NaN values\n"; + + if (m.any_element_not_one_or_zero ()) + octave_stdout << " includes other values than 1 and 0\n"; + + if (m.all_elements_are_int_or_inf_or_nan ()) + octave_stdout << " includes only int, Inf or NaN values\n"; + + if (m.all_integers (min_val, max_val)) + octave_stdout << " includes only integers in [-10,10]\n"; + + return octave_value (); } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/stringdemo.cc --- a/examples/code/stringdemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/stringdemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -3,27 +3,25 @@ DEFUN_DLD (stringdemo, args, , "String Demo") { octave_value_list retval; - int nargin = args.length (); - if (nargin != 1) + if (args.length () != 1) print_usage (); - else - { - charMatrix ch = args(0).char_matrix_value (); + + charMatrix ch = args(0).char_matrix_value (); + + retval(1) = octave_value (ch, '\''); // Single Quote String + + octave_idx_type nr = ch.rows (); - if (! error_state) - { - retval(1) = octave_value (ch, '\''); // Single Quote String + for (octave_idx_type i = 0; i < nr / 2; i++) + { + std::string tmp = ch.row_as_string (i); - octave_idx_type nr = ch.rows (); - for (octave_idx_type i = 0; i < nr / 2; i++) - { - std::string tmp = ch.row_as_string (i); - ch.insert (ch.row_as_string (nr-i-1).c_str (), i, 0); - ch.insert (tmp.c_str (), nr-i-1, 0); - } - retval(0) = octave_value (ch, '"'); // Double Quote String - } + ch.insert (ch.row_as_string (nr-i-1).c_str (), i, 0); + ch.insert (tmp.c_str (), nr-i-1, 0); } + + retval(0) = octave_value (ch, '"'); // Double Quote String + return retval; } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/structdemo.cc --- a/examples/code/structdemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/structdemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -3,43 +3,30 @@ DEFUN_DLD (structdemo, args, , "Struct Demo") { - octave_value retval; - int nargin = args.length (); - - if (args.length () == 2) - { - octave_scalar_map arg0 = args(0).scalar_map_value (); - //octave_map arg0 = args(0).map_value (); - - if (! error_state) - { - std::string arg1 = args(1).string_value (); - - if (! error_state) - { - octave_value tmp = arg0.contents (arg1); - //octave_value tmp = arg0.contents (arg1)(0); - - if (tmp.is_defined ()) - { - octave_scalar_map st; - - st.assign ("selected", tmp); - - retval = octave_value (st); - } - else - error ("structdemo: struct does not have a field named '%s'\n", - arg1.c_str ()); - } - else - error ("structdemo: ARG2 must be a character string"); - } - else - error ("structdemo: ARG1 must be a struct"); - } - else + if (args.length () != 2) print_usage (); - return retval; + if (! args(0).is_map ()) + error ("structdemo: ARG1 must be a struct"); + + octave_scalar_map arg0 = args(0).scalar_map_value (); + //octave_map arg0 = args(0).map_value (); + + if (! args(1).is_string ()) + error ("structdemo: ARG2 must be a character string"); + + std::string arg1 = args(1).string_value (); + + octave_value tmp = arg0.contents (arg1); + //octave_value tmp = arg0.contents (arg1)(0); + + if (! tmp.is_defined ()) + error ("structdemo: struct does not have a field named '%s'\n", + arg1.c_str ()); + + octave_scalar_map st; + + st.assign ("selected", tmp); + + return octave_value (st); } diff -r c547458dc10e -r 2f8500ca91d3 examples/code/unwinddemo.cc --- a/examples/code/unwinddemo.cc Sat Oct 03 13:20:28 2015 -0400 +++ b/examples/code/unwinddemo.cc Sat Oct 03 16:05:27 2015 -0400 @@ -15,33 +15,23 @@ DEFUN_DLD (unwinddemo, args, nargout, "Unwind Demo") { - octave_value retval; - int nargin = args.length (); - - if (nargin < 2) + if (args.length () < 2) print_usage (); - else - { - NDArray a = args(0).array_value (); - NDArray b = args(1).array_value (); + + NDArray a = args(0).array_value (); + NDArray b = args(1).array_value (); - if (! error_state) - { - // Declare unwind_protect frame which lasts as long as - // the variable frame has scope. - unwind_protect frame; - frame.add_fcn (set_liboctave_warning_handler, - current_liboctave_warning_handler); + // Declare unwind_protect frame which lasts as long as + // the variable frame has scope. + unwind_protect frame; + frame.add_fcn (set_liboctave_warning_handler, + current_liboctave_warning_handler); - frame.add_fcn (set_liboctave_warning_with_id_handler, - current_liboctave_warning_with_id_handler); - - set_liboctave_warning_handler (my_err_handler); - set_liboctave_warning_with_id_handler (my_err_with_id_handler); + frame.add_fcn (set_liboctave_warning_with_id_handler, + current_liboctave_warning_with_id_handler); - retval = octave_value (quotient (a, b)); - } - } + set_liboctave_warning_handler (my_err_handler); + set_liboctave_warning_with_id_handler (my_err_with_id_handler); - return retval; + return octave_value (quotient (a, b)); }