Mercurial > hg > octave-nkf
comparison libinterp/corefcn/graphics.cc @ 18118:ec9b35e60f95
style fixes in graphics.in.h and graphics.cc
* graphics.in.h, graphics.cc: Pass std::string as const reference.
Pass double by value, not as const or const reference.
Check str.empty () instead of str == "". Minor formatting changes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Dec 2013 17:51:53 -0500 |
parents | ca84d3c9dc24 |
children | 0cbd0d285541 |
comparison
equal
deleted
inserted
replaced
18117:ca84d3c9dc24 | 18118:ec9b35e60f95 |
---|---|
1010 { | 1010 { |
1011 std::string retval; | 1011 std::string retval; |
1012 for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); | 1012 for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); |
1013 it != possible_vals.end (); it++) | 1013 it != possible_vals.end (); it++) |
1014 { | 1014 { |
1015 if (retval == "") | 1015 if (retval.empty ()) |
1016 { | 1016 { |
1017 if (*it == default_value ()) | 1017 if (*it == default_value ()) |
1018 retval = "{" + *it + "}"; | 1018 retval = "{" + *it + "}"; |
1019 else | 1019 else |
1020 retval = *it; | 1020 retval = *it; |
1025 retval += " | {" + *it + "}"; | 1025 retval += " | {" + *it + "}"; |
1026 else | 1026 else |
1027 retval += " | " + *it; | 1027 retval += " | " + *it; |
1028 } | 1028 } |
1029 } | 1029 } |
1030 if (retval != "") | 1030 |
1031 if (! retval.empty ()) | |
1031 retval = "[ " + retval + " ]"; | 1032 retval = "[ " + retval + " ]"; |
1033 | |
1032 return retval; | 1034 return retval; |
1033 } | 1035 } |
1034 | 1036 |
1035 Cell | 1037 Cell |
1036 radio_values::values_as_cell (void) const | 1038 radio_values::values_as_cell (void) const |
1042 retval(i++) = std::string (*it); | 1044 retval(i++) = std::string (*it); |
1043 return retval; | 1045 return retval; |
1044 } | 1046 } |
1045 | 1047 |
1046 bool | 1048 bool |
1047 color_values::str2rgb (std::string str) | 1049 color_values::str2rgb (const std::string& str_arg) |
1048 { | 1050 { |
1051 bool retval = true; | |
1052 | |
1049 double tmp_rgb[3] = {0, 0, 0}; | 1053 double tmp_rgb[3] = {0, 0, 0}; |
1050 bool retval = true; | 1054 |
1055 std::string str = str_arg; | |
1051 unsigned int len = str.length (); | 1056 unsigned int len = str.length (); |
1052 | 1057 |
1053 std::transform (str.begin (), str.end (), str.begin (), tolower); | 1058 std::transform (str.begin (), str.end (), str.begin (), tolower); |
1054 | 1059 |
1055 if (str.compare (0, len, "blue", 0, len) == 0) | 1060 if (str.compare (0, len, "blue", 0, len) == 0) |
2974 if (p.is_radio ()) | 2979 if (p.is_radio ()) |
2975 retval += p.values_as_string (); | 2980 retval += p.values_as_string (); |
2976 } | 2981 } |
2977 } | 2982 } |
2978 } | 2983 } |
2979 if (retval != "") | 2984 |
2985 if (! retval.empty ()) | |
2980 retval += "\n"; | 2986 retval += "\n"; |
2981 } | 2987 } |
2982 else | 2988 else |
2983 error ("base_graphics_object::values_as_string: invalid graphics object"); | 2989 error ("base_graphics_object::values_as_string: invalid graphics object"); |
2984 | 2990 |
2985 return retval; | 2991 return retval; |
2986 } | 2992 } |
2987 | 2993 |
2988 std::string | 2994 std::string |
2989 base_graphics_object::value_as_string (std::string prop) | 2995 base_graphics_object::value_as_string (const std::string& prop) |
2990 { | 2996 { |
2991 std::string retval; | 2997 std::string retval; |
2992 | 2998 |
2993 if (valid_object ()) | 2999 if (valid_object ()) |
2994 { | 3000 { |
2997 property p = get_properties ().get_property (prop); | 3003 property p = get_properties ().get_property (prop); |
2998 | 3004 |
2999 if (p.ok () && ! p.is_hidden ()) | 3005 if (p.ok () && ! p.is_hidden ()) |
3000 { | 3006 { |
3001 if (p.is_radio ()) | 3007 if (p.is_radio ()) |
3002 { | 3008 retval += p.values_as_string (); |
3003 retval += p.values_as_string (); | |
3004 } | |
3005 } | 3009 } |
3006 } | 3010 } |
3007 if (retval != "") | 3011 |
3012 if (! retval.empty ()) | |
3008 retval += "\n"; | 3013 retval += "\n"; |
3009 } | 3014 } |
3010 else | 3015 else |
3011 error ("base_graphics_object::value_as_string: invalid graphics object"); | 3016 error ("base_graphics_object::value_as_string: invalid graphics object"); |
3012 | 3017 |
6916 | 6921 |
6917 xproperties.update_transform (); | 6922 xproperties.update_transform (); |
6918 } | 6923 } |
6919 | 6924 |
6920 inline | 6925 inline |
6921 double force_in_range (const double x, const double lower, const double upper) | 6926 double force_in_range (double x, double lower, double upper) |
6922 { | 6927 { |
6923 if (x < lower) | 6928 if (x < lower) |
6924 { return lower; } | 6929 return lower; |
6925 else if (x > upper) | 6930 else if (x > upper) |
6926 { return upper; } | 6931 return upper; |
6927 else | 6932 else |
6928 { return x; } | 6933 return x; |
6929 } | 6934 } |
6930 | 6935 |
6931 static Matrix | 6936 static Matrix |
6932 do_zoom (double val, double factor, const Matrix& lims, bool is_logscale) | 6937 do_zoom (double val, double factor, const Matrix& lims, bool is_logscale) |
6933 { | 6938 { |
8185 // function_event objects must be created with at least a function. | 8190 // function_event objects must be created with at least a function. |
8186 function_event (void); | 8191 function_event (void); |
8187 | 8192 |
8188 // No copying! | 8193 // No copying! |
8189 | 8194 |
8190 function_event (const function_event &); | 8195 function_event (const function_event&); |
8191 | 8196 |
8192 function_event & operator = (const function_event &); | 8197 function_event & operator = (const function_event&); |
8193 }; | 8198 }; |
8194 | 8199 |
8195 class | 8200 class |
8196 set_event : public base_graphics_event | 8201 set_event : public base_graphics_event |
8197 { | 8202 { |
8389 | 8394 |
8390 command_editor::add_event_hook (gh_manager::process_events); | 8395 command_editor::add_event_hook (gh_manager::process_events); |
8391 } | 8396 } |
8392 | 8397 |
8393 void | 8398 void |
8394 gh_manager::do_post_callback (const graphics_handle& h, const std::string name, | 8399 gh_manager::do_post_callback (const graphics_handle& h, const std::string& name, |
8395 const octave_value& data) | 8400 const octave_value& data) |
8396 { | 8401 { |
8397 gh_manager::auto_lock guard; | 8402 gh_manager::auto_lock guard; |
8398 | 8403 |
8399 graphics_object go = get_object (h); | 8404 graphics_object go = get_object (h); |
8439 | 8444 |
8440 do_post_event (graphics_event::create_function_event (fcn, fcn_data)); | 8445 do_post_event (graphics_event::create_function_event (fcn, fcn_data)); |
8441 } | 8446 } |
8442 | 8447 |
8443 void | 8448 void |
8444 gh_manager::do_post_set (const graphics_handle& h, const std::string name, | 8449 gh_manager::do_post_set (const graphics_handle& h, const std::string& name, |
8445 const octave_value& value, bool notify_toolkit) | 8450 const octave_value& value, bool notify_toolkit) |
8446 { | 8451 { |
8447 gh_manager::auto_lock guard; | 8452 gh_manager::auto_lock guard; |
8448 | 8453 |
8449 do_post_event (graphics_event::create_set_event (h, name, value, | 8454 do_post_event (graphics_event::create_set_event (h, name, value, |
8812 | 8817 |
8813 return retval; | 8818 return retval; |
8814 } | 8819 } |
8815 | 8820 |
8816 static std::string | 8821 static std::string |
8817 get_graphics_object_type (const double val) | 8822 get_graphics_object_type (double val) |
8818 { | 8823 { |
8819 std::string retval; | 8824 std::string retval; |
8820 | 8825 |
8821 graphics_object obj = gh_manager::get_object (val); | 8826 graphics_object obj = gh_manager::get_object (val); |
8822 | 8827 |