diff src/graphics.cc @ 11250:830b940e7ff4

Turn xget_ancestor into regular API
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 14 Nov 2010 21:51:45 +0000
parents 5fa7667f90e5
children fe11e2b9d48a
line wrap: on
line diff
--- a/src/graphics.cc	Sun Nov 14 22:01:20 2010 +0100
+++ b/src/graphics.cc	Sun Nov 14 21:51:45 2010 +0000
@@ -55,8 +55,6 @@
 
 // forward declarations
 static octave_value xget (const graphics_handle& h, const caseless_str& name);
-graphics_object xget_ancestor (const graphics_object& go_arg,
-                                      const std::string& type);
 
 static void
 gripe_set_invalid (const std::string& pname)
@@ -460,7 +458,7 @@
                        const caseless_str& to_units)
 {
   graphics_object go = gh_manager::get_object (props.get___myhandle__ ());
-  graphics_object ax = xget_ancestor (go, "axes");
+  graphics_object ax = go.get_ancestor ("axes");
 
   Matrix retval (1, pos.numel (), 0);
 
@@ -541,26 +539,6 @@
   return convert_position (sz, obj.get ("units").string_value (), "pixels", sz.extract_n (0, 2, 1, 2)).extract_n (0, 2, 1, 2);
 }
 
-graphics_object
-xget_ancestor (const graphics_object& go_arg, const std::string& type)
-{
-  graphics_object go = go_arg;
-
-  do
-    {
-      if (go.valid_object ())
-        {
-          if (go.isa (type))
-            return go;
-          else
-            go = gh_manager::get_object (go.get_parent ());
-        }
-      else
-        return graphics_object ();
-    }
- while (true);
-}
-
 static void
 convert_cdata_2 (bool is_scaled, double clim_0, double clim_1,
                  const double *cmapv, double x, octave_idx_type lda,
@@ -615,7 +593,7 @@
   Matrix clim (1, 2, 0.0);
 
   graphics_object go = gh_manager::get_object (props.get___myhandle__ ());
-  graphics_object fig = xget_ancestor (go, "figure");
+  graphics_object fig = go.get_ancestor ("figure");
 
   if (fig.valid_object ())
     {
@@ -627,7 +605,7 @@
 
   if (is_scaled)
     {
-      graphics_object ax = xget_ancestor (go, "axes");
+      graphics_object ax = go.get_ancestor ("axes");
 
       if (ax.valid_object ())
         {
@@ -2555,6 +2533,20 @@
   return retval;
 }
 
+graphics_object
+graphics_object::get_ancestor (const std::string& type) const
+{
+  if (valid_object ())
+    {
+      if (isa (type))
+        return *this;
+      else
+        return gh_manager::get_object (get_parent ()).get_ancestor (type);
+    }
+  else
+    return graphics_object ();
+}
+
 // ---------------------------------------------------------------------
 
 #include "graphics-props.cc"