changeset 21880:a6952c880cec

maint: Use 'auto' in graphics.cc, graphics.in.h files. * graphics.cc, graphics.in.h: Use 'auto' keyword.
author Rik <rik@octave.org>
date Sun, 12 Jun 2016 21:37:49 -0700
parents 1315aa0ca466
children aea1bf9493c0
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h
diffstat 2 files changed, 92 insertions(+), 121 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Sun Jun 12 13:46:42 2016 -0700
+++ b/libinterp/corefcn/graphics.cc	Sun Jun 12 21:37:49 2016 -0700
@@ -82,18 +82,15 @@
   size_t len = pname.length ();
   std::set<std::string> matches;
 
-  for (std::set<std::string>::const_iterator p = pnames.begin ();
-       p != pnames.end (); p++)
-    {
-      if (pname.compare (*p, len))
-        {
-          if (len == p->length ())
-            {
-              // Exact match.
-              return pname;
-            }
-
-          matches.insert (*p);
+  // Find exact or partial matches to property name
+  for (const auto& propnm : pnames)
+    {
+      if (pname.compare (propnm, len))
+        {
+          if (len == propnm.length ())
+            return pname;  // Exact match.
+
+          matches.insert (propnm);
         }
     }
 
@@ -118,7 +115,6 @@
   else if (num_matches == 1)
     {
       // Exact match was handled above.
-
       std::string possible_match = *(matches.begin ());
 
       warning_with_id ("Octave:abbreviated-property-match",
@@ -1433,8 +1429,9 @@
       xok = false;
 
       // check dimensional size constraints until a match is found
-      for (std::list<dim_vector>::const_iterator it = size_constraints.begin ();
-           ! xok && it != size_constraints.end (); ++it)
+      for (auto it = size_constraints.cbegin ();
+           ! xok && it != size_constraints.cend ();
+           ++it)
         {
           dim_vector itdims = (*it);
 
@@ -1603,27 +1600,25 @@
 
   if (! props.is_showhiddenhandles ())
     {
-      for (const_children_list_iterator p = children_list.begin ();
-           p != children_list.end (); p++)
-        {
-          graphics_handle kid = *p;
+      for (const auto& hchild : children_list)
+        {
+          graphics_handle kid = hchild;
 
           if (gh_manager::is_handle_visible (kid))
             {
               if (! return_hidden)
-                retval(k++) = *p;
+                retval(k++) = hchild;
             }
           else if (return_hidden)
-            retval(k++) = *p;
+            retval(k++) = hchild;
         }
 
       retval.resize (k, 1);
     }
   else
     {
-      for (const_children_list_iterator p = children_list.begin ();
-           p != children_list.end (); p++)
-        retval(k++) = *p;
+      for (const auto& hchild : children_list)
+        retval(k++) = hchild;
     }
 
   return retval;
@@ -1632,13 +1627,12 @@
 void
 children_property::do_delete_children (bool clear)
 {
-  for (children_list_iterator p = children_list.begin ();
-       p != children_list.end (); p++)
-    {
-      graphics_object go = gh_manager::get_object (*p);
+  for (auto& hchild : children_list)
+    {
+      graphics_object go = gh_manager::get_object (hchild);
 
       if (go.valid_object ())
-        gh_manager::free (*p);
+        gh_manager::free (hchild);
     }
 
   if (clear)
@@ -2175,10 +2169,8 @@
 
       const pval_map_type pval_map = p->second;
 
-      for (pval_map_const_iterator q = pval_map.begin ();
-           q != pval_map.end ();
-           q++)
-        m.assign (prefix + q->first, q->second);
+      for (const auto& prop_val_p : pval_map)
+        m.assign (prefix + prop_val_p.first, prop_val_p.second);
     }
 
   return m;
@@ -2557,12 +2549,11 @@
     handle_free_list.insert (std::ceil (old_gh.value ())
                              - make_handle_fraction ());
 
-  for (figure_list_iterator q = figure_list.begin ();
-       q != figure_list.end (); q++)
-    {
-      if (*q == old_gh)
-        {
-          *q = new_gh;
+  for (auto& hfig : figure_list)
+    {
+      if (hfig == old_gh)
+        {
+          hfig = new_gh;
           break;
         }
     }
@@ -2902,21 +2893,19 @@
 {
   std::string go_name = graphics_object_name ();
 
-  property_list::plist_map_const_iterator p = defaults.find (go_name);
-
-  if (p != defaults.end ())
-    {
-      const property_list::pval_map_type pval_map = p->second;
-
-      for (property_list::pval_map_const_iterator q = pval_map.begin ();
-           q != pval_map.end ();
-           q++)
-        {
-          std::string pname = q->first;
+  property_list::plist_map_const_iterator plist = defaults.find (go_name);
+
+  if (plist != defaults.end ())
+    {
+      const property_list::pval_map_type pval_map = plist->second;
+
+      for (const auto& prop_val_p : pval_map)
+        {
+          std::string pname = prop_val_p.first;
 
           try
             {
-              bgo.set (pname, q->second);
+              bgo.set (pname, prop_val_p.second);
             }
           catch (octave_execution_exception& e)
             {
@@ -3246,18 +3235,18 @@
 base_graphics_object::build_user_defaults_map (property_list::pval_map_type &def, const std::string go_name) const
 {
   property_list local_defaults = get_defaults_list ();
+  const auto it = local_defaults.find (go_name);
   property_list::plist_map_const_iterator p =
     local_defaults.find (go_name);
 
-  if (p != local_defaults.end ())
-    {
-      property_list::pval_map_type pval = p->second;
-      for (property_list::pval_map_const_iterator q = pval.begin ();
-           q != pval.end (); q++)
-        {
-          std::string pname = q->first;
+  if (it != local_defaults.end ())
+    {
+      property_list::pval_map_type pval = it->second;
+      for (const auto& prop_val_p : pval)
+        {
+          std::string pname = prop_val_p.first;
           if (def.find (pname) == def.end ())
-            def[pname] = q->second;
+            def[pname] = prop_val_p.second;
         }
     }
 
@@ -9295,13 +9284,11 @@
 void
 gh_manager::do_pop_figure (const graphics_handle& h)
 {
-  for (figure_list_iterator p = figure_list.begin ();
-       p != figure_list.end ();
-       p++)
-    {
-      if (*p == h)
-        {
-          figure_list.erase (p);
+  for (auto it = figure_list.begin (); it != figure_list.end (); it++)
+    {
+      if (*it == h)
+        {
+          figure_list.erase (it);
           break;
         }
     }
--- a/libinterp/corefcn/graphics.in.h	Sun Jun 12 13:46:42 2016 -0700
+++ b/libinterp/corefcn/graphics.in.h	Sun Jun 12 21:37:49 2016 -0700
@@ -862,25 +862,22 @@
 
     std::string first_match;
 
-    for (std::set<caseless_str>::const_iterator p = possible_vals.begin ();
-         p != possible_vals.end (); p++)
+    for (const auto& possible_val : possible_vals)
       {
-        if (p->compare (val, len))
+        if (possible_val.compare (val, len))
           {
-            if (len == p->length ())
+            if (len == possible_val.length ())
               {
-                // We found a full match (consider the case of val ==
-                // "replace" with possible values "replace" and
-                // "replacechildren").  Any other matches are
-                // irrelevant, so set match and return now.
-
-                match = *p;
+                // We found a full match (consider the case of val == "replace"
+                // with possible values "replace" and "replacechildren").  Any
+                // other matches are irrelevant, so set match and return now.
+                match = possible_val;
                 return true;
               }
             else
               {
                 if (k == 0)
-                  first_match = *p;
+                  first_match = possible_val;
 
                 k++;
               }
@@ -1650,12 +1647,11 @@
 
   void renumber (graphics_handle old_gh, graphics_handle new_gh)
   {
-    for (children_list_iterator p = children_list.begin ();
-         p != children_list.end (); p++)
+    for (auto& hchild : children_list)
       {
-        if (*p == old_gh)
+        if (hchild == old_gh)
           {
-            *p = new_gh.value ();
+            hchild = new_gh.value ();
             return;
           }
       }
@@ -1740,8 +1736,7 @@
   void do_init_children (const std::list<double>& val)
   {
     children_list.clear ();
-    for (const_children_list_iterator p = val.begin (); p != val.end (); p++)
-      children_list.push_front (*p);
+    children_list = val;
   }
 
   Matrix do_get_children (bool return_hidden) const;
@@ -1751,20 +1746,19 @@
     Matrix retval (children_list.size (), 1);
     octave_idx_type i = 0;
 
-    for (const_children_list_iterator p = children_list.begin ();
-         p != children_list.end (); p++)
-      retval(i++) = *p;
+    for (const auto& hchild : children_list)
+      retval(i++) = hchild;
+
     return retval;
   }
 
   bool do_remove_child (double child)
   {
-    for (children_list_iterator p = children_list.begin ();
-         p != children_list.end (); p++)
+    for (auto it = children_list.begin (); it != children_list.end (); it++)
       {
-        if (*p == child)
+        if (*it == child)
           {
-            children_list.erase (p);
+            children_list.erase (it);
             return true;
           }
       }
@@ -1958,9 +1952,9 @@
 
 // ---------------------------------------------------------------------
 
-typedef std::pair <std::string, octave_value> pval_pair;
-
-class pval_vector : public std::vector <pval_pair>
+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
@@ -2019,7 +2013,7 @@
 
   void erase (iterator it)
   {
-    std::vector <pval_pair>::erase (it);
+    std::vector<pval_pair>::erase (it);
   }
 
 };
@@ -2382,24 +2376,22 @@
 
   Cell do_available_toolkits_list (void) const
   {
-    Cell m (1 , available_toolkits.size ());
+    Cell m (1, available_toolkits.size ());
 
     octave_idx_type i = 0;
-    for (const_available_toolkits_iterator p = available_toolkits.begin ();
-         p != available_toolkits.end (); p++)
-      m(i++) = *p;
+    for (const auto& tkit : available_toolkits)
+      m(i++) = tkit;
 
     return m;
   }
 
   Cell do_loaded_toolkits_list (void) const
   {
-    Cell m (1 , loaded_toolkits.size ());
+    Cell m (1, loaded_toolkits.size ());
 
     octave_idx_type i = 0;
-    for (const_loaded_toolkits_iterator p = loaded_toolkits.begin ();
-         p != loaded_toolkits.end (); p++)
-      m(i++) = p->first;
+    for (const auto& nm_tkit_p : loaded_toolkits)
+      m(i++) = nm_tkit_p.first;
 
     return m;
   }
@@ -2414,8 +2406,7 @@
 
         p->second.close ();
 
-        // The toolkit may have unloaded itself.  If not, we'll do
-        // it here.
+        // The toolkit may have unloaded itself.  If not, we'll do it here.
         if (loaded_toolkits.find (name) != loaded_toolkits.end ())
           unload_toolkit (name);
       }
@@ -6322,7 +6313,8 @@
 
   graphics_handle do_lookup (double val)
   {
-    iterator p = (octave::math::isnan (val) ? handle_map.end () : handle_map.find (val));
+    iterator p = (octave::math::isnan (val) ? handle_map.end ()
+                                            : handle_map.find (val));
 
     return (p != handle_map.end ()) ? p->first : graphics_handle ();
   }
@@ -6347,9 +6339,9 @@
     Matrix retval (1, handle_map.size ());
 
     octave_idx_type i = 0;
-    for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++)
+    for (const auto& h_iter : handle_map)
       {
-        graphics_handle h = p->first;
+        graphics_handle h = h_iter.first;
 
         if (show_hidden || is_handle_visible (h))
           retval(i++) = h.value ();
@@ -6365,14 +6357,10 @@
     Matrix retval (1, figure_list.size ());
 
     octave_idx_type i = 0;
-    for (const_figure_list_iterator p = figure_list.begin ();
-         p != figure_list.end ();
-         p++)
+    for (const auto& hfig : figure_list)
       {
-        graphics_handle h = *p;
-
-        if (show_hidden || is_handle_visible (h))
-          retval(i++) = h.value ();
+        if (show_hidden || is_handle_visible (hfig))
+          retval(i++) = hfig.value ();
       }
 
     retval.resize (1, i);
@@ -6388,14 +6376,10 @@
   {
     graphics_handle retval;
 
-    for (const_figure_list_iterator p = figure_list.begin ();
-         p != figure_list.end ();
-         p++)
+    for (const auto& hfig : figure_list)
       {
-        graphics_handle h = *p;
-
-        if (is_handle_visible (h))
-          retval = h;
+        if (is_handle_visible (hfig))
+          retval = hfig;
       }
 
     return retval;