• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

duchainpointer.h

00001 /*
00002    Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #ifndef DUCHAINPOINTER_H
00020 #define DUCHAINPOINTER_H
00021 
00022 #include <QtCore/QMetaType>
00023 #include <ksharedptr.h>
00024 #include "../languageexport.h"
00025 
00026 //krazy:excludeall=dpointer
00027 
00028 namespace KDevelop {
00029 
00030 class DUContext;
00031 class TopDUContext;
00032 class DUChainBase;
00033 class Declaration;
00034 class AbstractFunctionDeclaration;
00035 
00050 class KDEVPLATFORMLANGUAGE_EXPORT  DUChainPointerData : public KShared {
00051   public:
00055     DUChainBase* base();
00056 
00060     DUChainBase* base() const;
00061 
00063     DUChainPointerData();
00064 
00065     ~DUChainPointerData();
00066 
00067   private:
00069     DUChainPointerData( DUChainBase* base );
00070 
00071     friend class DUChainBase;
00072     DUChainBase * m_base;
00073     Q_DISABLE_COPY(DUChainPointerData)
00074 };
00075 
00087   template<class Type>
00088   class DUChainPointer {
00089     template<class OtherType>
00090     friend class DUChainPointer;
00091 
00092     public:
00093     DUChainPointer() : d(KSharedPtr<DUChainPointerData>(0)) {
00094     }
00095 
00096     DUChainPointer(const DUChainPointer& rhs)
00097       : d(rhs.d)
00098     {
00099     }
00100 
00102     template<class OtherType>
00103     explicit DUChainPointer( OtherType* rhs ) {
00104       if( dynamic_cast<Type*>(rhs) )
00105         d = rhs->weakPointer();
00106     }
00107 
00108     template<class OtherType>
00109     explicit DUChainPointer( DUChainPointer<OtherType> rhs ) {
00110       if( dynamic_cast<Type*>(rhs.data()) )
00111         d = rhs.d;
00112     }
00113 
00114     explicit DUChainPointer( KSharedPtr<DUChainPointerData> rhs ) {
00115       if( dynamic_cast<Type*>(rhs->base()) )
00116         d = rhs;
00117     }
00118 
00119     explicit DUChainPointer( Type* rhs ) {
00120       if( rhs )
00121         d = rhs->weakPointer();
00122     }
00123 
00124     bool operator ==( const DUChainPointer<Type>& rhs ) const {
00125       return d.data() == rhs.d.data();
00126     }
00127 
00128     bool operator !=( const DUChainPointer<Type>& rhs ) const {
00129       return d.data() != rhs.d.data();
00130     }
00131 
00133     operator bool() const {
00134       return d && d->base();
00135     }
00136 
00137     Type& operator* () const {
00138       Q_ASSERT(d);
00139       return *static_cast<Type*>(d->base());
00140     }
00141 
00142     Type* operator->() const {
00143       Q_ASSERT(d);
00144       return static_cast<Type*>(d->base());
00145     }
00146 
00147     bool operator<(const DUChainPointer<Type>& rhs) const {
00148       return d.data() < rhs.d.data();
00149     }
00150 
00151     template<class NewType>
00152     DUChainPointer<NewType> dynamicCast() const {
00153       if( 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
00154         return DUChainPointer<NewType>( static_cast<NewType*>(d->base()) );
00155       else
00156         return DUChainPointer<NewType>();
00157     }
00158 
00159     Type* data() const {
00160       if( !d )
00161         return 0;
00162       return static_cast<Type*>(d->base());
00163     }
00164 
00165     DUChainPointer<Type>& operator= ( Type* rhs ) {
00166       if( rhs )
00167         d = rhs->weakPointer();
00168       else
00169         d = 0;
00170 
00171       return *this;
00172     }
00173 
00174     private:
00175       KSharedPtr<DUChainPointerData> d;
00176   };
00177 
00178   typedef DUChainPointer<DUChainBase> DUChainBasePointer;
00179   typedef DUChainPointer<DUContext> DUContextPointer;
00180   typedef DUChainPointer<TopDUContext> TopDUContextPointer;
00181   typedef DUChainPointer<Declaration> DeclarationPointer;
00182   typedef DUChainPointer<AbstractFunctionDeclaration> FunctionDeclarationPointer;
00183 }
00184 
00185 Q_DECLARE_METATYPE( KDevelop::DUChainBasePointer )
00186 
00187 #endif

language/duchain

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

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal