summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/featureprovider.h
blob: e5735b61d13f8d3dd785461b5e72549bb78acf81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#ifndef FEATUREMANAGER_H
#define FEATUREMANAGER_H

#include "core_global.h"

#include <coreplugin/id.h>

#include <QtCore/QObject>
#include <QtCore/QSet>
#include <QtCore/QStringList>


namespace Utils {
class AbstractMacroExpander;
}

namespace Core {

class CORE_EXPORT FeatureSet;

class CORE_EXPORT IFeatureProvider : public QObject
{
    Q_OBJECT

public:
    IFeatureProvider() {}
    virtual ~IFeatureProvider() {}
    virtual FeatureSet availableFeatures() const = 0;
};

class CORE_EXPORT Feature : public Id
{
friend class FeatureSet;
public:
    Feature(const char *name) : Id(name) {}
    explicit Feature(const QString &name) : Id(name) {}
};

class CORE_EXPORT FeatureSet : private QSet<Feature>
{
public:
    FeatureSet() {}

    FeatureSet(const Feature &feature)
    {
        if (feature.toString().isEmpty())
            return;

        insert(feature);
    }

    FeatureSet(const FeatureSet &other) : QSet<Feature>(other) {}

    FeatureSet &operator=(const FeatureSet &other)
    {
       QSet<Feature>::operator=(other);
       return *this;
    }

    bool contains(const Feature &feature) const
    {
        return QSet<Feature>::contains(feature);
    }

    bool contains(const FeatureSet &features) const
    {
        return QSet<Feature>::contains(features);
    }

    void remove(const Feature &feature)
    {
        QSet<Feature>::remove(feature);
    }

    FeatureSet operator|(const Feature &feature) const
    {
        FeatureSet copy = *this;
        if (feature.isValid())
            copy.insert(feature);
        return copy;
    }

    FeatureSet operator|(const FeatureSet &features) const
    {
        FeatureSet copy = *this;
        if (!features.isEmpty())
            copy.unite(features);
        return copy;
    }

    FeatureSet &operator|=(const Feature &feature)
    {
        if (feature.isValid())
           insert(feature);
        return *this;
    }

    FeatureSet &operator|=(const FeatureSet &features)
    {
        if (!features.isEmpty())
            unite(features);
        return *this;
    }

    QStringList toStringList() const
    {
        QStringList stringList;
        foreach (const Feature &feature, QSet<Feature>(*this))
            stringList.append(feature.toString());
        return stringList;
    }
};

} // namespace Core

/*
The following operators have to be defined in the global namespace!
Otherwise "using namespace Core" would hide other | operators
defined in the global namespace (e. g. QFlags).
*/

inline Core::FeatureSet operator |(Core::Feature feature1, Core::Feature feature2)
{ return Core::FeatureSet(feature1) | feature2; }

inline Core::FeatureSet operator|(Core::Feature feature1, Core::FeatureSet feature2)
{ return feature2 | feature1; }


#endif // FEATUREANAGER_H