cmPropertyMap.cxx 1.49 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
#include "cmPropertyMap.h"
4

5
#include <utility>
6

7
void cmPropertyMap::Clear()
8
{
9
  Map_.clear();
10 11
}

12
void cmPropertyMap::SetProperty(const std::string& name, const char* value)
13
{
14
  if (!value) {
15
    Map_.erase(name);
16
    return;
17
  }
18

19
  Map_[name] = value;
20 21
}

22
void cmPropertyMap::AppendProperty(const std::string& name, const char* value,
23
                                   bool asString)
24 25
{
  // Skip if nothing to append.
26
  if (!value || !*value) {
27
    return;
28
  }
29

30 31 32 33 34 35 36
  {
    std::string& pVal = Map_[name];
    if (!pVal.empty() && !asString) {
      pVal += ';';
    }
    pVal += value;
  }
37 38
}

39 40 41 42 43
void cmPropertyMap::RemoveProperty(const std::string& name)
{
  Map_.erase(name);
}

44
const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
45
{
46 47 48
  {
    auto it = Map_.find(name);
    if (it != Map_.end()) {
49
      return it->second.c_str();
50
    }
51
  }
52
  return nullptr;
53
}
54 55 56 57

std::vector<std::string> cmPropertyMap::GetKeys() const
{
  std::vector<std::string> keyList;
58 59
  keyList.reserve(Map_.size());
  for (auto const& item : Map_) {
60 61 62 63
    keyList.push_back(item.first);
  }
  return keyList;
}
64 65 66 67

std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
{
  std::vector<std::pair<std::string, std::string>> kvList;
68 69
  kvList.reserve(Map_.size());
  for (auto const& item : Map_) {
70
    kvList.emplace_back(item.first, item.second);
71 72 73
  }
  return kvList;
}