changeset 6836:ea6ae3af82d1

[project @ 2007-08-27 19:50:22 by jwe]
author jwe
date Mon, 27 Aug 2007 19:50:23 +0000
parents 293913e2b15b
children 7eefeed173ea
files src/ChangeLog src/graphics.cc src/graphics.h
diffstat 3 files changed, 251 insertions(+), 223 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Aug 27 19:27:39 2007 +0000
+++ b/src/ChangeLog	Mon Aug 27 19:50:23 2007 +0000
@@ -1,5 +1,11 @@
 2007-08-27  John W. Eaton  <jwe@octave.org>
 
+	* graphics.cc (base_properties::mark_modified,
+	base_properties::override_defaults,
+	base_properties::delete_children, figure::get_default,
+	axes::get_default): Move definitions here, from graphics.h.
+	* graphics.h (class gh_manager): Move decl to end of file.
+
 	* Cell.h (Cell::Cell (const octave_value_list&)): Create row
 	vector instead of column vector.
 
--- a/src/graphics.cc	Mon Aug 27 19:27:39 2007 +0000
+++ b/src/graphics.cc	Mon Aug 27 19:50:23 2007 +0000
@@ -687,7 +687,8 @@
     }
 }
 
-void base_properties::set_parent (const octave_value& val)
+void
+base_properties::set_parent (const octave_value& val)
 {
   double tmp = val.double_value ();
 
@@ -715,6 +716,30 @@
 }
 
 void
+base_properties::mark_modified (void)
+{
+  __modified__ = true;
+  graphics_object parent_obj = gh_manager::get_object (parent);
+  parent_obj.mark_modified ();
+}
+
+void
+base_properties::override_defaults (base_graphics_object& obj)
+{
+  graphics_object parent_obj = gh_manager::get_object (parent);
+  parent_obj.override_defaults (obj);
+}
+
+void
+base_properties::delete_children (void)
+{
+  octave_idx_type n = children.numel ();
+
+  for (octave_idx_type i = 0; i < n; i++)
+    gh_manager::free (children(i));
+}
+
+void
 root_figure::root_figure_properties::set (const property_name& name,
 					  const octave_value& val)
 {
@@ -896,7 +921,8 @@
   return retval;
 }
 
-void figure::figure_properties::close (void)
+void
+figure::figure_properties::close (void)
 {
   if (! __plot_stream__.is_empty ())
     {
@@ -914,7 +940,8 @@
   xset (0, "currentfigure", gh_manager::current_figure ());
 }
 
-property_list::pval_map_type figure::figure_properties::factory_defaults (void)
+property_list::pval_map_type
+figure::figure_properties::factory_defaults (void)
 {
   property_list::pval_map_type m;
 
@@ -927,6 +954,22 @@
   return m;
 }
 
+octave_value
+figure::get_default (const property_name& name) const
+{
+  octave_value retval = default_properties.lookup (name);
+
+  if (retval.is_undefined ())
+    {
+      graphics_handle parent = get_parent ();
+      graphics_object parent_obj = gh_manager::get_object (parent);
+
+      retval = parent_obj.get_default (name);
+    }
+
+  return retval;
+}
+
 std::string figure::figure_properties::go_name ("figure");
 
 // ---------------------------------------------------------------------
@@ -1524,7 +1567,8 @@
     gh_manager::free (zlabel);
 }
 
-property_list::pval_map_type axes::axes_properties::factory_defaults (void)
+property_list::pval_map_type
+axes::axes_properties::factory_defaults (void)
 {
   property_list::pval_map_type m;
 
@@ -1600,6 +1644,22 @@
   return m;
 }
 
+octave_value
+axes::get_default (const property_name& name) const
+{
+  octave_value retval = default_properties.lookup (name);
+
+  if (retval.is_undefined ())
+    {
+      graphics_handle parent = get_parent ();
+      graphics_object parent_obj = gh_manager::get_object (parent);
+
+      retval = parent_obj.get_default (name);
+    }
+
+  return retval;
+}
+
 std::string axes::axes_properties::go_name ("axes");
 
 // ---------------------------------------------------------------------
@@ -1766,7 +1826,8 @@
   return retval;
 }
 
-property_list::pval_map_type line::line_properties::factory_defaults (void)
+property_list::pval_map_type
+line::line_properties::factory_defaults (void)
 {
   property_list::pval_map_type m;
 
@@ -1989,7 +2050,8 @@
   return retval;
 }
 
-property_list::pval_map_type image::image_properties::factory_defaults (void)
+property_list::pval_map_type
+image::image_properties::factory_defaults (void)
 {
   property_list::pval_map_type m;
 
@@ -2145,7 +2207,8 @@
   return retval;
 }
 
-property_list::pval_map_type patch::patch_properties::factory_defaults (void)
+property_list::pval_map_type
+patch::patch_properties::factory_defaults (void)
 {
   property_list::pval_map_type m;
 
--- a/src/graphics.h	Mon Aug 27 19:27:39 2007 +0000
+++ b/src/graphics.h	Mon Aug 27 19:50:23 2007 +0000
@@ -633,176 +633,6 @@
   base_graphics_object *rep;
 };
 
-// ---------------------------------------------------------------------
-
-class gh_manager
-{
-protected:
-
-  gh_manager (void);
-
-public:
-
-  static bool instance_ok (void)
-  {
-    bool retval = true;
-
-    if (! instance)
-      instance = new gh_manager ();
-
-    if (! instance)
-      {
-	::error ("unable to create gh_manager!");
-
-	retval = false;
-      }
-
-    return retval;
-  }
-
-  static void free (const graphics_handle& h)
-  {
-    if (instance_ok ())
-      instance->do_free (h);
-  }
-
-  static graphics_handle lookup (double val)
-  {
-    return instance_ok () ? instance->do_lookup (val) : graphics_handle ();
-  }
-
-  static graphics_object get_object (const graphics_handle& h)
-  {
-    return instance_ok () ? instance->do_get_object (h) : graphics_object ();
-  }
-
-  static graphics_handle
-  make_graphics_handle (const std::string& go_name,
-			const graphics_handle& parent)
-  {
-    return instance_ok ()
-      ? instance->do_make_graphics_handle (go_name, parent) : octave_NaN;
-  }
-
-  static graphics_handle make_figure_handle (double val)
-  {
-    return instance_ok ()
-      ? instance->do_make_figure_handle (val) : octave_NaN;
-  }
-
-  static void push_figure (const graphics_handle& h)
-  {
-    if (instance_ok ())
-      instance->do_push_figure (h);
-  }
-
-  static void pop_figure (const graphics_handle& h)
-  {
-    if (instance_ok ())
-      instance->do_pop_figure (h);
-  }
-
-  static graphics_handle current_figure (void)
-  {
-    return instance_ok () ? instance->do_current_figure () : octave_NaN;
-  }
-
-  static Matrix handle_list (void)
-  {
-    return instance_ok () ? instance->do_handle_list () : Matrix ();
-  }
-
-  static Matrix figure_handle_list (void)
-  {
-    return instance_ok () ? instance->do_figure_handle_list () : Matrix ();
-  }
-
-private:
-
-  static gh_manager *instance;
-
-  typedef std::map<graphics_handle, graphics_object>::iterator iterator;
-  typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator;
-
-  typedef std::set<graphics_handle>::iterator free_list_iterator;
-  typedef std::set<graphics_handle>::const_iterator const_free_list_iterator;
-
-  typedef std::list<graphics_handle>::iterator figure_list_iterator;
-  typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator;
-
-  // A map of handles to graphics objects.
-  std::map<graphics_handle, graphics_object> handle_map;
-
-  // The available graphics handles.
-  std::set<graphics_handle> handle_free_list;
-
-  // The next handle available if handle_free_list is empty.
-  graphics_handle next_handle;
-
-  // The allocated figure handles.  Top of the stack is most recently
-  // created.
-  std::list<graphics_handle> figure_list;
-
-  graphics_handle get_handle (const std::string& go_name);
-
-  void do_free (const graphics_handle& h);
-
-  graphics_handle do_lookup (double val)
-  {
-    iterator p = handle_map.find (val);
-
-    return (p != handle_map.end ()) ? p->first : octave_NaN;
-  }
-
-  graphics_object do_get_object (const graphics_handle& h)
-  {
-    iterator p = handle_map.find (h);
-
-    return (p != handle_map.end ()) ? p->second : graphics_object ();
-  }
-
-  graphics_handle do_make_graphics_handle (const std::string& go_name,
-					   const graphics_handle& p);
-
-  graphics_handle do_make_figure_handle (double val);
-
-  Matrix do_handle_list (void)
-  {
-    Matrix retval (1, handle_map.size ());
-    octave_idx_type i = 0;
-    for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++)
-      retval(i++) = p->first;
-    return retval;
-  }
-
-  Matrix do_figure_handle_list (void)
-  {
-    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++)
-      retval(i++) = *p;
-    return retval;
-  }
-
-  void do_push_figure (const graphics_handle& h);
-
-  void do_pop_figure (const graphics_handle& h);
-
-  graphics_handle do_current_figure (void) const
-  {
-    return figure_list.empty () ? octave_NaN : figure_list.front ();
-  }
-};
-
-
-// This function is NOT equivalent to the scripting language function gcf.
-graphics_handle gcf (void);
-
-// This function is NOT equivalent to the scripting language function gca.
-graphics_handle gca (void);
-
 class base_properties
 {
 public:
@@ -816,18 +646,9 @@
 
   virtual std::string graphics_object_name (void) const = 0;
 
-  void mark_modified (void)
-  {
-    __modified__ = true;
-    graphics_object parent_obj = gh_manager::get_object (parent);
-    parent_obj.mark_modified ();
-  }
+  void mark_modified (void);
 
-  void override_defaults (base_graphics_object& obj)
-  {
-    graphics_object parent_obj = gh_manager::get_object (parent);
-    parent_obj.override_defaults (obj);
-  }
+  void override_defaults (base_graphics_object& obj);
 
   // Look through DEFAULTS for properties with given CLASS_NAME, and
   // apply them to the current object with set (virtual method).
@@ -851,13 +672,7 @@
 
   void reparent (const graphics_handle& new_parent) { parent = new_parent; }
 
-  virtual void delete_children (void)
-  {
-    octave_idx_type n = children.numel ();
-
-    for (octave_idx_type i = 0; i < n; i++)
-      gh_manager::free (children(i));
-  }
+  virtual void delete_children (void);
 
 protected:
   std::string type;
@@ -1105,20 +920,7 @@
     return retval;
   }
 
-  octave_value get_default (const property_name& name) const
-  {
-    octave_value retval = default_properties.lookup (name);
-
-    if (retval.is_undefined ())
-      {
-	graphics_handle parent = get_parent ();
-	graphics_object parent_obj = gh_manager::get_object (parent);
-
-	retval = parent_obj.get_default (name);
-      }
-
-    return retval;
-  }
+  octave_value get_default (const property_name& name) const;
 
   octave_value get_defaults (void) const
   {
@@ -1289,20 +1091,7 @@
     return retval;
   }
 
-  octave_value get_default (const property_name& name) const
-  {
-    octave_value retval = default_properties.lookup (name);
-
-    if (retval.is_undefined ())
-      {
-	graphics_handle parent = get_parent ();
-	graphics_object parent_obj = gh_manager::get_object (parent);
-
-	retval = parent_obj.get_default (name);
-      }
-
-    return retval;
-  }
+  octave_value get_default (const property_name& name) const;
 
   octave_value get_defaults (void) const
   {
@@ -1776,6 +1565,176 @@
 #undef OCTAVE_GRAPHICS_PROPERTY
 #undef OCTAVE_GRAPHICS_MUTABLE_PROPERTY
 
+// ---------------------------------------------------------------------
+
+class gh_manager
+{
+protected:
+
+  gh_manager (void);
+
+public:
+
+  static bool instance_ok (void)
+  {
+    bool retval = true;
+
+    if (! instance)
+      instance = new gh_manager ();
+
+    if (! instance)
+      {
+	::error ("unable to create gh_manager!");
+
+	retval = false;
+      }
+
+    return retval;
+  }
+
+  static void free (const graphics_handle& h)
+  {
+    if (instance_ok ())
+      instance->do_free (h);
+  }
+
+  static graphics_handle lookup (double val)
+  {
+    return instance_ok () ? instance->do_lookup (val) : graphics_handle ();
+  }
+
+  static graphics_object get_object (const graphics_handle& h)
+  {
+    return instance_ok () ? instance->do_get_object (h) : graphics_object ();
+  }
+
+  static graphics_handle
+  make_graphics_handle (const std::string& go_name,
+			const graphics_handle& parent)
+  {
+    return instance_ok ()
+      ? instance->do_make_graphics_handle (go_name, parent) : octave_NaN;
+  }
+
+  static graphics_handle make_figure_handle (double val)
+  {
+    return instance_ok ()
+      ? instance->do_make_figure_handle (val) : octave_NaN;
+  }
+
+  static void push_figure (const graphics_handle& h)
+  {
+    if (instance_ok ())
+      instance->do_push_figure (h);
+  }
+
+  static void pop_figure (const graphics_handle& h)
+  {
+    if (instance_ok ())
+      instance->do_pop_figure (h);
+  }
+
+  static graphics_handle current_figure (void)
+  {
+    return instance_ok () ? instance->do_current_figure () : octave_NaN;
+  }
+
+  static Matrix handle_list (void)
+  {
+    return instance_ok () ? instance->do_handle_list () : Matrix ();
+  }
+
+  static Matrix figure_handle_list (void)
+  {
+    return instance_ok () ? instance->do_figure_handle_list () : Matrix ();
+  }
+
+private:
+
+  static gh_manager *instance;
+
+  typedef std::map<graphics_handle, graphics_object>::iterator iterator;
+  typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator;
+
+  typedef std::set<graphics_handle>::iterator free_list_iterator;
+  typedef std::set<graphics_handle>::const_iterator const_free_list_iterator;
+
+  typedef std::list<graphics_handle>::iterator figure_list_iterator;
+  typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator;
+
+  // A map of handles to graphics objects.
+  std::map<graphics_handle, graphics_object> handle_map;
+
+  // The available graphics handles.
+  std::set<graphics_handle> handle_free_list;
+
+  // The next handle available if handle_free_list is empty.
+  graphics_handle next_handle;
+
+  // The allocated figure handles.  Top of the stack is most recently
+  // created.
+  std::list<graphics_handle> figure_list;
+
+  graphics_handle get_handle (const std::string& go_name);
+
+  void do_free (const graphics_handle& h);
+
+  graphics_handle do_lookup (double val)
+  {
+    iterator p = handle_map.find (val);
+
+    return (p != handle_map.end ()) ? p->first : octave_NaN;
+  }
+
+  graphics_object do_get_object (const graphics_handle& h)
+  {
+    iterator p = handle_map.find (h);
+
+    return (p != handle_map.end ()) ? p->second : graphics_object ();
+  }
+
+  graphics_handle do_make_graphics_handle (const std::string& go_name,
+					   const graphics_handle& p);
+
+  graphics_handle do_make_figure_handle (double val);
+
+  Matrix do_handle_list (void)
+  {
+    Matrix retval (1, handle_map.size ());
+    octave_idx_type i = 0;
+    for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++)
+      retval(i++) = p->first;
+    return retval;
+  }
+
+  Matrix do_figure_handle_list (void)
+  {
+    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++)
+      retval(i++) = *p;
+    return retval;
+  }
+
+  void do_push_figure (const graphics_handle& h);
+
+  void do_pop_figure (const graphics_handle& h);
+
+  graphics_handle do_current_figure (void) const
+  {
+    return figure_list.empty () ? octave_NaN : figure_list.front ();
+  }
+};
+
+
+// This function is NOT equivalent to the scripting language function gcf.
+graphics_handle gcf (void);
+
+// This function is NOT equivalent to the scripting language function gca.
+graphics_handle gca (void);
+
 #endif
 
 /*