fix logic
[personal-kdelibs.git] / khtml / dom / dom_misc.h
blob32f0670161ce7b8dbf52ca3f61f8d3bac0496922
1 /*
2 * This file is part of the DOM implementation for KDE.
4 * Copyright 1999 Lars Knoll (knoll@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef _DOM_RefCountImpl_h_
23 #define _DOM_RefCountImpl_h_
25 #include <khtml_export.h>
27 namespace DOM {
30 * This implements the reference counting scheme used for all internal
31 * DOM objects.
33 * Other objects should overload deleteMe() to fit their needs. The default
34 * implementation deletes the object if the ref count drops to 0.
36 class KHTML_EXPORT DomShared
38 public:
39 DomShared() : _ref( 0 ) {}
40 virtual ~DomShared();
42 /* Overload this function if you want a different deletion behavior
44 virtual bool deleteMe();
46 void ref() { _ref++; }
47 void deref() { if(_ref) _ref--; if(!_ref && deleteMe()) delete this; }
48 bool hasOneRef() const { return _ref == 1; }
49 unsigned int refCount() const { return _ref; }
51 protected:
52 // the number of DOMObjects referencing this Node
53 // An implementation object will delete itself, if it has
54 // no DOMObject referencing it, and deleteMe() returns true.
55 unsigned int _ref;
58 } // namespace
60 #endif