KHtml

dom_misc.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 #ifndef _DOM_RefCountImpl_h_
23 #define _DOM_RefCountImpl_h_
24 
25 #include <khtml_export.h>
26 
27 namespace DOM
28 {
29 
30 /*
31  * This implements the reference counting scheme used for all internal
32  * DOM objects.
33  *
34  * Other objects should overload deleteMe() to fit their needs. The default
35  * implementation deletes the object if the ref count drops to 0.
36  */
37 class KHTML_EXPORT DomShared
38 {
39 public:
40  DomShared() : _ref(0) {}
41  virtual ~DomShared();
42 
43  /* Overload this function if you want a different deletion behavior
44  */
45  virtual bool deleteMe();
46 
47  void ref()
48  {
49  _ref++;
50  }
51  void deref()
52  {
53  if (_ref) {
54  _ref--;
55  } if (!_ref && deleteMe()) {
56  delete this;
57  }
58  }
59  bool hasOneRef() const
60  {
61  return _ref == 1;
62  }
63  unsigned int refCount() const
64  {
65  return _ref;
66  }
67 
68 protected:
69  // the number of DOMObjects referencing this Node
70  // An implementation object will delete itself, if it has
71  // no DOMObject referencing it, and deleteMe() returns true.
72  unsigned int _ref;
73 };
74 
75 } // namespace
76 
77 #endif
void ref()
void deref()
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.