changeset 10733:f72a761a784c

eliminate code duplication in reset_default_properties methods
author John W. Eaton <jwe@octave.org>
date Fri, 25 Jun 2010 07:22:45 -0400
parents 9d95d8ab7c3a
children 551913ba1f85
files src/ChangeLog src/graphics.cc
diffstat 2 files changed, 18 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Jun 25 08:46:17 2010 +0200
+++ b/src/ChangeLog	Fri Jun 25 07:22:45 2010 -0400
@@ -1,3 +1,10 @@
+2010-06-25  John W. Eaton  <jwe@octave.org>
+
+	* graphics.cc (reset_default_properties): New static function.
+	(root_figure::reset_default_properties,
+	figure::reset_default_properties, axes::reset_default_properties):
+	Use it to avoid duplicated code.
+
 2010-06-24  Rik <octave@nomad.inbox5.com>
 
         * octave.cc: Add [FILE] to octave usage string (bug #30258).
--- a/src/graphics.cc	Fri Jun 25 08:46:17 2010 +0200
+++ b/src/graphics.cc	Fri Jun 25 07:22:45 2010 -0400
@@ -2625,8 +2625,8 @@
 property_list
 root_figure::factory_properties = root_figure::init_factory_properties ();
 
-void
-root_figure::reset_default_properties (void)
+static void
+reset_default_properties (property_list& default_properties)
 {
   property_list new_defaults;
 
@@ -2650,9 +2650,16 @@
             new_defaults.set (prefix + s, q->second);
         }
     }
+
   default_properties = new_defaults;
 }
 
+void
+root_figure::reset_default_properties (void)
+{
+  ::reset_default_properties (default_properties);
+}
+
 // ---------------------------------------------------------------------
 
 void
@@ -2800,29 +2807,7 @@
 void
 figure::reset_default_properties (void)
 {
-  property_list new_defaults;
-
-  for (property_list::plist_map_const_iterator p = default_properties.begin ();
-       p != default_properties.end (); p++)
-    {
-      const property_list::pval_map_type pval_map = p->second;
-      std::string prefix = p->first;
-      
-      for (property_list::pval_map_const_iterator q = pval_map.begin ();
-           q != pval_map.end ();
-           q++)
-        {
-          std::string s = q->first;
-
-          if (prefix == "axes" && (s == "position" || s == "units"))
-            new_defaults.set (prefix + s, q->second);
-          else if (prefix == "figure" && (s == "position" || s == "units" 
-                                          || s == "windowstyle" 
-                                          || s == "paperunits"))
-            new_defaults.set (prefix + s, q->second);
-        }
-    }
-  default_properties = new_defaults;
+  ::reset_default_properties (default_properties);
 }
 
 // ---------------------------------------------------------------------
@@ -4345,29 +4330,7 @@
 void
 axes::reset_default_properties (void)
 {
-  property_list new_defaults;
-
-  for (property_list::plist_map_const_iterator p = default_properties.begin ();
-       p != default_properties.end (); p++)
-    {
-      const property_list::pval_map_type pval_map = p->second;
-      std::string prefix = p->first;
-      
-      for (property_list::pval_map_const_iterator q = pval_map.begin ();
-           q != pval_map.end ();
-           q++)
-        {
-          std::string s = q->first;
-
-          if (prefix == "axes" && (s == "position" || s == "units"))
-            new_defaults.set (prefix + s, q->second);
-          else if (prefix == "figure" && (s == "position" || s == "units" 
-                                          || s == "windowstyle" 
-                                          || s == "paperunits"))
-            new_defaults.set (prefix + s, q->second);
-        }
-    }
-  default_properties = new_defaults;
+  ::reset_default_properties (default_properties);
 }
 
 // ---------------------------------------------------------------------