Mercurial > hg > octave-lyh
changeset 7964:9cd3ee5298a0
Use common rep/class pattern for graphics events
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 22 Jul 2008 16:03:19 -0400 |
parents | bd3fa5ca55e6 |
children | 6a6a030a3517 |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 146 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2008-07-22 Michael Goffioul <michael.goffioul@gmail.com> + + * graphics.h.in (class base_graphics_event, class graphics_event): New + classes (replace gh_manager::event_data). + (class gh_manager::event_data): Remove. + (gh_manager::post_function, gh_manager::do_post_function): Use + graphics_event::event_fcn type. + (gh_manager::event_queue, gh_manager::do_post_event): Use + graphics_event type. + * graphics.cc (class callback_event, class function_event, class + set_event): Renamed from xxx_data classes. + (graphics_event::create_callback_event, + graphics_event::create_function_event, + graphics_event::create_set_event): Renamed from gh_manager::xxx + equivalent methods, removed reference count increment. + (gh_manager::do_post_event): Likewise. + (gh_manager::do_post_event): Use graphics_event type. + (gh_manager::do_post_function): Use graphics_event::event_fcn type. + 2008-07-22 John W. Eaton <jwe@octave.org> * version.h (OCTAVE_VERSION): Now 3.1.51+.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -3566,12 +3566,12 @@ } class -callback_event_data : public gh_manager::event_data +callback_event : public base_graphics_event { public: - callback_event_data (const graphics_handle& h, const std::string& name, - const octave_value& data = Matrix ()) - : gh_manager::event_data (0), handle (h), callback_name (name), + callback_event (const graphics_handle& h, const std::string& name, + const octave_value& data = Matrix ()) + : base_graphics_event (), handle (h), callback_name (name), callback_data (data) { } void execute (void) @@ -3580,8 +3580,8 @@ } private: - callback_event_data (void) - : gh_manager::event_data (0) { } + callback_event (void) + : base_graphics_event () { } private: graphics_handle handle; @@ -3590,11 +3590,11 @@ }; class -function_event_data : public gh_manager::event_data +function_event : public base_graphics_event { public: - function_event_data (gh_manager::event_fcn fcn, void* data = 0) - : gh_manager::event_data (0), function (fcn), + function_event (graphics_event::event_fcn fcn, void* data = 0) + : base_graphics_event (), function (fcn), function_data (data) { } void execute (void) @@ -3603,21 +3603,21 @@ } private: - function_event_data (void) - : gh_manager::event_data (0) { } + function_event (void) + : base_graphics_event () { } private: - gh_manager::event_fcn function; + graphics_event::event_fcn function; void* function_data; }; class -set_event_data : public gh_manager::event_data +set_event : public base_graphics_event { public: - set_event_data (const graphics_handle& h, const std::string& name, - const octave_value& value) - : gh_manager::event_data (0), handle (h), property_name (name), + set_event (const graphics_handle& h, const std::string& name, + const octave_value& value) + : base_graphics_event (), handle (h), property_name (name), property_value (value) { } void execute (void) @@ -3628,8 +3628,8 @@ } private: - set_event_data (void) - : gh_manager::event_data (0) { } + set_event (void) + : base_graphics_event () { } private: graphics_handle handle; @@ -3637,43 +3637,37 @@ octave_value property_value; }; -gh_manager::event_data -gh_manager::event_data::create_callback_event (const graphics_handle& h, - const std::string& name, - const octave_value& data) +graphics_event +graphics_event::create_callback_event (const graphics_handle& h, + const std::string& name, + const octave_value& data) { - event_data e; - - e.rep = new callback_event_data (h, name, data); - - e.rep->refcount++; + graphics_event e; + + e.rep = new callback_event (h, name, data); return e; } -gh_manager::event_data -gh_manager::event_data::create_function_event (gh_manager::event_fcn fcn, - void *data) +graphics_event +graphics_event::create_function_event (graphics_event::event_fcn fcn, + void *data) { - event_data e; - - e.rep =new function_event_data (fcn, data); - - e.rep->refcount++; + graphics_event e; + + e.rep = new function_event (fcn, data); return e; } -gh_manager::event_data -gh_manager::event_data::create_set_event (const graphics_handle& h, - const std::string& name, - const octave_value& data) +graphics_event +graphics_event::create_set_event (const graphics_handle& h, + const std::string& name, + const octave_value& data) { - event_data e; - - e.rep = new set_event_data (h, name, data); - - e.rep->refcount++; + graphics_event e; + + e.rep = new set_event (h, name, data); return e; } @@ -3769,7 +3763,7 @@ } void -gh_manager::do_post_event (const event_data& e) +gh_manager::do_post_event (const graphics_event& e) { event_queue.push_back (e); @@ -3787,19 +3781,19 @@ if (go.valid_object ()) { if (callback_objects.empty ()) - do_post_event (event_data::create_callback_event (h, name, data)); + do_post_event (graphics_event::create_callback_event (h, name, data)); else { const graphics_object& current = callback_objects.front (); if (current.get_properties ().is_interruptible ()) - do_post_event (event_data::create_callback_event (h, name, data)); + do_post_event (graphics_event::create_callback_event (h, name, data)); else { caseless_str busy_action (go.get_properties ().get_busyaction ()); if (busy_action.compare ("queue")) - do_post_event (event_data::create_callback_event (h, name, data)); + do_post_event (graphics_event::create_callback_event (h, name, data)); else { caseless_str cname (name); @@ -3809,7 +3803,7 @@ || (go.isa ("figure") && (cname.compare ("closerequestfcn") || cname.compare ("resizefcn")))) - do_post_event (event_data::create_callback_event (h, name, data)); + do_post_event (graphics_event::create_callback_event (h, name, data)); } } } @@ -3817,11 +3811,11 @@ } void -gh_manager::do_post_function (event_fcn fcn, void* fcn_data) +gh_manager::do_post_function (graphics_event::event_fcn fcn, void* fcn_data) { gh_manager::autolock guard; - do_post_event (event_data::create_function_event (fcn, fcn_data)); + do_post_event (graphics_event::create_function_event (fcn, fcn_data)); } void @@ -3830,17 +3824,17 @@ { gh_manager::autolock guard; - do_post_event (event_data::create_set_event (h, name, value)); + do_post_event (graphics_event::create_set_event (h, name, value)); } int gh_manager::do_process_events (bool force) { - event_data e; + graphics_event e; do { - e = event_data (); + e = graphics_event (); gh_manager::lock ();
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -3491,6 +3491,81 @@ // --------------------------------------------------------------------- +class graphics_event; + +class +base_graphics_event +{ +public: + friend class graphics_event; + + base_graphics_event (void) : count (1) { } + + virtual ~base_graphics_event (void) { } + + virtual void execute (void) = 0; + +private: + int count; +}; + +class +graphics_event +{ +public: + typedef void (*event_fcn) (void*); + + graphics_event (void) : rep (0) { } + + graphics_event (const graphics_event& e) + { + rep = e.rep; + rep->count++; + } + + ~graphics_event (void) + { + if (rep && --rep->count == 0) + delete rep; + } + + graphics_event& operator = (const graphics_event& e) + { + if (rep != e.rep) + { + if (rep && --rep->count == 0) + delete rep; + + rep = e.rep; + if (rep) + rep->count++; + } + + return *this; + } + + void execute (void) + { if (rep) rep->execute (); } + + bool ok (void) const + { return (rep != 0); } + + static graphics_event + create_callback_event (const graphics_handle& h, + const std::string& name, + const octave_value& data = Matrix ()); + + static graphics_event + create_function_event (event_fcn fcn, void *data = 0); + + static graphics_event + create_set_event (const graphics_handle& h, + const std::string& name, + const octave_value& value); +private: + base_graphics_event *rep; +}; + class OCTINTERP_API gh_manager { protected: @@ -3499,8 +3574,6 @@ public: - typedef void (*event_fcn) (void*); - static bool instance_ok (void) { bool retval = true; @@ -3620,7 +3693,7 @@ instance->do_post_callback (h, name, data); } - static void post_function (event_fcn fcn, void* data = 0) + static void post_function (graphics_event::event_fcn fcn, void* data = 0) { if (instance_ok ()) instance->do_post_function (fcn, data); @@ -3659,73 +3732,6 @@ autolock& operator = (const autolock&); }; -public: - class event_data - { - public: - event_data (void) : rep (0) { } - - event_data (const event_data& d) - { - rep = d.rep; - if (rep) - rep->refcount++; - } - - virtual ~event_data (void) - { - if (rep && --rep->refcount == 0) - { - delete rep; - rep = 0; - } - } - - event_data& operator = (const event_data& d) - { - if (d.rep != rep) - { - if (rep && --rep->refcount == 0) - delete rep; - - rep = d.rep; - if (rep) - rep->refcount++; - } - - return *this; - } - - virtual void execute (void) - { if (rep) rep->execute (); } - - bool ok (void) const { return (rep != 0); } - - static event_data - create_callback_event (const graphics_handle& h, - const std::string& name, - const octave_value& data = Matrix ()); - - static event_data - create_function_event (event_fcn fcn, void *data = 0); - - static event_data - create_set_event (const graphics_handle& h, - const std::string& name, - const octave_value& value); - - protected: - explicit event_data (int /* dummy */) - : refcount (0) { } - - private: - union - { - event_data *rep; - int refcount; - }; - }; - private: static gh_manager *instance; @@ -3756,7 +3762,7 @@ octave_mutex graphics_lock; // The list of event queued by backends - std::list<event_data> event_queue; + std::list<graphics_event> event_queue; // The stack of callback objects std::list<graphics_object> callback_objects; @@ -3829,7 +3835,7 @@ void do_post_callback (const graphics_handle& h, const std::string name, const octave_value& data); - void do_post_function (event_fcn fcn, void* fcn_data); + void do_post_function (graphics_event::event_fcn fcn, void* fcn_data); void do_post_set (const graphics_handle& h, const std::string name, const octave_value& value); @@ -3844,7 +3850,7 @@ void do_restore_gcbo (void); - void do_post_event (const event_data& e); + void do_post_event (const graphics_event& e); };