changeset 9972:d32a6cc0193b

unshare dynamic properties
author John W. Eaton <jwe@octave.org>
date Fri, 11 Dec 2009 21:42:02 -0500
parents d0680ace5fcb
children cd8f355157b8
files src/ChangeLog src/genprops.awk src/graphics.cc src/graphics.h.in
diffstat 4 files changed, 49 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,31 @@
+2009-12-11  John W. Eaton  <jwe@octave.org>
+
+	* graphics.h.in (base_properties::all_dynamic_properties):
+	No longer static.
+	(base_properties::set (const caseless_str&, const octave_value&)):
+	Only provide decl, not definition.
+	(base_properties::set (const caseless_str&, const std::string&,
+	const octave_value&)): Delete.
+	(base_properties::dynamic_properties): Rename from
+	all_dynamic_properties.  No longer static.  Now protected.
+	(base_properties::has_dynamic_property,
+	base_properties::dynamic_property_names,
+	base_properties::set_dynamic): Omit class name argument.
+	* graphics.cc (base_properties::all_dynamic_properties):
+	Delete obsolete definition.
+	(base_properties::dynamic_property_names): Now const.
+	Omit class name argument.  Simply return dynamic_properties set.
+	(base_properties::has_dynamic_property): Omit class name argument.
+	Simply return dynamic_properties set.  Don't pass class name to
+	dynamic_property_names function.
+	(base_properties::set_dynamic): Omit class name argument.
+	Dynamic_properties is no longer a map.
+
+	* genprops.awk: Omit class name from arguments of generated
+	base_properties::all_property_names and base_properties::set
+	functions.  Don't pass class name to base_properties::set in
+	generated derived class set functions.
+
 2009-12-11  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.am (DOCSTRINGS): Use $(cp_update_rule) instead of
--- a/src/genprops.awk
+++ b/src/genprops.awk
@@ -264,12 +264,7 @@
   if (class_name && ! base)
     emit_common_declarations();
 
-  printf ("public:\n\n\n  static std::set<std::string> core_property_names (void);\n\n  static bool has_core_property (const caseless_str& pname);\n\n  std::set<std::string> all_property_names (");
-  if (base)
-    printf ("const std::string& cname");
-  else
-    printf ("void");
-  printf (") const;\n\n");
+  printf ("public:\n\n\n  static std::set<std::string> core_property_names (void);\n\n  static bool has_core_property (const caseless_str& pname);\n\n  std::set<std::string> all_property_names (void) const;\n\n");
 
   if (! base)
     printf ("  bool has_property (const caseless_str& pname) const;\n\n");
@@ -439,7 +434,7 @@
     ## set method
 
     if (base)
-      printf ("void\nbase_properties::set (const caseless_str& pname, const std::string& cname, const octave_value& val)\n{\n");
+      printf ("void\nbase_properties::set (const caseless_str& pname, const octave_value& val)\n{\n");
     else
       printf ("void\n%s::properties::set (const caseless_str& pname_arg, const octave_value& val)\n{\n",
               class_name);
@@ -460,9 +455,9 @@
     }
 
     if (base)
-      printf ("  else\n    set_dynamic (pname, cname, val);\n}\n\n");
+      printf ("  else\n    set_dynamic (pname, val);\n}\n\n");
     else
-      printf ("  else\n    base_properties::set (pname, \"%s\", val);\n}\n\n", class_name);
+      printf ("  else\n    base_properties::set (pname, val);\n}\n\n");
 
     ## get "all" method
 
@@ -610,16 +605,11 @@
 	printf ("base_properties");
     else
       printf ("%s::properties", class_name);
-    printf ("::all_property_names (");
+    printf ("::all_property_names (void) const\n{\n  static std::set<std::string> all_pnames = core_property_names ();\n\n");
     if (base)
-      printf ("const std::string& cname");
+      printf ("  std::set<std::string> retval = all_pnames;\n  std::set<std::string> dyn_props = dynamic_property_names ();\n  retval.insert (dyn_props.begin (), dyn_props.end ());\n  for (std::map<caseless_str, property, cmp_caseless_str>::const_iterator p = all_props.begin ();\n       p != all_props.end (); p++)\n    retval.insert (p->first);\n\n  return retval;\n}\n\n");
     else
-      printf ("void");
-    printf (") const\n{\n  static std::set<std::string> all_pnames = core_property_names ();\n\n");
-    if (base)
-      printf ("  std::set<std::string> retval = all_pnames;\n  std::set<std::string> dyn_props = dynamic_property_names (cname);\n  retval.insert (dyn_props.begin (), dyn_props.end ());\n  for (std::map<caseless_str, property, cmp_caseless_str>::const_iterator p = all_props.begin ();\n       p != all_props.end (); p++)\n    retval.insert (p->first);\n\n  return retval;\n}\n\n");
-    else
-      printf ("  std::set<std::string> retval = all_pnames;\n  std::set<std::string> base_props = base_properties::all_property_names (\"%s\");\n  retval.insert (base_props.begin (), base_props.end ());\n\n  return retval;\n}\n\n", class_name);
+      printf ("  std::set<std::string> retval = all_pnames;\n  std::set<std::string> base_props = base_properties::all_property_names ();\n  retval.insert (base_props.begin (), base_props.end ());\n\n  return retval;\n}\n\n");
 
     if (! base)
       printf ("bool\n%s::properties::has_property (const caseless_str& pname) const\n{\n  std::set<std::string> pnames = all_property_names ();\n\n  return pnames.find (pname) != pnames.end ();\n}\n\n", class_name);
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -1804,26 +1804,22 @@
   return m;
 }
 
-std::map<std::string, std::set<std::string> > base_properties::all_dynamic_properties;
-
 std::set<std::string>
-base_properties::dynamic_property_names (const std::string& cname)
-{
-  return all_dynamic_properties[cname];
+base_properties::dynamic_property_names (void) const
+{
+  return dynamic_properties;
 }
 
 bool
-base_properties::has_dynamic_property (const std::string& pname,
-				       const std::string& cname)
-{
-  const std::set<std::string>& dynprops = dynamic_property_names (cname);
+base_properties::has_dynamic_property (const std::string& pname)
+{
+  const std::set<std::string>& dynprops = dynamic_property_names ();
 
   return dynprops.find (pname) != dynprops.end ();
 }
 
 void
 base_properties::set_dynamic (const caseless_str& pname,
-			      const std::string& cname,
 			      const octave_value& val)
 {
   std::map<caseless_str, property, cmp_caseless_str>::iterator it = all_props.find (pname);
@@ -1835,7 +1831,7 @@
 
   if (! error_state)
     {
-      all_dynamic_properties[cname].insert (pname);
+      dynamic_properties.insert (pname);
 
       mark_modified ();
     }
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -1642,13 +1642,7 @@
       all_props[name] = p;
     }
 
-  virtual void set (const caseless_str&, const octave_value&)
-  {
-    panic_impossible ();
-  }
-
-  void set (const caseless_str& pname, const std::string& cname,
-	    const octave_value& val);
+  virtual void set (const caseless_str&, const octave_value&);
 
   virtual octave_value get (const caseless_str& pname) const;
 
@@ -1744,16 +1738,14 @@
     return ! handlevisibility.is ("off");
   }
 
-  static std::map<std::string, std::set<std::string> > all_dynamic_properties;
- 
-  static std::set<std::string> dynamic_property_names (const std::string& cname);
-
-  static bool has_dynamic_property (const std::string& pname,
-				    const std::string& cname);
+  std::set<std::string> dynamic_property_names (void) const;
+
+  bool has_dynamic_property (const std::string& pname);
 
 protected:
-  void set_dynamic (const caseless_str& pname, const std::string& cname,
-		    const octave_value& val);
+  std::set<std::string> dynamic_properties;
+ 
+  void set_dynamic (const caseless_str& pname, const octave_value& val);
 
   octave_value get_dynamic (const caseless_str& pname) const;