File indexing completed on 2024-04-28 15:22:57
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright 1999 Lars Knoll (knoll@kde.org) 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 * 0021 */ 0022 #ifndef _DOM_RefCountImpl_h_ 0023 #define _DOM_RefCountImpl_h_ 0024 0025 #include <khtml_export.h> 0026 0027 namespace DOM 0028 { 0029 0030 /* 0031 * This implements the reference counting scheme used for all internal 0032 * DOM objects. 0033 * 0034 * Other objects should overload deleteMe() to fit their needs. The default 0035 * implementation deletes the object if the ref count drops to 0. 0036 */ 0037 class KHTML_EXPORT DomShared 0038 { 0039 public: 0040 DomShared() : _ref(0) {} 0041 virtual ~DomShared(); 0042 0043 /* Overload this function if you want a different deletion behavior 0044 */ 0045 virtual bool deleteMe(); 0046 0047 void ref() 0048 { 0049 _ref++; 0050 } 0051 void deref() 0052 { 0053 if (_ref) { 0054 _ref--; 0055 } if (!_ref && deleteMe()) { 0056 delete this; 0057 } 0058 } 0059 bool hasOneRef() const 0060 { 0061 return _ref == 1; 0062 } 0063 unsigned int refCount() const 0064 { 0065 return _ref; 0066 } 0067 0068 protected: 0069 // the number of DOMObjects referencing this Node 0070 // An implementation object will delete itself, if it has 0071 // no DOMObject referencing it, and deleteMe() returns true. 0072 unsigned int _ref; 0073 }; 0074 0075 } // namespace 0076 0077 #endif