KHtml

DataRef.h
1 /*
2  * Copyright (C) 2000 Lars Knoll ([email protected])
3  * (C) 2000 Antti Koivisto ([email protected])
4  * (C) 2000 Dirk Mueller ([email protected])
5  * Copyright (C) 2003, 2005, 2008 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef DataRef_h
25 #define DataRef_h
26 
27 #include <wtf/RefPtr.h>
28 
29 namespace khtml
30 {
31 
32 template <class DATA>
33 class DataRef
34 {
35 public:
36  DataRef()
37  {
38  data = nullptr;
39  }
40 
41  DataRef(const DataRef<DATA> &d)
42  {
43  data = d.data;
44  data->ref();
45  }
46 
47  ~DataRef()
48  {
49  if (data) {
50  data->deref();
51  }
52  }
53 
54  const DATA *operator->() const
55  {
56  return data;
57  }
58 
59  const DATA *get() const
60  {
61  return data;
62  }
63 
64  DATA *access()
65  {
66  if (!data->hasOneRef()) {
67  data->deref();
68  data = new DATA(*data);
69  data->ref();
70  }
71  return data;
72  }
73 
74  void init()
75  {
76  data = new DATA;
77  data->ref();
78  }
79 
80  DataRef<DATA> &operator=(const DataRef<DATA> &d)
81  {
82  if (data == d.data) {
83  return *this;
84  }
85  if (data) {
86  data->deref();
87  }
88  data = d.data;
89 
90  data->ref();
91 
92  return *this;
93  }
94 
95  bool operator == (const DataRef<DATA> &o) const
96  {
97  return (*data == *(o.data));
98  }
99 
100  bool operator != (const DataRef<DATA> &o) const
101  {
102  return (*data != *(o.data));
103  }
104 
105 private:
106  DATA *data;
107 };
108 
109 } // namespace khtml
110 
111 #endif // DataRef_h
This file is part of the HTML rendering engine for KDE.
QCA_EXPORT void init()
int access(const QString &path, int mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.