# HG changeset patch # User John W. Eaton # Date 1277464965 14400 # Node ID f72a761a784c19e44807c8ab00e90a34f9235146 # Parent 9d95d8ab7c3accbe538411228e8786bf0864c5c9 eliminate code duplication in reset_default_properties methods diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-06-25 John W. Eaton + + * 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.cc: Add [FILE] to octave usage string (bug #30258). diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -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); } // ---------------------------------------------------------------------