comparison src/graphics.h.in @ 7419:f62fb98f1da2

[project @ 2008-01-25 08:24:48 by jwe]
author jwe
date Fri, 25 Jan 2008 08:24:48 +0000
parents 246f905cb984
children 65f0a8ced9d2
comparison
equal deleted inserted replaced
7418:42b70df74c21 7419:f62fb98f1da2
949 949
950 Octave_map as_struct (const std::string& prefix_arg) const; 950 Octave_map as_struct (const std::string& prefix_arg) const;
951 951
952 private: 952 private:
953 plist_map_type plist_map; 953 plist_map_type plist_map;
954 };
955
956 // ---------------------------------------------------------------------
957
958 class graphics_backend;
959
960 class base_graphics_backend
961 {
962 public:
963 friend class graphics_backend;
964
965 public:
966 base_graphics_backend (const std::string& nm)
967 : name (nm), count (0) { }
968
969 virtual ~base_graphics_backend (void) { }
970
971 std::string get_name (void) const { return name; }
972
973 virtual bool is_valid (void) const { return false; }
974
975 virtual void close_figure (const octave_value&) const
976 { error ("close_figure: invalid graphics backend"); }
977
978 virtual void redraw_figure (const graphics_handle&) const
979 { error ("redraw_figure: invalid graphics backend"); }
980
981 virtual void print_figure (const graphics_handle&, const std::string&,
982 const std::string&, bool,
983 const std::string& = "") const
984 { error ("print_figure: invalid graphics backend"); }
985
986 virtual Matrix get_canvas_size (const graphics_handle&) const
987 {
988 error ("get_canvas_size: invalid graphics backend");
989 return Matrix (1, 2, 0.0);
990 }
991
992 private:
993 std::string name;
994 int count;
995 };
996
997 class graphics_backend
998 {
999 public:
1000 graphics_backend (void)
1001 : rep (new base_graphics_backend ("unknown"))
1002 {
1003 rep->count++;
1004 }
1005
1006 graphics_backend (base_graphics_backend* b)
1007 : rep (b)
1008 {
1009 rep->count++;
1010 }
1011
1012 graphics_backend (const graphics_backend& b)
1013 : rep (b.rep)
1014 {
1015 rep->count++;
1016 }
1017
1018 ~graphics_backend (void)
1019 {
1020 if (--rep->count == 0)
1021 delete rep;
1022 }
1023
1024 graphics_backend& operator = (const graphics_backend& b)
1025 {
1026 if (rep != b.rep)
1027 {
1028 if (--rep->count == 0)
1029 delete rep;
1030
1031 rep = b.rep;
1032 rep->count++;
1033 }
1034
1035 return *this;
1036 }
1037
1038 operator bool (void) const { return rep->is_valid (); }
1039
1040 std::string get_name (void) const { return rep->get_name (); }
1041
1042 void close_figure (const octave_value& pstream) const
1043 { rep->close_figure (pstream); }
1044
1045 void redraw_figure (const graphics_handle& fh) const
1046 { rep->redraw_figure (fh); }
1047
1048 void print_figure (const graphics_handle& fh, const std::string& term,
1049 const std::string& file, bool mono,
1050 const std::string& debug_file = "") const
1051 { rep->print_figure (fh, term, file, mono, debug_file); }
1052
1053 Matrix get_canvas_size (const graphics_handle& fh) const
1054 { return rep->get_canvas_size (fh); }
1055
1056 OCTINTERP_API static graphics_backend default_backend (void);
1057
1058 static void register_backend (const graphics_backend& b)
1059 { available_backends[b.get_name ()] = b; }
1060
1061 static void unregister_backend (const std::string& name)
1062 { available_backends.erase (name); }
1063
1064 private:
1065 base_graphics_backend *rep;
1066
1067 private:
1068 static std::map<std::string, graphics_backend> available_backends;
954 }; 1069 };
955 1070
956 // --------------------------------------------------------------------- 1071 // ---------------------------------------------------------------------
957 1072
958 class base_graphics_object; 1073 class base_graphics_object;
1065 { 1180 {
1066 octave_idx_type n = children.numel (); 1181 octave_idx_type n = children.numel ();
1067 children.resize (1, n+1); 1182 children.resize (1, n+1);
1068 children(n) = h.value (); 1183 children(n) = h.value ();
1069 } 1184 }
1185
1186 virtual graphics_backend get_backend (void) const;
1070 1187
1071 void set_tag (const octave_value& val) { tag = val; } 1188 void set_tag (const octave_value& val) { tag = val; }
1072 1189
1073 void set_parent (const octave_value& val); 1190 void set_parent (const octave_value& val);
1074 1191
1463 bool isa (const std::string& go_name) const 1580 bool isa (const std::string& go_name) const
1464 { 1581 {
1465 return type () == go_name; 1582 return type () == go_name;
1466 } 1583 }
1467 1584
1585 virtual graphics_backend get_backend (void) const
1586 {
1587 if (valid_object ())
1588 return get_properties ().get_backend ();
1589 else
1590 {
1591 error ("base_graphics_object::get_backend: invalid graphics object");
1592 return graphics_backend ();
1593 }
1594 }
1595
1468 protected: 1596 protected:
1469 // A reference count. 1597 // A reference count.
1470 int count; 1598 int count;
1471 }; 1599 };
1472 1600
1627 { 1755 {
1628 const base_properties& props = get_properties (); 1756 const base_properties& props = get_properties ();
1629 return props.get_cdata_property (); 1757 return props.get_cdata_property ();
1630 } 1758 }
1631 1759
1760 graphics_backend get_backend (void) const { return rep->get_backend (); }
1761
1632 private: 1762 private:
1633 base_graphics_object *rep; 1763 base_graphics_object *rep;
1634 };
1635
1636 // ---------------------------------------------------------------------
1637
1638 class graphics_backend;
1639
1640 class base_graphics_backend
1641 {
1642 public:
1643 friend class graphics_backend;
1644
1645 public:
1646 base_graphics_backend (const std::string& nm)
1647 : name (nm), count (0) { }
1648
1649 virtual ~base_graphics_backend (void) { }
1650
1651 std::string get_name (void) const { return name; }
1652
1653 virtual bool is_valid (void) const { return false; }
1654
1655 virtual void close_figure (const octave_value&) const
1656 { error ("close_figure: invalid graphics backend"); }
1657
1658 virtual void redraw_figure (const graphics_handle&) const
1659 { error ("redraw_figure: invalid graphics backend"); }
1660
1661 virtual void print_figure (const graphics_handle&, const std::string&,
1662 const std::string&, bool,
1663 const std::string& = "") const
1664 { error ("print_figure: invalid graphics backend"); }
1665
1666 virtual Matrix get_canvas_size (const graphics_handle&) const
1667 {
1668 error ("get_canvas_size: invalid graphics backend");
1669 return Matrix (1, 2, 0.0);
1670 }
1671
1672 private:
1673 std::string name;
1674 int count;
1675 };
1676
1677 class graphics_backend
1678 {
1679 public:
1680 graphics_backend (void)
1681 : rep (new base_graphics_backend ("unknown"))
1682 {
1683 rep->count++;
1684 }
1685
1686 graphics_backend (base_graphics_backend* b)
1687 : rep (b)
1688 {
1689 rep->count++;
1690 }
1691
1692 graphics_backend (const graphics_backend& b)
1693 : rep (b.rep)
1694 {
1695 rep->count++;
1696 }
1697
1698 ~graphics_backend (void)
1699 {
1700 if (--rep->count == 0)
1701 delete rep;
1702 }
1703
1704 graphics_backend& operator = (const graphics_backend& b)
1705 {
1706 if (rep != b.rep)
1707 {
1708 if (--rep->count == 0)
1709 delete rep;
1710
1711 rep = b.rep;
1712 rep->count++;
1713 }
1714
1715 return *this;
1716 }
1717
1718 operator bool (void) const { return rep->is_valid (); }
1719
1720 std::string get_name (void) const { return rep->get_name (); }
1721
1722 void close_figure (const octave_value& pstream) const
1723 { rep->close_figure (pstream); }
1724
1725 void redraw_figure (const graphics_handle& fh) const
1726 { rep->redraw_figure (fh); }
1727
1728 void print_figure (const graphics_handle& fh, const std::string& term,
1729 const std::string& file, bool mono,
1730 const std::string& debug_file = "") const
1731 { rep->print_figure (fh, term, file, mono, debug_file); }
1732
1733 Matrix get_canvas_size (const graphics_handle& fh) const
1734 { return rep->get_canvas_size (fh); }
1735
1736 OCTINTERP_API static graphics_backend default_backend (void);
1737
1738 static void register_backend (const graphics_backend& b)
1739 { available_backends[b.get_name ()] = b; }
1740
1741 static void unregister_backend (const std::string& name)
1742 { available_backends.erase (name); }
1743
1744 private:
1745 base_graphics_backend *rep;
1746
1747 private:
1748 static std::map<std::string, graphics_backend> available_backends;
1749 }; 1764 };
1750 1765
1751 // --------------------------------------------------------------------- 1766 // ---------------------------------------------------------------------
1752 1767
1753 class OCTINTERP_API root_figure : public base_graphics_object 1768 class OCTINTERP_API root_figure : public base_graphics_object
2010 base_properties& get_properties (void) { return xproperties; } 2025 base_properties& get_properties (void) { return xproperties; }
2011 2026
2012 const base_properties& get_properties (void) const { return xproperties; } 2027 const base_properties& get_properties (void) const { return xproperties; }
2013 2028
2014 bool valid_object (void) const { return true; } 2029 bool valid_object (void) const { return true; }
2015
2016 graphics_backend get_backend (void) const
2017 { return xproperties.get_backend (); }
2018
2019 void set_backend (const graphics_backend& b)
2020 { xproperties.set_backend (b); }
2021 2030
2022 private: 2031 private:
2023 property_list default_properties; 2032 property_list default_properties;
2024 }; 2033 };
2025 2034