Mercurial > hg > octave-terminal
changeset 7419:f62fb98f1da2
[project @ 2008-01-25 08:24:48 by jwe]
author | jwe |
---|---|
date | Fri, 25 Jan 2008 08:24:48 +0000 |
parents | 42b70df74c21 |
children | 4b17a7297e5d |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 151 insertions(+), 124 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2008-01-25 Michael Goffioul <michael.goffioul@gmail.com> + + * graphics.h.in (base_properties::get_backend, + base_graphics_object::get_backend, graphics_backend::get_backend): + New methods for convenient access to the backend. + (figure::get_backend, figure::set_backend): Remove. + * graphics.cc (base_properties::get_backend): New method. + (Fdrawnow): Use graphics_object::get_backend to simplify code. + 2008-01-24 Pascal Dupuis <Pascal.Dupuis@worldonline.be> * mxarray.h.in: Include <cstring>.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -1149,6 +1149,17 @@ gh_manager::free (children(i)); } +graphics_backend +base_properties::get_backend (void) const +{ + graphics_object go = gh_manager::get_object (get_parent ()); + + if (go) + return go.get_backend (); + else + return graphics_backend (); +} + // --------------------------------------------------------------------- class gnuplot_backend : public base_graphics_backend @@ -2466,9 +2477,7 @@ { graphics_object go = gh_manager::get_object (h); - figure::properties& fprops = dynamic_cast<figure::properties&> (go.get_properties ()); - - fprops.get_backend () + go.get_backend () .print_figure (h, term, file, mono, debug_file); } else
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -955,6 +955,121 @@ // --------------------------------------------------------------------- +class graphics_backend; + +class base_graphics_backend +{ +public: + friend class graphics_backend; + +public: + base_graphics_backend (const std::string& nm) + : name (nm), count (0) { } + + virtual ~base_graphics_backend (void) { } + + std::string get_name (void) const { return name; } + + virtual bool is_valid (void) const { return false; } + + virtual void close_figure (const octave_value&) const + { error ("close_figure: invalid graphics backend"); } + + virtual void redraw_figure (const graphics_handle&) const + { error ("redraw_figure: invalid graphics backend"); } + + virtual void print_figure (const graphics_handle&, const std::string&, + const std::string&, bool, + const std::string& = "") const + { error ("print_figure: invalid graphics backend"); } + + virtual Matrix get_canvas_size (const graphics_handle&) const + { + error ("get_canvas_size: invalid graphics backend"); + return Matrix (1, 2, 0.0); + } + +private: + std::string name; + int count; +}; + +class graphics_backend +{ +public: + graphics_backend (void) + : rep (new base_graphics_backend ("unknown")) + { + rep->count++; + } + + graphics_backend (base_graphics_backend* b) + : rep (b) + { + rep->count++; + } + + graphics_backend (const graphics_backend& b) + : rep (b.rep) + { + rep->count++; + } + + ~graphics_backend (void) + { + if (--rep->count == 0) + delete rep; + } + + graphics_backend& operator = (const graphics_backend& b) + { + if (rep != b.rep) + { + if (--rep->count == 0) + delete rep; + + rep = b.rep; + rep->count++; + } + + return *this; + } + + operator bool (void) const { return rep->is_valid (); } + + std::string get_name (void) const { return rep->get_name (); } + + void close_figure (const octave_value& pstream) const + { rep->close_figure (pstream); } + + void redraw_figure (const graphics_handle& fh) const + { rep->redraw_figure (fh); } + + void print_figure (const graphics_handle& fh, const std::string& term, + const std::string& file, bool mono, + const std::string& debug_file = "") const + { rep->print_figure (fh, term, file, mono, debug_file); } + + Matrix get_canvas_size (const graphics_handle& fh) const + { return rep->get_canvas_size (fh); } + + OCTINTERP_API static graphics_backend default_backend (void); + + static void register_backend (const graphics_backend& b) + { available_backends[b.get_name ()] = b; } + + static void unregister_backend (const std::string& name) + { available_backends.erase (name); } + +private: + base_graphics_backend *rep; + +private: + static std::map<std::string, graphics_backend> available_backends; +}; + +// --------------------------------------------------------------------- + class base_graphics_object; class OCTINTERP_API base_properties @@ -1068,6 +1183,8 @@ children(n) = h.value (); } + virtual graphics_backend get_backend (void) const; + void set_tag (const octave_value& val) { tag = val; } void set_parent (const octave_value& val); @@ -1465,6 +1582,17 @@ return type () == go_name; } + virtual graphics_backend get_backend (void) const + { + if (valid_object ()) + return get_properties ().get_backend (); + else + { + error ("base_graphics_object::get_backend: invalid graphics object"); + return graphics_backend (); + } + } + protected: // A reference count. int count; @@ -1629,123 +1757,10 @@ return props.get_cdata_property (); } -private: - base_graphics_object *rep; -}; - -// --------------------------------------------------------------------- - -class graphics_backend; - -class base_graphics_backend -{ -public: - friend class graphics_backend; - -public: - base_graphics_backend (const std::string& nm) - : name (nm), count (0) { } - - virtual ~base_graphics_backend (void) { } - - std::string get_name (void) const { return name; } - - virtual bool is_valid (void) const { return false; } - - virtual void close_figure (const octave_value&) const - { error ("close_figure: invalid graphics backend"); } - - virtual void redraw_figure (const graphics_handle&) const - { error ("redraw_figure: invalid graphics backend"); } - - virtual void print_figure (const graphics_handle&, const std::string&, - const std::string&, bool, - const std::string& = "") const - { error ("print_figure: invalid graphics backend"); } - - virtual Matrix get_canvas_size (const graphics_handle&) const - { - error ("get_canvas_size: invalid graphics backend"); - return Matrix (1, 2, 0.0); - } + graphics_backend get_backend (void) const { return rep->get_backend (); } private: - std::string name; - int count; -}; - -class graphics_backend -{ -public: - graphics_backend (void) - : rep (new base_graphics_backend ("unknown")) - { - rep->count++; - } - - graphics_backend (base_graphics_backend* b) - : rep (b) - { - rep->count++; - } - - graphics_backend (const graphics_backend& b) - : rep (b.rep) - { - rep->count++; - } - - ~graphics_backend (void) - { - if (--rep->count == 0) - delete rep; - } - - graphics_backend& operator = (const graphics_backend& b) - { - if (rep != b.rep) - { - if (--rep->count == 0) - delete rep; - - rep = b.rep; - rep->count++; - } - - return *this; - } - - operator bool (void) const { return rep->is_valid (); } - - std::string get_name (void) const { return rep->get_name (); } - - void close_figure (const octave_value& pstream) const - { rep->close_figure (pstream); } - - void redraw_figure (const graphics_handle& fh) const - { rep->redraw_figure (fh); } - - void print_figure (const graphics_handle& fh, const std::string& term, - const std::string& file, bool mono, - const std::string& debug_file = "") const - { rep->print_figure (fh, term, file, mono, debug_file); } - - Matrix get_canvas_size (const graphics_handle& fh) const - { return rep->get_canvas_size (fh); } - - OCTINTERP_API static graphics_backend default_backend (void); - - static void register_backend (const graphics_backend& b) - { available_backends[b.get_name ()] = b; } - - static void unregister_backend (const std::string& name) - { available_backends.erase (name); } - -private: - base_graphics_backend *rep; - -private: - static std::map<std::string, graphics_backend> available_backends; + base_graphics_object *rep; }; // --------------------------------------------------------------------- @@ -2013,12 +2028,6 @@ bool valid_object (void) const { return true; } - graphics_backend get_backend (void) const - { return xproperties.get_backend (); } - - void set_backend (const graphics_backend& b) - { xproperties.set_backend (b); } - private: property_list default_properties; };