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

language/duchain

duchainbase.cpp

00001 /* This  is part of KDevelop
00002     Copyright 2006 Hamish Rodda <rodda@kde.org>
00003     Copyright 2007/2008 David Nolden <david.nolden.kdevelop@art-master.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "duchainbase.h"
00021 
00022 #include <QMutexLocker>
00023 #include <QThreadStorage>
00024 
00025 #include "duchainpointer.h"
00026 #include "indexedstring.h"
00027 #include "topducontext.h"
00028 #include "duchainregister.h"
00029 #include <qthread.h>
00030 
00031 namespace KDevelop
00032 {
00033 REGISTER_DUCHAIN_ITEM(DUChainBase);
00034 
00035 uint DUChainBaseData::classSize() const {
00036   return DUChainItemSystem::self().dataClassSize(*this);
00037 }
00038 
00039 DUChainBase::DUChainBase(const SimpleRange& range)
00040   : KDevelop::DocumentRangeObject(*new DUChainBaseData, range), m_ptr( 0L )
00041 {
00042   d_func_dynamic()->setClassId(this);
00043 }
00044 
00045 DUChainBase::DUChainBase( DUChainBaseData & dd, const SimpleRange& range )
00046   : KDevelop::DocumentRangeObject( dd, range ), m_ptr( 0 )
00047 {
00048 }
00049 
00050 DUChainBase::DUChainBase( DUChainBaseData & dd )
00051   : KDevelop::DocumentRangeObject( dd ), m_ptr( 0 )
00052 {
00053 }
00054 
00055 DUChainBase::DUChainBase( DUChainBase& rhs )
00056   : KDevelop::DocumentRangeObject( rhs ), m_ptr( 0 )
00057 {
00058 }
00059 
00060 IndexedString DUChainBase::url() const
00061 {
00062   TopDUContext* top = topContext();
00063   if(top)
00064     return top->TopDUContext::url();
00065   else
00066     return IndexedString();
00067 }
00068 
00069 void DUChainBase::setData(DocumentRangeObjectData* data, bool constructorCalled)
00070 {
00071   if(constructorCalled)
00072     KDevelop::DUChainItemSystem::self().callDestructor(static_cast<DUChainBaseData*>(d_ptr));
00073   
00074   DocumentRangeObject::setData(data, constructorCalled);
00075 }
00076 
00077 DUChainBase::~DUChainBase()
00078 {
00079   if(d_func()->m_dynamic)
00080     KDevelop::DUChainItemSystem::self().callDestructor(d_func_dynamic());
00081   
00082   if (m_ptr)
00083     m_ptr->m_base = 0;
00084 }
00085 
00086 TopDUContext* DUChainBase::topContext() const
00087 {
00088   return 0;
00089 }
00090 
00091 const KSharedPtr<DUChainPointerData>& DUChainBase::weakPointer() const
00092 {
00093   QMutexLocker lock(mutex());
00094 
00095   if (!m_ptr) {
00096     m_ptr = new DUChainPointerData(const_cast<DUChainBase*>(this));
00097     m_ptr->m_base = const_cast<DUChainBase*>(this);
00098   }
00099 
00100   return m_ptr;
00101 }
00102 
00103 void DUChainBase::rebuildDynamicData(DUContext* parent, uint ownIndex)
00104 {
00105     Q_UNUSED(parent)
00106     Q_UNUSED(ownIndex)
00107 }
00108 
00109 void DUChainBase::aboutToWriteData() {
00110   makeDynamic();
00111 }
00112 
00113 bool DUChainBase::canWriteData() const {
00114   return d_func()->m_dynamic;
00115 }
00116 
00117 void DUChainBase::makeDynamic() {
00118   Q_ASSERT(d_ptr);
00119   if(!d_func()->m_dynamic) {
00120     Q_ASSERT(d_func()->classId);
00121     DUChainBaseData* newData = DUChainItemSystem::self().cloneData(*d_func());
00122     enableDUChainReferenceCounting(d_ptr, DUChainItemSystem::self().dynamicSize(*static_cast<DUChainBaseData*>(d_ptr)));
00123     //We don't delete the previous data, because it's embedded in the top-context when it isn't dynamic.
00124     //However we do call the destructor, to keep semantic stuff like reference-counting within the data class working correctly.
00125     KDevelop::DUChainItemSystem::self().callDestructor(static_cast<DUChainBaseData*>(d_ptr));
00126     disableDUChainReferenceCounting(d_ptr);
00127     d_ptr = newData;
00128     Q_ASSERT(d_ptr);
00129     Q_ASSERT(d_func()->m_dynamic);
00130     Q_ASSERT(d_func()->classId);
00131   }
00132 }
00133 
00134 QMutex shouldCreateConstantDataStorageMutex;
00135 QSet<Qt::HANDLE> shouldCreateConstantDataStorage;
00136 
00137 bool DUChainBaseData::shouldCreateConstantData() {
00138   shouldCreateConstantDataStorageMutex.lock();
00139   bool ret = shouldCreateConstantDataStorage.contains( QThread::currentThreadId() );
00140   shouldCreateConstantDataStorageMutex.unlock();
00141   return ret;
00142 }
00143 
00144 void DUChainBaseData::setShouldCreateConstantData(bool should) {
00145   shouldCreateConstantDataStorageMutex.lock();
00146   
00147   if(should)
00148     shouldCreateConstantDataStorage.insert(QThread::currentThreadId());
00149   else
00150     shouldCreateConstantDataStorage.remove(QThread::currentThreadId());
00151   
00152   shouldCreateConstantDataStorageMutex.unlock();
00153 }
00154 
00155 }
00156 
00157 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on
00158 

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