2016-10-30 18:24:19 +01:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-10-12 18:41:06 +02:00
|
|
|
#include "cmPropertyMap.h"
|
2016-07-09 11:21:54 +02:00
|
|
|
|
2016-10-30 18:24:19 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <utility>
|
2015-11-17 17:22:37 +01:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
void cmPropertyMap::Clear()
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
2021-09-14 00:13:48 +02:00
|
|
|
this->Map_.clear();
|
2016-10-30 18:24:19 +01:00
|
|
|
}
|
|
|
|
|
2023-07-02 19:51:09 +02:00
|
|
|
void cmPropertyMap::SetProperty(const std::string& name, std::nullptr_t)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
2023-07-02 19:51:09 +02:00
|
|
|
this->Map_.erase(name);
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
2021-11-20 13:41:27 +01:00
|
|
|
void cmPropertyMap::SetProperty(const std::string& name, cmValue value)
|
|
|
|
{
|
|
|
|
if (!value) {
|
|
|
|
this->Map_.erase(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->Map_[name] = *value;
|
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
void cmPropertyMap::AppendProperty(const std::string& name,
|
|
|
|
const std::string& value, bool asString)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
|
|
|
// Skip if nothing to append.
|
2020-08-30 11:54:41 +02:00
|
|
|
if (value.empty()) {
|
2008-10-12 18:41:06 +02:00
|
|
|
return;
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
{
|
2021-09-14 00:13:48 +02:00
|
|
|
std::string& pVal = this->Map_[name];
|
2020-02-01 23:06:01 +01:00
|
|
|
if (!pVal.empty() && !asString) {
|
|
|
|
pVal += ';';
|
|
|
|
}
|
|
|
|
pVal += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmPropertyMap::RemoveProperty(const std::string& name)
|
|
|
|
{
|
2021-09-14 00:13:48 +02:00
|
|
|
this->Map_.erase(name);
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
|
|
|
|
2021-11-20 13:41:27 +01:00
|
|
|
cmValue cmPropertyMap::GetPropertyValue(const std::string& name) const
|
2013-03-16 19:13:01 +02:00
|
|
|
{
|
2021-09-14 00:13:48 +02:00
|
|
|
auto it = this->Map_.find(name);
|
|
|
|
if (it != this->Map_.end()) {
|
2021-11-20 13:41:27 +01:00
|
|
|
return cmValue(it->second);
|
2020-02-01 23:06:01 +01:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
std::vector<std::string> cmPropertyMap::GetKeys() const
|
|
|
|
{
|
|
|
|
std::vector<std::string> keyList;
|
2021-09-14 00:13:48 +02:00
|
|
|
keyList.reserve(this->Map_.size());
|
|
|
|
for (auto const& item : this->Map_) {
|
2020-02-01 23:06:01 +01:00
|
|
|
keyList.push_back(item.first);
|
|
|
|
}
|
|
|
|
std::sort(keyList.begin(), keyList.end());
|
|
|
|
return keyList;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
|
|
|
|
{
|
|
|
|
using StringPair = std::pair<std::string, std::string>;
|
|
|
|
std::vector<StringPair> kvList;
|
2021-09-14 00:13:48 +02:00
|
|
|
kvList.reserve(this->Map_.size());
|
|
|
|
for (auto const& item : this->Map_) {
|
2020-02-01 23:06:01 +01:00
|
|
|
kvList.emplace_back(item.first, item.second);
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2020-02-01 23:06:01 +01:00
|
|
|
std::sort(kvList.begin(), kvList.end(),
|
|
|
|
[](StringPair const& a, StringPair const& b) {
|
|
|
|
return a.first < b.first;
|
|
|
|
});
|
|
|
|
return kvList;
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|