X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FPtr.hh;fp=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FPtr.hh;h=9330c96cfb22c897d10dbe3185bfaabb11da3309;hb=89262281b6e83bd2321150f81f1a0583645eb0c8;hp=0000000000000000000000000000000000000000;hpb=b1fb6b8e1767d775bc452303629e95941d142bea;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/Ptr.hh b/helm/DEVEL/mathml_editor/src/Ptr.hh new file mode 100644 index 000000000..9330c96cf --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/Ptr.hh @@ -0,0 +1,53 @@ +// Copyright (C) 2000-2002, Luca Padovani . +// +// This file is part of GtkMathView, a Gtk widget for MathML. +// +// GtkMathView 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 2 +// of the License, or (at your option) any later version. +// +// GtkMathView 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 GtkMathView; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// For details, see the GtkMathView World-Wide-Web page, +// http://www.cs.unibo.it/helm/mml-widget, or send a mail to +// + +#ifndef Ptr_hh +#define Ptr_hh + +template +class Ptr +{ +public: + Ptr(P* p = 0) : ptr(p) { if (ptr != 0) ptr->ref(); } + Ptr(const Ptr& p) : ptr(p.ptr) { if (ptr != 0) ptr->ref(); } + ~Ptr() { if (ptr != 0) ptr->unref(); } + + P* operator->() const { assert(ptr != 0); return ptr; } + Ptr& operator=(const Ptr& p) + { + if (ptr == p.ptr) return *this; + if (p.ptr != 0) p.ptr->ref(); + if (ptr != 0) ptr->unref(); + ptr = p.ptr; + return *this; + } + + operator P*() const { return ptr; } + template friend Ptr smart_cast(const Ptr& p) { return Ptr(dynamic_cast(p.ptr)); } + template friend bool is_a(const Ptr& p) { return dynamic_cast(p.ptr) != 0; } + template operator Ptr() const { return Ptr(ptr); } + +private: + P* ptr; +}; + +#endif // Ptr_hh