diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-23 16:54:45 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-26 06:40:50 +0000 |
commit | eadd033fb99a65def3fcc1cd79895e158a6adedf (patch) | |
tree | c33d73c0c6144f5cbc4446dca5a7eea3a7fd7fe2 /src/libs/utils/environment.h | |
parent | 59a0aeb739a7402d0dcf567bb67df4dca82bc1d5 (diff) |
EnvironmentItem: Introduce operation enumeration
Extend operations to handle prepend/append which can be optionally
determined by diff(). This allows cleanly implementing
the MSVC toolchain setup.
Amends c7a84634fde03d5a2f3ded86445b3f95d1930e64
Change-Id: Ida08d8f5e00cf5f78c20ea8d08c531b1ed22c015
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/libs/utils/environment.h')
-rw-r--r-- | src/libs/utils/environment.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/libs/utils/environment.h b/src/libs/utils/environment.h index 1dbcd856c04..2f4e84106eb 100644 --- a/src/libs/utils/environment.h +++ b/src/libs/utils/environment.h @@ -34,31 +34,42 @@ #include <functional> +QT_FORWARD_DECLARE_CLASS(QDebug) QT_FORWARD_DECLARE_CLASS(QProcessEnvironment) namespace Utils { +class Environment; class QTCREATOR_UTILS_EXPORT EnvironmentItem { public: - EnvironmentItem(const QString &n, const QString &v) - : name(n), value(v), unset(false) + enum Operation { Set, Unset, Prepend, Append }; + + EnvironmentItem(const QString &n, const QString &v, Operation op = Set) + : name(n), value(v), operation(op) {} + void apply(Environment *e) const { apply(e, operation); } + QString name; QString value; - bool unset; + Operation operation; bool operator==(const EnvironmentItem &other) const { - return unset == other.unset && name == other.name && value == other.value; + return operation == other.operation && name == other.name && value == other.value; } static void sort(QList<EnvironmentItem> *list); static QList<EnvironmentItem> fromStringList(const QStringList &list); static QStringList toStringList(const QList<EnvironmentItem> &list); + +private: + void apply(Environment *e, Operation op) const; }; +QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const EnvironmentItem &i); + class QTCREATOR_UTILS_EXPORT Environment { public: @@ -78,7 +89,7 @@ public: void unset(const QString &key); void modify(const QList<EnvironmentItem> &list); /// Return the Environment changes necessary to modify this into the other environment. - QList<EnvironmentItem> diff(const Environment &other) const; + QList<EnvironmentItem> diff(const Environment &other, bool checkAppendPrepend = false) const; bool hasKey(const QString &key) const; QString userName() const; |