# HG changeset patch # User Pantxo Diribarne # Date 1410079640 -7200 # Node ID dc88c5784f74d5b3182c59d32ab8217d67d3a442 # Parent bec5386bcdf550a26b4c95357caf41f8bd336175 Respect the order in which default graphics properties are set (bug #38449) * /libinterp/corefcn/graphics.cc (xreset_default_properties): use [] operator to store new prop/val * /libinterp/corefcn/graphics.cc: add %!test for bug #38449 * /libinterp/corefcn/graphics.in.h (pval_pair): new typedef for std::pair * /libinterp/corefcn/graphics.in.h (class pval_vector): new class to keep track of the order in which prop/val pairs are stored ** const_iterator find (const std::string pname), iterator find (const std::string pname)): mimic std::map::find ** octave_value lookup (const std::string pname)): mimic std::map::lookup ** octave_value& operator [] (const std::string pname)): mimic std::map [] operator ** void erase (const std::string pname): mimic std::map::erase ** void erase (iterator it): call std::vector ::erase diff -r bec5386bcdf5 -r dc88c5784f74 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Fri Sep 12 11:06:02 2014 -0400 +++ b/libinterp/corefcn/graphics.cc Sun Sep 07 10:47:20 2014 +0200 @@ -2775,8 +2775,7 @@ { // Store *mode prop/val in order to set them last if (pname.find ("mode") == (pname.length () - 4)) - pval.insert (std::pair - (pname, it->second)); + pval[pname] = it->second; else obj.set (pname, it->second); } @@ -2819,6 +2818,22 @@ } } +/* +## test defaults are set in the order they were stored +%!test +%! set(0, "defaultfigureunits", "normalized"); +%! set(0, "defaultfigureposition", [0.7 0 0.3 0.3]); +%! hf = figure ("visible", "off"); +%! tol = 20 * eps; +%! unwind_protect +%! assert (get (hf, "position"), [0.7 0 0.3 0.3], tol); +%! unwind_protect_cleanup +%! close (hf); +%! set(0, "defaultfigureunits", "remove"); +%! set(0, "defaultfigureposition", "remove"); +%! end_unwind_protect +*/ + octave_value base_properties::get_dynamic (const caseless_str& name) const { diff -r bec5386bcdf5 -r dc88c5784f74 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Fri Sep 12 11:06:02 2014 -0400 +++ b/libinterp/corefcn/graphics.in.h Sun Sep 07 10:47:20 2014 +0200 @@ -1989,10 +1989,76 @@ // --------------------------------------------------------------------- +typedef std::pair pval_pair; + +class pval_vector : public std::vector +{ + public: + const_iterator find (const std::string pname) const + { + const_iterator it; + + for (it = (*this).begin (); it != (*this).end (); it++) + if (pname.compare ((*it).first) == 0) + return it; + + return (*this).end (); + } + + iterator find (const std::string pname) + { + iterator it; + + for (it = (*this).begin (); it != (*this).end (); it++) + if (pname.compare ((*it).first) == 0) + return it; + + return (*this).end (); + } + + octave_value lookup (const std::string pname) const + { + octave_value retval; + + const_iterator it = find (pname); + + if (it != (*this).end ()) + retval = (*it).second; + + return retval; + } + + octave_value& operator [] (const std::string pname) + { + iterator it = find (pname); + + if (it == (*this).end ()) + { + push_back (pval_pair (pname, octave_value ())); + return (*this).back ().second; + } + + return (*it).second; + } + + void erase (const std::string pname) + { + iterator it = find (pname); + if (it != (*this).end ()) + erase (it); + } + + void erase (iterator it) + { + std::vector ::erase (it); + } + +}; + class property_list { public: - typedef std::map pval_map_type; + typedef pval_vector pval_map_type; typedef std::map plist_map_type; typedef pval_map_type::iterator pval_map_iterator;