00001 /*************************************************************************** 00002 * (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This program is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU Library General Public License (LGPL) * 00008 * as published by the Free Software Foundation; either version 2 of * 00009 * the License, or (at your option) any later version. * 00010 * for detail see the LICENCE text file. * 00011 * * 00012 * FreeCAD is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU Library General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU Library General Public * 00018 * License along with FreeCAD; if not, write to the Free Software * 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 00020 * USA * 00021 * * 00022 * Juergen Riegel 2002 * 00023 ***************************************************************************/ 00024 00025 00026 #include "PreCompiled.h" 00027 00028 #ifndef _PreComp_ 00029 # include <assert.h> 00030 #endif 00031 00032 #include <QAtomicInt> 00033 00034 #include "Handle.h" 00035 #include "Exception.h" 00036 00037 using namespace Base; 00038 00039 //************************************************************************** 00040 // Construction/Destruction 00041 00042 Handled::Handled() 00043 : _lRefCount(new QAtomicInt(0)) 00044 { 00045 } 00046 00047 Handled::~Handled() 00048 { 00049 if ((int)(*_lRefCount) != 0) 00050 throw Exception("Reference counter of deleted object is not zero!!!!!\n"); 00051 delete _lRefCount; 00052 } 00053 00054 void Handled::ref() const 00055 { 00056 _lRefCount->ref(); 00057 } 00058 00059 void Handled::unref() const 00060 { 00061 assert(_lRefCount > 0); 00062 if (!_lRefCount->deref()) { 00063 delete this; 00064 } 00065 } 00066 00067 int Handled::getRefCount(void) const 00068 { 00069 return (int)(*_lRefCount); 00070 } 00071 00072 const Handled& Handled::operator = (const Handled&) 00073 { 00074 // we must not assign _lRefCount 00075 return *this; 00076 }