# HG changeset patch # User Pantxo Diribarne # Date 1392738908 -3600 # Node ID 8d5cb159fbc7b51b6d296500e36dc75c6891b2ba # Parent 875f4510d6dc85138943f1c89db6a14f3791e5ba Add methods to determine if a graphic property is read-only (bug #41629). * genprops.awk: add *::properties::has_readonly_property and *::properties::readonly_property_names. * genprops.awk: modify base_properties::set to report early when a property is read-only. * graphics.in.h: add *::has_readonly_property methods to all graphics objects. diff -r 875f4510d6dc -r 8d5cb159fbc7 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Mon Mar 17 09:10:32 2014 -0700 +++ b/libinterp/corefcn/graphics.in.h Tue Feb 18 16:55:08 2014 +0100 @@ -2704,6 +2704,11 @@ return octave_value (); } + virtual bool has_readonly_property (const caseless_str& pname) const + { + return base_properties::has_readonly_property (pname); + } + virtual std::string values_as_string (void); virtual std::string value_as_string (const std::string& prop); @@ -2977,6 +2982,11 @@ return rep->get_factory_defaults (); } + bool has_readonly_property (const caseless_str& pname) const + { + return rep->has_readonly_property (pname); + } + std::string values_as_string (void) { return rep->values_as_string (); } std::string value_as_string (const std::string& prop) @@ -3237,6 +3247,14 @@ bool valid_object (void) const { return true; } void reset_default_properties (void); + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } private: property_list default_properties; @@ -3461,6 +3479,14 @@ bool valid_object (void) const { return true; } void reset_default_properties (void); + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } private: property_list default_properties; @@ -4183,6 +4209,14 @@ void reset_default_properties (void); + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + protected: void initialize (const graphics_object& go); @@ -4263,6 +4297,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -4428,6 +4470,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -4575,6 +4625,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -4699,6 +4757,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -4854,6 +4920,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -4932,6 +5006,14 @@ void update_axis_limits (const std::string& axis_type, const graphics_handle& h); + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + }; // --------------------------------------------------------------------- @@ -4993,6 +5075,14 @@ bool valid_object (void) const { return true; } + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + }; // --------------------------------------------------------------------- @@ -5040,6 +5130,14 @@ bool valid_object (void) const { return true; } + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + }; // --------------------------------------------------------------------- @@ -5132,6 +5230,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -5199,6 +5305,14 @@ const base_properties& get_properties (void) const { return xproperties; } bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } }; // --------------------------------------------------------------------- @@ -5286,6 +5400,14 @@ void reset_default_properties (void); + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + private: property_list default_properties; }; @@ -5338,6 +5460,14 @@ bool valid_object (void) const { return true; } + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + }; // --------------------------------------------------------------------- @@ -5391,6 +5521,14 @@ bool valid_object (void) const { return true; } + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + }; // --------------------------------------------------------------------- diff -r 875f4510d6dc -r 8d5cb159fbc7 libinterp/genprops.awk --- a/libinterp/genprops.awk Mon Mar 17 09:10:32 2014 -0700 +++ b/libinterp/genprops.awk Tue Feb 18 16:55:08 2014 +0100 @@ -290,7 +290,7 @@ if (class_name && ! base) emit_common_declarations(); - printf ("public:\n\n\n static std::set core_property_names (void);\n\n static bool has_core_property (const caseless_str& pname);\n\n std::set all_property_names (void) const;\n\n"); + printf ("public:\n\n\n static std::set core_property_names (void);\n\n static std::set readonly_property_names (void);\n\n static bool has_core_property (const caseless_str& pname);\n\n static bool has_readonly_property (const caseless_str& pname);\n\n std::set all_property_names (void) const;\n\n"); if (! base) printf (" bool has_property (const caseless_str& pname) const;\n\n"); @@ -470,7 +470,7 @@ class_name); if (! base) - printf (" const std::set& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", go_name, pnames, pname_arg);\n\n if (error_state)\n return;\n\n"); + printf (" const std::set& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", go_name, pnames, pname_arg);\n\n if (error_state)\n return;\n else if (has_readonly_property (pname))\n {\n error (\"set: \\\"%%s\\\" is read-only\", pname.c_str ());\n return;\n }\n\n"); first = 1; @@ -611,6 +611,7 @@ printf ("std::string %s::properties::go_name (\"%s\");\n\n", class_name, object_name); + ## core_property_names printf ("std::set\n"); if (base) printf ("base_properties"); @@ -622,7 +623,7 @@ if (! base) printf ("\n std::set base_pnames = base_properties::core_property_names ();\n all_pnames.insert (base_pnames.begin (), base_pnames.end ());\n"); printf ("\n initialized = true;\n }\n\n return all_pnames;\n}\n\n"); - + ## has_core_property printf ("bool\n"); if (base) printf ("base_properties"); @@ -630,6 +631,30 @@ printf ("%s::properties", class_name); printf ("::has_core_property (const caseless_str& pname)\n{\n std::set pnames = core_property_names ();\n\n return pnames.find (pname) != pnames.end ();\n}\n\n", class_name); + ## readonly_property_names + printf ("std::set\n"); + if (base) + printf ("base_properties"); + else + printf ("%s::properties", class_name); + printf ("::readonly_property_names (void)\n{\n static std::set all_pnames;\n\n static bool initialized = false;\n\n if (! initialized)\n {\n"); + for (i = 1; i <= idx; i++) + if (readonly[i]) + { + printf (" all_pnames.insert (\"%s\");\n", name[i]); + } + if (! base) + printf ("\n std::set base_pnames = base_properties::readonly_property_names ();\n all_pnames.insert (base_pnames.begin (), base_pnames.end ());\n"); + printf ("\n initialized = true;\n }\n\n return all_pnames;\n}\n\n"); + ## has_readonly_property + printf ("bool\n"); + if (base) + printf ("base_properties"); + else + printf ("%s::properties", class_name); + printf ("::has_readonly_property (const caseless_str& pname)\n{\n std::set pnames = readonly_property_names ();\n\n return pnames.find (pname) != pnames.end ();\n}\n\n", class_name); + + ## all_property_names printf ("std::set\n"); if (base) printf ("base_properties");