Utils: Iterate environment via callback

Iterators expose the underlying datastructure and get
in the way of moving towards "env as stack of changes"

Task-number: QTCREATORBUG-28357
Change-Id: I69e3b53e62ed4c9ab394779e97afbc6fd1986838
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-03-01 13:50:06 +01:00
parent fef8bc4bc4
commit 4b93f47565
2 changed files with 8 additions and 0 deletions

View File

@@ -24,6 +24,12 @@ NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepe
return m_dict.diff(other.m_dict, checkAppendPrepend);
}
void Environment::forEachEntry(const std::function<void(const QString &, const QString &, bool)> &callBack) const
{
for (auto it = m_dict.m_values.constBegin(); it != m_dict.m_values.constEnd(); ++it)
callBack(it.key().name, it.value().first, it.value().second);
}
bool Environment::hasChanges() const
{
return m_dict.size() != 0;

View File

@@ -93,6 +93,8 @@ public:
const_iterator constEnd() const { return m_dict.constEnd(); } // FIXME: avoid
const_iterator constFind(const QString &name) const { return m_dict.constFind(name); } // FIXME: avoid
void forEachEntry(const std::function<void (const QString &, const QString &, bool)> &callBack) const;
friend bool operator!=(const Environment &first, const Environment &second)
{
return first.m_dict != second.m_dict;