cmake/Source/cmPropertyMap.cxx

79 lines
1.7 KiB
C++
Raw Normal View History

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. */
#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()
{
2020-02-01 23:06:01 +01:00
Map_.clear();
2016-10-30 18:24:19 +01:00
}
2016-07-09 11:21:54 +02:00
void cmPropertyMap::SetProperty(const std::string& name, const char* value)
{
2016-07-09 11:21:54 +02:00
if (!value) {
2020-02-01 23:06:01 +01:00
Map_.erase(name);
return;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
Map_[name] = value;
}
2020-08-30 11:54:41 +02:00
void cmPropertyMap::AppendProperty(const std::string& name,
const std::string& value, bool asString)
{
// Skip if nothing to append.
2020-08-30 11:54:41 +02:00
if (value.empty()) {
return;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
{
std::string& pVal = Map_[name];
if (!pVal.empty() && !asString) {
pVal += ';';
}
pVal += value;
}
}
void cmPropertyMap::RemoveProperty(const std::string& name)
{
Map_.erase(name);
}
2020-08-30 11:54:41 +02:00
cmProp cmPropertyMap::GetPropertyValue(const std::string& name) const
2013-03-16 19:13:01 +02:00
{
2020-08-30 11:54:41 +02:00
auto it = Map_.find(name);
if (it != Map_.end()) {
return &it->second;
2020-02-01 23:06:01 +01:00
}
return nullptr;
}
2020-02-01 23:06:01 +01:00
std::vector<std::string> cmPropertyMap::GetKeys() const
{
std::vector<std::string> keyList;
keyList.reserve(Map_.size());
for (auto const& item : Map_) {
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;
kvList.reserve(Map_.size());
for (auto const& item : Map_) {
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;
}