comparison libinterp/corefcn/graphics.cc @ 20617:ba2b07c13913

use new string_value method to handle value extraction errors * __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc, graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc, spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 10:06:39 -0400
parents bc6daa38ff50
children
comparison
equal deleted inserted replaced
20616:fd0efcdb3718 20617:ba2b07c13913
1671 { 1671 {
1672 if (args.length () < 1) 1672 if (args.length () < 1)
1673 error ("addproperty: missing possible values for radio property"); 1673 error ("addproperty: missing possible values for radio property");
1674 else 1674 else
1675 { 1675 {
1676 std::string sv = args(0).string_value (); 1676 std::string sv = args(0).string_value ("addproperty: invalid argument for radio property, expected a string value");
1677 1677
1678 if (! error_state) 1678 retval = property (new radio_property (name, h, sv));
1679 { 1679
1680 retval = property (new radio_property (name, h, sv)); 1680 if (args.length () > 1)
1681 1681 retval.set (args(1));
1682 if (args.length () > 1)
1683 retval.set (args(1));
1684 }
1685 else
1686 error ("addproperty: invalid argument for radio property, expected a string value");
1687 } 1682 }
1688 } 1683 }
1689 else if (type.compare ("double")) 1684 else if (type.compare ("double"))
1690 { 1685 {
1691 double dv = (args.length () > 0 ? args(0).double_value () : 0.0); 1686 double dv = (args.length () > 0 ? args(0).double_value () : 0.0);
10692 { 10687 {
10693 graphics_handle h = gh_manager::lookup (val); 10688 graphics_handle h = gh_manager::lookup (val);
10694 10689
10695 if (h.ok ()) 10690 if (h.ok ())
10696 { 10691 {
10697 std::string name = args(1).string_value (); 10692 std::string name = args(1).string_value ("__go_execute_callback__: invalid callback name");
10698 10693
10699 if (! error_state) 10694 if (nargin == 2)
10700 { 10695 gh_manager::execute_callback (h, name);
10701 if (nargin == 2)
10702 gh_manager::execute_callback (h, name);
10703 else
10704 gh_manager::execute_callback (h, name, args(2));
10705 }
10706 else 10696 else
10707 error ("__go_execute_callback__: invalid callback name"); 10697 gh_manager::execute_callback (h, name, args(2));
10708 } 10698 }
10709 else 10699 else
10710 error ("__go_execute_callback__: invalid graphics object (= %g)", 10700 error ("__go_execute_callback__: invalid graphics object (= %g)",
10711 val); 10701 val);
10712 } 10702 }
10871 10861
10872 gh_manager::auto_lock guard; 10862 gh_manager::auto_lock guard;
10873 10863
10874 if (args.length () == 1) 10864 if (args.length () == 1)
10875 { 10865 {
10876 if (args(0).is_string ()) 10866 std::string name = args(0).string_value ("register_graphics_toolkit: TOOLKIT must be a string");
10877 { 10867
10878 std::string name = args(0).string_value (); 10868 gtk_manager::register_toolkit (name);
10879 gtk_manager::register_toolkit (name);
10880 }
10881 else
10882 error ("register_graphics_toolkit: TOOLKIT must be a string");
10883 } 10869 }
10884 else 10870 else
10885 print_usage (); 10871 print_usage ();
10886 10872
10887 return retval; 10873 return retval;
10989 else if (args.length () >= 2 && args.length () <= 4) 10975 else if (args.length () >= 2 && args.length () <= 4)
10990 { 10976 {
10991 std::string term, file, debug_file; 10977 std::string term, file, debug_file;
10992 bool mono; 10978 bool mono;
10993 10979
10994 term = args(0).string_value (); 10980 term = args(0).string_value ("drawnow: invalid terminal TERM, expected a string value");
10981
10982 file = args(1).string_value ("drawnow: invalid FILE, expected a string value");
10983
10984 size_t pos_p = file.find_first_of ("|");
10985 size_t pos_c = file.find_first_not_of ("| ");
10986
10987 if (pos_p == std::string::npos &&
10988 pos_c == std::string::npos)
10989 {
10990 error ("drawnow: empty output ''");
10991
10992 gh_manager::unlock ();
10993
10994 return retval;
10995 }
10996 else if (pos_c == std::string::npos)
10997 {
10998 error ("drawnow: empty pipe '|'");
10999
11000 gh_manager::unlock ();
11001
11002 return retval;
11003 }
11004 else if (pos_p != std::string::npos && pos_p < pos_c)
11005 {
11006 // Strip leading pipe character
11007 file = file.substr (pos_c);
11008 }
11009 else
11010 {
11011 size_t pos = file.find_last_of (file_ops::dir_sep_chars ());
11012
11013 if (pos != std::string::npos)
11014 {
11015 std::string dirname = file.substr (pos_c, pos+1);
11016
11017 file_stat fs (dirname);
11018
11019 if (! (fs && fs.is_dir ()))
11020 {
11021 error ("drawnow: nonexistent directory '%s'",
11022 dirname.c_str ());
11023
11024 gh_manager::unlock ();
11025
11026 return retval;
11027 }
11028 }
11029 }
11030
11031 mono = (args.length () >= 3 ? args(2).bool_value () : false);
10995 11032
10996 if (! error_state) 11033 if (! error_state)
10997 { 11034 {
10998 file = args(1).string_value (); 11035 debug_file = (args.length () > 3 ? args(3).string_value () : "");
10999 11036
11000 if (! error_state) 11037 if (! error_state)
11001 { 11038 {
11002 size_t pos_p = file.find_first_of ("|"); 11039 graphics_handle h = gcf ();
11003 size_t pos_c = file.find_first_not_of ("| "); 11040
11004 11041 if (h.ok ())
11005 if (pos_p == std::string::npos &&
11006 pos_c == std::string::npos)
11007 { 11042 {
11008 error ("drawnow: empty output ''"); 11043 graphics_object go = gh_manager::get_object (h);
11009 11044
11010 gh_manager::unlock (); 11045 gh_manager::unlock ();
11011 11046
11012 return retval; 11047 go.get_toolkit ().print_figure (go, term, file,
11013 } 11048 mono, debug_file);
11014 else if (pos_c == std::string::npos) 11049
11015 { 11050 gh_manager::lock ();
11016 error ("drawnow: empty pipe '|'");
11017
11018 gh_manager::unlock ();
11019
11020 return retval;
11021 }
11022 else if (pos_p != std::string::npos && pos_p < pos_c)
11023 {
11024 // Strip leading pipe character
11025 file = file.substr (pos_c);
11026 } 11051 }
11027 else 11052 else
11028 { 11053 error ("drawnow: nothing to draw");
11029 size_t pos = file.find_last_of (file_ops::dir_sep_chars ());
11030
11031 if (pos != std::string::npos)
11032 {
11033 std::string dirname = file.substr (pos_c, pos+1);
11034
11035 file_stat fs (dirname);
11036
11037 if (! (fs && fs.is_dir ()))
11038 {
11039 error ("drawnow: nonexistent directory '%s'",
11040 dirname.c_str ());
11041
11042 gh_manager::unlock ();
11043
11044 return retval;
11045 }
11046 }
11047 }
11048
11049 mono = (args.length () >= 3 ? args(2).bool_value () : false);
11050
11051 if (! error_state)
11052 {
11053 debug_file = (args.length () > 3 ? args(3).string_value ()
11054 : "");
11055
11056 if (! error_state)
11057 {
11058 graphics_handle h = gcf ();
11059
11060 if (h.ok ())
11061 {
11062 graphics_object go = gh_manager::get_object (h);
11063
11064 gh_manager::unlock ();
11065
11066 go.get_toolkit ().print_figure (go, term, file,
11067 mono, debug_file);
11068
11069 gh_manager::lock ();
11070 }
11071 else
11072 error ("drawnow: nothing to draw");
11073 }
11074 else
11075 error ("drawnow: invalid DEBUG_FILE, expected a string value");
11076 }
11077 else
11078 error ("drawnow: invalid colormode MONO, expected a boolean value");
11079 } 11054 }
11080 else 11055 else
11081 error ("drawnow: invalid FILE, expected a string value"); 11056 error ("drawnow: invalid DEBUG_FILE, expected a string value");
11082 } 11057 }
11083 else 11058 else
11084 error ("drawnow: invalid terminal TERM, expected a string value"); 11059 error ("drawnow: invalid colormode MONO, expected a boolean value");
11085 } 11060 }
11086 else 11061 else
11087 print_usage (); 11062 print_usage ();
11088 } 11063 }
11089 11064
11135 { 11110 {
11136 double h = args(0).double_value (); 11111 double h = args(0).double_value ();
11137 11112
11138 if (! error_state) 11113 if (! error_state)
11139 { 11114 {
11140 std::string pname = args(1).string_value (); 11115 std::string pname = args(1).string_value ("addlistener: invalid property name, expected a string value");
11141 11116
11142 if (! error_state) 11117 graphics_handle gh = gh_manager::lookup (h);
11118
11119 if (gh.ok ())
11143 { 11120 {
11144 graphics_handle gh = gh_manager::lookup (h); 11121 graphics_object go = gh_manager::get_object (gh);
11145 11122
11146 if (gh.ok ()) 11123 go.add_property_listener (pname, args(2), POSTSET);
11124
11125 if (args.length () == 4)
11147 { 11126 {
11148 graphics_object go = gh_manager::get_object (gh); 11127 caseless_str persistent = args(3).string_value ();
11149 11128 if (persistent.compare ("persistent"))
11150 go.add_property_listener (pname, args(2), POSTSET); 11129 go.add_property_listener (pname, args(2), PERSISTENT);
11151
11152 if (args.length () == 4)
11153 {
11154 caseless_str persistent = args(3).string_value ();
11155 if (persistent.compare ("persistent"))
11156 go.add_property_listener (pname, args(2), PERSISTENT);
11157 }
11158 } 11130 }
11159 else
11160 error ("addlistener: invalid graphics object (= %g)",
11161 h);
11162 } 11131 }
11163 else 11132 else
11164 error ("addlistener: invalid property name, expected a string value"); 11133 error ("addlistener: invalid graphics object (= %g)", h);
11165 } 11134 }
11166 else 11135 else
11167 error ("addlistener: invalid handle"); 11136 error ("addlistener: invalid handle");
11168 } 11137 }
11169 else 11138 else
11208 { 11177 {
11209 double h = args(0).double_value (); 11178 double h = args(0).double_value ();
11210 11179
11211 if (! error_state) 11180 if (! error_state)
11212 { 11181 {
11213 std::string pname = args(1).string_value (); 11182 std::string pname = args(1).string_value ("dellistener: invalid property name, expected a string value");
11214 11183
11215 if (! error_state) 11184 graphics_handle gh = gh_manager::lookup (h);
11185
11186 if (gh.ok ())
11216 { 11187 {
11217 graphics_handle gh = gh_manager::lookup (h); 11188 graphics_object go = gh_manager::get_object (gh);
11218 11189
11219 if (gh.ok ()) 11190 if (args.length () == 2)
11191 go.delete_property_listener (pname, octave_value (), POSTSET);
11192 else
11220 { 11193 {
11221 graphics_object go = gh_manager::get_object (gh); 11194 if (args(2).is_string ()
11222 11195 && args(2).string_value () == "persistent")
11223 if (args.length () == 2) 11196 {
11224 go.delete_property_listener (pname, octave_value (), 11197 go.delete_property_listener (pname, octave_value (),
11225 POSTSET); 11198 PERSISTENT);
11199 go.delete_property_listener (pname, octave_value (),
11200 POSTSET);
11201 }
11226 else 11202 else
11227 { 11203 go.delete_property_listener (pname, args(2), POSTSET);
11228 if (args(2).is_string ()
11229 && args(2).string_value () == "persistent")
11230 {
11231 go.delete_property_listener (pname, octave_value (),
11232 PERSISTENT);
11233 go.delete_property_listener (pname, octave_value (),
11234 POSTSET);
11235 }
11236 else
11237 go.delete_property_listener (pname, args(2), POSTSET);
11238 }
11239 } 11204 }
11240 else
11241 error ("dellistener: invalid graphics object (= %g)",
11242 h);
11243 } 11205 }
11244 else 11206 else
11245 error ("dellistener: invalid property name, expected a string value"); 11207 error ("dellistener: invalid graphics object (= %g)", h);
11246 } 11208 }
11247 else 11209 else
11248 error ("dellistener: invalid handle"); 11210 error ("dellistener: invalid handle");
11249 } 11211 }
11250 else 11212 else
11329 11291
11330 octave_value retval; 11292 octave_value retval;
11331 11293
11332 if (args.length () >= 3) 11294 if (args.length () >= 3)
11333 { 11295 {
11334 std::string name = args(0).string_value (); 11296 std::string name = args(0).string_value ("addproperty: invalid property NAME, expected a string value");
11297
11298 double h = args(1).double_value ();
11335 11299
11336 if (! error_state) 11300 if (! error_state)
11337 { 11301 {
11338 double h = args(1).double_value (); 11302 graphics_handle gh = gh_manager::lookup (h);
11339 11303
11340 if (! error_state) 11304 if (gh.ok ())
11341 { 11305 {
11342 graphics_handle gh = gh_manager::lookup (h); 11306 graphics_object go = gh_manager::get_object (gh);
11343 11307
11344 if (gh.ok ()) 11308 std::string type = args(2).string_value ("addproperty: invalid property TYPE, expected a string value");
11309
11310 if (! go.get_properties ().has_property (name))
11345 { 11311 {
11346 graphics_object go = gh_manager::get_object (gh); 11312 property p = property::create (name, gh, type,
11347 11313 args.splice (0, 3));
11348 std::string type = args(2).string_value (); 11314
11349 11315 go.get_properties ().insert_property (name, p);
11350 if (! error_state)
11351 {
11352 if (! go.get_properties ().has_property (name))
11353 {
11354 property p = property::create (name, gh, type,
11355 args.splice (0, 3));
11356
11357 go.get_properties ().insert_property (name, p);
11358 }
11359 else
11360 error ("addproperty: a '%s' property already exists in the graphics object",
11361 name.c_str ());
11362 }
11363 else
11364 error ("addproperty: invalid property TYPE, expected a string value");
11365 } 11316 }
11366 else 11317 else
11367 error ("addproperty: invalid graphics object (= %g)", h); 11318 error ("addproperty: a '%s' property already exists in the graphics object",
11319 name.c_str ());
11368 } 11320 }
11369 else 11321 else
11370 error ("addproperty: invalid handle value"); 11322 error ("addproperty: invalid graphics object (= %g)", h);
11371 } 11323 }
11372 else 11324 else
11373 error ("addproperty: invalid property NAME, expected a string value"); 11325 error ("addproperty: invalid handle value");
11374 } 11326 }
11375 else 11327 else
11376 print_usage (); 11328 print_usage ();
11377 11329
11378 return retval; 11330 return retval;