File indexing completed on 2024-05-12 04:38:03

0001 /*
0002     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0003     SPDX-FileCopyrightText: 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H
0009 #define KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H
0010 
0011 #include <language/languageexport.h>
0012 #include <QtGlobal>
0013 
0014 namespace KDevelop {
0015 class DUContext;
0016 class TopDUContext;
0017 
0018 /**
0019  * Represents a DUContext within a TopDUContext, without storing the TopDUContext(It must be given to data())
0020  */
0021 class KDEVPLATFORMLANGUAGE_EXPORT LocalIndexedDUContext
0022 {
0023 public:
0024     explicit LocalIndexedDUContext(DUContext* decl);
0025     explicit LocalIndexedDUContext(uint contextIndex = 0);
0026 
0027     /**
0028      * @warning Duchain must be read locked
0029      */
0030     DUContext* data(TopDUContext* top) const;
0031 
0032     bool operator==(const LocalIndexedDUContext& rhs) const
0033     {
0034         return m_contextIndex == rhs.m_contextIndex;
0035     }
0036 
0037     bool isValid() const
0038     {
0039         return m_contextIndex != 0;
0040     }
0041 
0042     uint hash() const
0043     {
0044         return m_contextIndex * 29;
0045     }
0046 
0047     bool operator<(const LocalIndexedDUContext& rhs) const
0048     {
0049         return m_contextIndex < rhs.m_contextIndex;
0050     }
0051 
0052     /**
0053      * Index within the top-context
0054      */
0055     uint localIndex() const
0056     {
0057         return m_contextIndex;
0058     }
0059 
0060     bool isLoaded(TopDUContext* top) const;
0061 
0062 private:
0063     uint m_contextIndex;
0064 };
0065 }
0066 
0067 Q_DECLARE_TYPEINFO(KDevelop::LocalIndexedDUContext, Q_MOVABLE_TYPE);
0068 
0069 #endif // KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H