• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xap_GtkObjectHolder.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 2009 Hubert Figuiere
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 
00021 #ifndef _XAP_GTKOBJECTHOLDER_H_
00022 #define _XAP_GTKOBJECTHOLDER_H_
00023 
00024 
00026 template <class T>
00027 class XAP_GtkObjectHolder
00028 {
00029 public:
00030     XAP_GtkObjectHolder(const XAP_GtkObjectHolder<T> &_obj)
00031         : m_obj(_obj.m_obj)
00032         {
00033             _ref();
00034         }
00035     XAP_GtkObjectHolder(T * _obj = NULL)
00036         : m_obj(_obj)
00037         {
00038             _ref();
00039         }
00040     ~XAP_GtkObjectHolder()
00041         {
00042             _unref();
00043         }
00044     XAP_GtkObjectHolder<T> & operator=(T * _obj)
00045         {
00046             _unref();
00047             m_obj = _obj;
00048             _ref();
00049             return *this;
00050         }
00051     XAP_GtkObjectHolder<T> & operator=(const XAP_GtkObjectHolder<T> & _obj)
00052         {
00053             _unref();
00054             m_obj = _obj.m_obj;
00055             _ref();
00056             return *this;
00057         }
00058     T * obj() const
00059         {
00060             return m_obj;
00061         }
00062 private:
00063     void _unref()
00064         {
00065             if(m_obj)
00066                 g_object_unref(m_obj);
00067         }
00068     void _ref()
00069         {
00070             if(m_obj)
00071                 g_object_ref(m_obj);
00072         }
00073     T* m_obj;
00074 };
00075 
00076 
00077 #endif
00078 

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1