1 // Copyright (C) 2000-2002, Luca Padovani <luca.padovani@cs.unibo.it>.
3 // This file is part of GtkMathView, a Gtk widget for MathML.
5 // GtkMathView is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // GtkMathView is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with GtkMathView; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 // For details, see the GtkMathView World-Wide-Web page,
20 // http://www.cs.unibo.it/helm/mml-widget, or send a mail to
21 // <luca.padovani@cs.unibo.it>
30 Ptr(P* p = 0) : ptr(p) { if (ptr != 0) ptr->ref(); }
31 Ptr(const Ptr& p) : ptr(p.ptr) { if (ptr != 0) ptr->ref(); }
32 ~Ptr() { if (ptr != 0) ptr->unref(); }
34 P* operator->() const { assert(ptr != 0); return ptr; }
35 Ptr& operator=(const Ptr& p)
37 if (ptr == p.ptr) return *this;
38 if (p.ptr != 0) p.ptr->ref();
39 if (ptr != 0) ptr->unref();
44 operator P*() const { return ptr; }
45 template <class Q> friend Ptr<Q> smart_cast(const Ptr& p) { return Ptr<Q>(dynamic_cast<Q*>(p.ptr)); }
46 template <class Q> friend bool is_a(const Ptr& p) { return dynamic_cast<Q*>(p.ptr) != 0; }
47 template <class Q> operator Ptr<Q>() const { return Ptr<Q>(ptr); }