Add AbstractDeclarationNavigationContext, and move the html-method from
[kdevelopdvcssupport.git] / language / duchain / specializationstore.h
blob02f92298b55515b190ece465610e871ef2eca7b5
1 /* This file is part of KDevelop
2 Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef SPECIALIZATIONSTORE_H
20 #define SPECIALIZATIONSTORE_H
22 #include <QtCore/qhash.h>
23 #include "../languageexport.h"
25 namespace KDevelop {
26 class DeclarationId;
27 class Declaration;
28 class DUContext;
29 class TopDUContext;
31 /**
32 * This class allows dynamic management of "current" specializations for declarations.
33 * The specializations will be applied in editors, and wherever it makes sense.
34 * For example, this is used in C++ to get code-completion and use-building within
35 * instantiated template-classes/functions.
37 class KDEVPLATFORMLANGUAGE_EXPORT SpecializationStore {
38 public:
39 static SpecializationStore& self();
41 /**
42 * Adds/updates the current specialization for the given declaration-id
43 * */
44 void set(DeclarationId declaration, uint specialization);
45 /**
46 * Gets the registered specialization for the given declaration-id, or zero.
48 uint get(DeclarationId declaration);
49 /**
50 * Clears the specialization registered for the given declaration-id
52 void clear(DeclarationId declaration);
53 /**
54 * Clears all registered specializations
56 void clear();
58 /**
59 * Applies the known specializations for the given declaration using the Declaration::specialize() function.
60 * If no specializations are known, the original declaration is returned.
61 * @param declaration The declaration to specialize
62 * @param source The top-context from where to start searching
63 * @param recursive Whether parent-contexts should be checked for known specializations, and those applied.
64 * This is a bit more expensive then just doing a local check.
66 KDevelop::Declaration* applySpecialization(KDevelop::Declaration* declaration, KDevelop::TopDUContext* source, bool recursive = true);
67 /**
68 * Applies the known specializations for the given context using the DUContext::specialize() function.
69 * If no specializations are known, returns the original context.
70 * @param context The context to specialize
71 * @param source The top-context from where to start searching
72 * @param recursive Whether parent-contexts should be checked for known specializations, and those applied.
73 * This is a bit more expensive then just doing a local check.
75 DUContext* applySpecialization(KDevelop::DUContext* context, KDevelop::TopDUContext* source, bool recursive = true);
77 private:
78 SpecializationStore();
79 ~SpecializationStore();
80 QHash<DeclarationId, uint> m_specializations;
84 #endif