eliminate code duplication in reset_default_properties methods
authorJohn W. Eaton <jwe@octave.org>
Fri Jun 25 07:22:45 2010 -0400 (23 months ago)
changeset 10756f72a761a784c
parent 10742 9d95d8ab7c3a
child 10757 551913ba1f85
eliminate code duplication in reset_default_properties methods
src/ChangeLog
src/graphics.cc
     1.1 --- a/src/ChangeLog	Fri Jun 25 08:46:17 2010 +0200
     1.2 +++ b/src/ChangeLog	Fri Jun 25 07:22:45 2010 -0400
     1.3 @@ -1,3 +1,10 @@
     1.4 +2010-06-25  John W. Eaton  <jwe@octave.org>
     1.5 +
     1.6 +	* graphics.cc (reset_default_properties): New static function.
     1.7 +	(root_figure::reset_default_properties,
     1.8 +	figure::reset_default_properties, axes::reset_default_properties):
     1.9 +	Use it to avoid duplicated code.
    1.10 +
    1.11  2010-06-24  Rik <octave@nomad.inbox5.com>
    1.12  
    1.13          * octave.cc: Add [FILE] to octave usage string (bug #30258).
     2.1 --- a/src/graphics.cc	Fri Jun 25 08:46:17 2010 +0200
     2.2 +++ b/src/graphics.cc	Fri Jun 25 07:22:45 2010 -0400
     2.3 @@ -2625,8 +2625,8 @@
     2.4  property_list
     2.5  root_figure::factory_properties = root_figure::init_factory_properties ();
     2.6  
     2.7 -void
     2.8 -root_figure::reset_default_properties (void)
     2.9 +static void
    2.10 +reset_default_properties (property_list& default_properties)
    2.11  {
    2.12    property_list new_defaults;
    2.13  
    2.14 @@ -2650,9 +2650,16 @@
    2.15              new_defaults.set (prefix + s, q->second);
    2.16          }
    2.17      }
    2.18 +
    2.19    default_properties = new_defaults;
    2.20  }
    2.21  
    2.22 +void
    2.23 +root_figure::reset_default_properties (void)
    2.24 +{
    2.25 +  ::reset_default_properties (default_properties);
    2.26 +}
    2.27 +
    2.28  // ---------------------------------------------------------------------
    2.29  
    2.30  void
    2.31 @@ -2800,29 +2807,7 @@
    2.32  void
    2.33  figure::reset_default_properties (void)
    2.34  {
    2.35 -  property_list new_defaults;
    2.36 -
    2.37 -  for (property_list::plist_map_const_iterator p = default_properties.begin ();
    2.38 -       p != default_properties.end (); p++)
    2.39 -    {
    2.40 -      const property_list::pval_map_type pval_map = p->second;
    2.41 -      std::string prefix = p->first;
    2.42 -      
    2.43 -      for (property_list::pval_map_const_iterator q = pval_map.begin ();
    2.44 -           q != pval_map.end ();
    2.45 -           q++)
    2.46 -        {
    2.47 -          std::string s = q->first;
    2.48 -
    2.49 -          if (prefix == "axes" && (s == "position" || s == "units"))
    2.50 -            new_defaults.set (prefix + s, q->second);
    2.51 -          else if (prefix == "figure" && (s == "position" || s == "units" 
    2.52 -                                          || s == "windowstyle" 
    2.53 -                                          || s == "paperunits"))
    2.54 -            new_defaults.set (prefix + s, q->second);
    2.55 -        }
    2.56 -    }
    2.57 -  default_properties = new_defaults;
    2.58 +  ::reset_default_properties (default_properties);
    2.59  }
    2.60  
    2.61  // ---------------------------------------------------------------------
    2.62 @@ -4345,29 +4330,7 @@
    2.63  void
    2.64  axes::reset_default_properties (void)
    2.65  {
    2.66 -  property_list new_defaults;
    2.67 -
    2.68 -  for (property_list::plist_map_const_iterator p = default_properties.begin ();
    2.69 -       p != default_properties.end (); p++)
    2.70 -    {
    2.71 -      const property_list::pval_map_type pval_map = p->second;
    2.72 -      std::string prefix = p->first;
    2.73 -      
    2.74 -      for (property_list::pval_map_const_iterator q = pval_map.begin ();
    2.75 -           q != pval_map.end ();
    2.76 -           q++)
    2.77 -        {
    2.78 -          std::string s = q->first;
    2.79 -
    2.80 -          if (prefix == "axes" && (s == "position" || s == "units"))
    2.81 -            new_defaults.set (prefix + s, q->second);
    2.82 -          else if (prefix == "figure" && (s == "position" || s == "units" 
    2.83 -                                          || s == "windowstyle" 
    2.84 -                                          || s == "paperunits"))
    2.85 -            new_defaults.set (prefix + s, q->second);
    2.86 -        }
    2.87 -    }
    2.88 -  default_properties = new_defaults;
    2.89 +  ::reset_default_properties (default_properties);
    2.90  }
    2.91  
    2.92  // ---------------------------------------------------------------------