cmake/Source/cmPropertyMap.cxx

64 lines
1.4 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>
2015-11-17 17:22:37 +01:00
#include <assert.h>
2016-10-30 18:24:19 +01:00
#include <utility>
2015-11-17 17:22:37 +01:00
2016-07-09 11:21:54 +02:00
cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name)
{
cmPropertyMap::iterator it = this->find(name);
2016-07-09 11:21:54 +02:00
cmProperty* prop;
if (it == this->end()) {
prop = &(*this)[name];
2016-07-09 11:21:54 +02:00
} else {
prop = &(it->second);
2016-07-09 11:21:54 +02:00
}
return prop;
}
2016-10-30 18:24:19 +01:00
std::vector<std::string> cmPropertyMap::GetPropertyList() const
{
std::vector<std::string> keyList;
2018-01-26 17:06:56 +01:00
for (auto const& i : *this) {
keyList.push_back(i.first);
2016-10-30 18:24:19 +01:00
}
std::sort(keyList.begin(), keyList.end());
return keyList;
}
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) {
this->erase(name);
return;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
cmProperty* prop = this->GetOrCreateProperty(name);
2015-11-17 17:22:37 +01:00
prop->Set(value);
}
2015-04-27 22:25:09 +02:00
void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
2015-11-17 17:22:37 +01:00
bool asString)
{
// Skip if nothing to append.
2016-07-09 11:21:54 +02:00
if (!value || !*value) {
return;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
cmProperty* prop = this->GetOrCreateProperty(name);
prop->Append(value, asString);
}
2016-07-09 11:21:54 +02:00
const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
2013-03-16 19:13:01 +02:00
{
2015-11-17 17:22:37 +01:00
assert(!name.empty());
cmPropertyMap::const_iterator it = this->find(name);
2016-07-09 11:21:54 +02:00
if (it == this->end()) {
2018-01-26 17:06:56 +01:00
return nullptr;
2016-07-09 11:21:54 +02:00
}
return it->second.GetValue();
}