[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: general c++ question
From: |
John W. Eaton |
Subject: |
Re: general c++ question |
Date: |
Mon, 27 Aug 2007 16:07:01 -0400 |
On 27-Aug-2007, John W. Eaton wrote:
| On 3-Jul-2007, Shai Ayal wrote:
|
| | On 7/2/07, John W. Eaton <address@hidden> wrote:
| | > On 2-Jul-2007, Shai Ayal wrote:
| | >
| | > | OK, so it seems this isn't possible (google also seems to say this).
| | > | Unless there is some big objection, I will remove the nesting, i.e.
| | > | class XXX_properties will not be nested in class XXX.
| | >
| | > Before you do that, can you please explain why do you need to declare
| | > the function that returns properties before the property class has
| | > been fully declared?
| |
| | I thought of adding functions to access the individual XXX_properties
| | classes, so the a back-end written in c++ could gain access to these.
| | It seemed to me that the gh_manager class was a good place for these
| | functions since it would allow gaining access to properties using only
| | the handle. I though of using something similar to the ocave_value way
| | -- add const XXX::XXX_properties& XXX_properties_value() functions
| | However, all XXX_properties depend on base_property which in turn
| | depends on gh_manager which means I have to forward-declare the
| | XXX_properties before gh_manger. Since this is impossible to do with a
| | nested class my solution was to un-nest XXX_properties from XXX
|
| How about the following change instead? This makes it possible to
| move the declaration of gh_manager after all the graphics object types
| have been declared. If this change makes it possible for you to do
| what you need with nested classes, then I propose that we also rename
| the properties classes so that they are just figure::properties
| instead of figure::figure_properties (for example).
|
| jwe
Oops, this time with the diffs.
jwe
2007-08-27 John W. Eaton <address@hidden>
* 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.
Index: src/graphics.cc
===================================================================
RCS file: /cvs/octave/src/graphics.cc,v
retrieving revision 1.26
diff -u -u -r1.26 graphics.cc
--- src/graphics.cc 24 Aug 2007 20:25:39 -0000 1.26
+++ src/graphics.cc 27 Aug 2007 19:43:08 -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;
Index: src/graphics.h
===================================================================
RCS file: /cvs/octave/src/graphics.h,v
retrieving revision 1.10
diff -u -u -r1.10 graphics.h
--- src/graphics.h 24 Aug 2007 20:25:39 -0000 1.10
+++ src/graphics.h 27 Aug 2007 19:43:08 -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
/*
- Re: general c++ question, John W. Eaton, 2007/08/27
- Re: general c++ question,
John W. Eaton <=
- Re: general c++ question, Shai Ayal, 2007/08/28
- Re: general c++ question, John W. Eaton, 2007/08/28
- Re: general c++ question, Shai Ayal, 2007/08/29
- Re: general c++ question, John W. Eaton, 2007/08/29
- Re: general c++ question, Shai Ayal, 2007/08/29
- Re: general c++ question, John W. Eaton, 2007/08/29
- Re: general c++ question, John W. Eaton, 2007/08/31
- Re: general c++ question, Shai Ayal, 2007/08/31