changeset 19120:dc88c5784f74

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 <std::string, octave_value> * /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 <pval_pair>::erase
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 07 Sep 2014 10:47:20 +0200
parents bec5386bcdf5
children 3e0720bd6bfc
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h
diffstat 2 files changed, 84 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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<std::string, octave_value>
-                         (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
 {
--- 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 <std::string, octave_value> pval_pair;
+
+class pval_vector : public std::vector <pval_pair>
+{
+ 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 <pval_pair>::erase (it);
+  }
+
+};
+
 class property_list
 {
 public:
-  typedef std::map<std::string, octave_value> pval_map_type;
+  typedef pval_vector pval_map_type;
   typedef std::map<std::string, pval_map_type> plist_map_type;
 
   typedef pval_map_type::iterator pval_map_iterator;