• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
duchainpointer.h
Go to the documentation of this file.
1 /*
2  Copyright 2007 David Nolden <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KDEVPLATFORM_DUCHAINPOINTER_H
20 #define KDEVPLATFORM_DUCHAINPOINTER_H
21 
22 #include <QMetaType>
23 #include <QList>
24 #include <QExplicitlySharedDataPointer>
25 #include <language/languageexport.h>
26 
27 //krazy:excludeall=dpointer
28 
29 namespace KDevelop {
30 class DUContext;
31 class TopDUContext;
32 class DUChainBase;
33 class Declaration;
34 class AbstractFunctionDeclaration;
35 
50 class KDEVPLATFORMLANGUAGE_EXPORT DUChainPointerData
51  : public QSharedData
52 {
53 public:
57  DUChainBase* base();
58 
62  DUChainBase* base() const;
63 
65  DUChainPointerData();
66 
67  ~DUChainPointerData();
68 
69 private:
71  explicit DUChainPointerData(DUChainBase* base);
72 
73  friend class DUChainBase;
74  DUChainBase* m_base = nullptr;
75  Q_DISABLE_COPY(DUChainPointerData)
76 };
77 
89 template <class Type>
90 class DUChainPointer
91 {
92  template <class OtherType>
93  friend class DUChainPointer;
94 
95 public:
96  DUChainPointer() : d(QExplicitlySharedDataPointer<DUChainPointerData>(nullptr))
97  {
98  }
99 
100  DUChainPointer(const DUChainPointer&) = default;
101  DUChainPointer(DUChainPointer&&) = default;
102 
104  template <class OtherType>
105  explicit DUChainPointer(OtherType* rhs)
106  {
107  if (dynamic_cast<Type*>(rhs))
108  d = rhs->weakPointer();
109  }
110 
111  template <class OtherType>
112  explicit DUChainPointer(DUChainPointer<OtherType> rhs)
113  {
114  if (dynamic_cast<Type*>(rhs.data()))
115  d = rhs.d;
116  }
117 
118  explicit DUChainPointer(QExplicitlySharedDataPointer<DUChainPointerData> rhs)
119  {
120  if (dynamic_cast<Type*>(rhs->base()))
121  d = rhs;
122  }
123 
124  explicit DUChainPointer(Type* rhs)
125  {
126  if (rhs)
127  d = rhs->weakPointer();
128  }
129 
130  ~DUChainPointer() = default;
131 
132  bool operator ==(const DUChainPointer<Type>& rhs) const
133  {
134  return d.data() == rhs.d.data();
135  }
136 
137  bool operator !=(const DUChainPointer<Type>& rhs) const
138  {
139  return d.data() != rhs.d.data();
140  }
141 
143  operator bool() const {
144  return d && d->base();
145  }
146 
147  Type& operator*() const
148  {
149  Q_ASSERT(d);
150  return *static_cast<Type*>(d->base());
151  }
152 
153  Type* operator->() const
154  {
155  Q_ASSERT(d);
156  return static_cast<Type*>(d->base());
157  }
158 
159  bool operator<(const DUChainPointer<Type>& rhs) const
160  {
161  return d.data() < rhs.d.data();
162  }
163 
164  template <class NewType>
165  DUChainPointer<NewType> dynamicCast() const
166  {
167  if (d && dynamic_cast<NewType*>(d->base())) //When the reference to the pointer is constant that doesn't mean that the pointed object needs to be constant
168  return DUChainPointer<NewType>(static_cast<NewType*>(d->base()));
169  else
170  return DUChainPointer<NewType>();
171  }
172 
173  Type* data() const
174  {
175  if (!d)
176  return nullptr;
177  return static_cast<Type*>(d->base());
178  }
179 
180  DUChainPointer<Type>& operator=(const DUChainPointer<Type>&) = default;
181  DUChainPointer<Type>& operator=(DUChainPointer<Type>&&) = default;
182 
183  DUChainPointer<Type>& operator=(Type* rhs)
184  {
185  if (rhs)
186  d = rhs->weakPointer();
187  else
188  d = nullptr;
189 
190  return *this;
191  }
192 
193 private:
194  QExplicitlySharedDataPointer<DUChainPointerData> d;
195 };
196 
197 using DUChainBasePointer = DUChainPointer<DUChainBase>;
198 using DUContextPointer = DUChainPointer<DUContext>;
199 using TopDUContextPointer = DUChainPointer<TopDUContext>;
200 using DeclarationPointer = DUChainPointer<Declaration>;
201 using FunctionDeclarationPointer = DUChainPointer<AbstractFunctionDeclaration>;
202 }
203 
204 Q_DECLARE_METATYPE(KDevelop::DUChainBasePointer)
205 Q_DECLARE_METATYPE(KDevelop::DeclarationPointer)
206 Q_DECLARE_METATYPE(KDevelop::DUContextPointer)
207 Q_DECLARE_METATYPE(KDevelop::TopDUContextPointer)
208 
209 #endif
QSharedData
KDevelop::DUChainPointer::DUChainPointer
DUChainPointer(QExplicitlySharedDataPointer< DUChainPointerData > rhs)
Definition: duchainpointer.h:118
KDevelop::DUChainPointer::operator=
DUChainPointer< Type > & operator=(const DUChainPointer< Type > &)=default
KDevelop::DUChainBase
Base class for definition-use chain objects.
Definition: duchainbase.h:131
KDevelop::DUChainPointer::dynamicCast
DUChainPointer< NewType > dynamicCast() const
Definition: duchainpointer.h:165
KDevelop::DUChainPointer
A smart-pointer similar class that conveniently wraps around DUChainPointerData without too many dyna...
Definition: duchainpointer.h:90
KDevelop::DUChainPointer::operator->
Type * operator->() const
Definition: duchainpointer.h:153
QExplicitlySharedDataPointer
Definition: topducontext.h:28
KDevelop::DUChainPointer::DUChainPointer
DUChainPointer()
Definition: duchainpointer.h:96
KDevelop::DUChainPointer::operator<
bool operator<(const DUChainPointer< Type > &rhs) const
Definition: duchainpointer.h:159
KDevelop::DUChainPointer::~DUChainPointer
~DUChainPointer()=default
KDevelop::DUChainPointer::DUChainPointer
DUChainPointer(DUChainPointer< OtherType > rhs)
Definition: duchainpointer.h:112
KDevelop::DUChainPointer::DUChainPointer
DUChainPointer(Type *rhs)
Definition: duchainpointer.h:124
KDevelop::DUChainPointer::DUChainPointer
DUChainPointer(OtherType *rhs)
This constructor includes dynamic casting. If the object cannot be casted to the type,...
Definition: duchainpointer.h:105
KDevelop::DUChainPointer::operator=
DUChainPointer< Type > & operator=(Type *rhs)
Definition: duchainpointer.h:183
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::DUChainPointer::data
Type * data() const
Definition: duchainpointer.h:173
KDevelop::DUChainPointer::operator*
Type & operator*() const
Definition: duchainpointer.h:147
KDevelop::DUChainPointer::operator==
bool operator==(const DUChainPointer< Type > &rhs) const
Definition: duchainpointer.h:132
KDevelop::DUChainPointerData
Whenever the du-chain is unlocked and locked again, any du-chain item may have been deleted in betwee...
Definition: duchainpointer.h:50
KDevelop::DUChainPointer::operator!=
bool operator!=(const DUChainPointer< Type > &rhs) const
Definition: duchainpointer.h:137
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 16 2021 23:35:05 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

Skip menu "kdevplatform/language/duchain"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal