# HG changeset patch # User Pantxo Diribarne # Date 1386428203 -3600 # Node ID ca84d3c9dc24dd527112580ac5a67468eaeb3df0 # Parent 95466a42bcba082b1b23926a43465b33c7df8498 set: allow retrieving allowed values for individual properties * libinterp/corefcn/graphics.in.h: add "std::string value_as_string (std::string)" method to (base)graphics_object classes * libinterp/corefcn/graphics.cc: implement base_graphics_object::value_as_string method. * libinterp/corefcn/graphics.cc: set: when 2 arguments are provided, if the second is a property name, either return a cell array containing allowed values or print them. diff -r 95466a42bcba -r ca84d3c9dc24 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Fri Dec 06 16:45:38 2013 -0500 +++ b/libinterp/corefcn/graphics.cc Sat Dec 07 15:56:43 2013 +0100 @@ -2985,6 +2985,34 @@ return retval; } +std::string +base_graphics_object::value_as_string (std::string prop) +{ + std::string retval; + + if (valid_object ()) + { + if (prop != "children") + { + property p = get_properties ().get_property (prop); + + if (p.ok () && ! p.is_hidden ()) + { + if (p.is_radio ()) + { + retval += p.values_as_string (); + } + } + } + if (retval != "") + retval += "\n"; + } + else + error ("base_graphics_object::value_as_string: invalid graphics object"); + + return retval; +} + octave_scalar_map base_graphics_object::values_as_struct (void) { @@ -8721,6 +8749,29 @@ { obj.set (args(1).map_value ()); } + else if (nargin == 2 && args(1).is_string ()) + { + std::string property = args(1).string_value (); + + octave_map pmap = obj.values_as_struct (); + + if (pmap.isfield (property)) + { + if (nargout != 0) + retval = pmap.getfield (property)(0); + else + { + std::string s = obj.value_as_string (property); + if (! error_state) + octave_stdout << s; + } + } + else + { + error ("set: unknown property"); + break; + } + } else if (nargin == 1) { if (nargout != 0) diff -r 95466a42bcba -r ca84d3c9dc24 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Fri Dec 06 16:45:38 2013 -0500 +++ b/libinterp/corefcn/graphics.in.h Sat Dec 07 15:56:43 2013 +0100 @@ -2706,6 +2706,8 @@ virtual std::string values_as_string (void); + virtual std::string value_as_string (std::string prop); + virtual octave_scalar_map values_as_struct (void); virtual graphics_handle get_parent (void) const @@ -2977,6 +2979,11 @@ std::string values_as_string (void) { return rep->values_as_string (); } + std::string value_as_string (std::string prop) + { + return rep->value_as_string (prop); + } + octave_map values_as_struct (void) { return rep->values_as_struct (); } graphics_handle get_parent (void) const { return rep->get_parent (); }