1 /*
2     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
3     SPDX-FileCopyrightText: 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de>
4 
5     SPDX-License-Identifier: LGPL-2.0-only
6 */
7 
8 #ifndef KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H
9 #define KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H
10 
11 #include <language/languageexport.h>
12 #include <QtGlobal>
13 
14 namespace KDevelop {
15 class DUContext;
16 class TopDUContext;
17 
18 /**
19  * Represents a DUContext within a TopDUContext, without storing the TopDUContext(It must be given to data())
20  */
21 class KDEVPLATFORMLANGUAGE_EXPORT LocalIndexedDUContext
22 {
23 public:
24     explicit LocalIndexedDUContext(DUContext* decl);
25     explicit LocalIndexedDUContext(uint contextIndex = 0);
26 
27     /**
28      * @warning Duchain must be read locked
29      */
30     DUContext* data(TopDUContext* top) const;
31 
32     bool operator==(const LocalIndexedDUContext& rhs) const
33     {
34         return m_contextIndex == rhs.m_contextIndex;
35     }
36 
isValid()37     bool isValid() const
38     {
39         return m_contextIndex != 0;
40     }
41 
hash()42     uint hash() const
43     {
44         return m_contextIndex * 29;
45     }
46 
47     bool operator<(const LocalIndexedDUContext& rhs) const
48     {
49         return m_contextIndex < rhs.m_contextIndex;
50     }
51 
52     /**
53      * Index within the top-context
54      */
localIndex()55     uint localIndex() const
56     {
57         return m_contextIndex;
58     }
59 
60     bool isLoaded(TopDUContext* top) const;
61 
62 private:
63     uint m_contextIndex;
64 };
65 }
66 
67 Q_DECLARE_TYPEINFO(KDevelop::LocalIndexedDUContext, Q_MOVABLE_TYPE);
68 
69 #endif // KDEVPLATFORM_LOCALINDEXEDDUCONTEXT_H
70