1 /* This is part of KDevelop
2 Copyright 2006 Hamish Rodda <rodda@kde.org>
3 Copyright 2007/2008 David Nolden <david.nolden.kdevelop@art-master.de>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "duchainbase.h"
22 #include <QMutexLocker>
23 #include <QThreadStorage>
25 #include "duchainpointer.h"
26 #include "indexedstring.h"
27 #include "topducontext.h"
28 #include "duchainregister.h"
32 REGISTER_DUCHAIN_ITEM(DUChainBase
);
34 uint
DUChainBaseData::classSize() const {
35 return DUChainItemSystem::self().dataClassSize(*this);
38 void DUChainBase::aboutToSave() {
41 DUChainBase::DUChainBase(const SimpleRange
& range
)
42 : KDevelop::DocumentRangeObject(*new DUChainBaseData
, range
), m_ptr( 0L )
44 d_func_dynamic()->setClassId(this);
47 DUChainBase::DUChainBase( DUChainBaseData
& dd
, const SimpleRange
& range
)
48 : KDevelop::DocumentRangeObject( dd
, range
), m_ptr( 0 )
52 DUChainBase::DUChainBase( DUChainBaseData
& dd
)
53 : KDevelop::DocumentRangeObject( dd
), m_ptr( 0 )
57 DUChainBase::DUChainBase( DUChainBase
& rhs
)
58 : KDevelop::DocumentRangeObject( rhs
), m_ptr( 0 )
62 IndexedString
DUChainBase::url() const
64 TopDUContext
* top
= topContext();
68 return IndexedString();
71 void DUChainBase::setData(DocumentRangeObjectData
* data
)
73 if(d_func()->m_dynamic
)
74 //We only delete the data when it's dynamic, because else it is embedded in an array in the top-context.
75 KDevelop::DUChainItemSystem::self().callDestructor(d_func_dynamic());
77 DocumentRangeObject::setData(data
);
80 DUChainBase::~DUChainBase()
82 if(d_func()->m_dynamic
) {
83 //We only delete the data when it's dynamic, because else it is embedded in an array in the top-context.
84 KDevelop::DUChainItemSystem::self().callDestructor(d_func_dynamic());
91 TopDUContext
* DUChainBase::topContext() const
96 const KSharedPtr
<DUChainPointerData
>& DUChainBase::weakPointer() const
98 QMutexLocker
lock(mutex());
101 m_ptr
= new DUChainPointerData(const_cast<DUChainBase
*>(this));
102 m_ptr
->m_base
= const_cast<DUChainBase
*>(this);
108 void DUChainBase::rebuildDynamicData(DUContext
* parent
, uint ownIndex
)
114 void DUChainBase::makeDynamic() {
116 if(!d_func()->m_dynamic
) {
117 //We don't delete the previous data, because it's embedded in the top-context when it isn't dynamic.
118 d_ptr
= DUChainItemSystem::self().cloneData(*d_func());
120 Q_ASSERT(d_func()->m_dynamic
);
124 QThreadStorage
<char*> shouldCreateConstantDataStorage
;
126 bool DUChainBaseData::shouldCreateConstantData() {
127 return shouldCreateConstantDataStorage
.hasLocalData();
130 void DUChainBaseData::setShouldCreateConstantData(bool should
) {
131 if(should
== shouldCreateConstantData())
134 shouldCreateConstantDataStorage
.setLocalData(new char);
136 shouldCreateConstantDataStorage
.setLocalData(0);
140 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on