/* Copyright (C) 2008 Michael Goffioul This file is part of Octave. Octave is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see . */ #if !defined (graphics_backend_h) #define graphics_backend_h 1 #include "dMatrix.h" #include "graphics.h" 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 void close_figure (const figure::properties&) const { error ("close_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); } virtual Matrix get_figure_position (const graphics_handle&) const { error ("get_figure_position: invalid graphics backend"); return Matrix (1, 4, 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; } std::string get_name (void) const { return rep->get_name (); } void close_figure (const figure::properties& props) const { rep->close_figure (props); } Matrix get_canvas_size (const graphics_handle& fh) const { return rep->get_canvas_size (fh); } Matrix get_figure_position (const graphics_handle& fh) const { return rep->get_figure_position (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 available_backends; }; #endif /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */