/src/CMake/Source/cmPropertyMap.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmPropertyMap.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <utility> |
7 | | |
8 | | void cmPropertyMap::Clear() |
9 | 1 | { |
10 | 1 | this->Map_.clear(); |
11 | 1 | } |
12 | | |
13 | | void cmPropertyMap::SetProperty(std::string const& name, cmValue value) |
14 | 4 | { |
15 | 4 | if (!value) { |
16 | 0 | this->Map_.erase(name); |
17 | 0 | return; |
18 | 0 | } |
19 | | |
20 | 4 | this->Map_[name] = *value; |
21 | 4 | } |
22 | | |
23 | | void cmPropertyMap::AppendProperty(std::string const& name, |
24 | | std::string const& value, bool asString) |
25 | 0 | { |
26 | | // Skip if nothing to append. |
27 | 0 | if (value.empty()) { |
28 | 0 | return; |
29 | 0 | } |
30 | | |
31 | 0 | { |
32 | 0 | std::string& pVal = this->Map_[name]; |
33 | 0 | if (!pVal.empty() && !asString) { |
34 | 0 | pVal += ';'; |
35 | 0 | } |
36 | 0 | pVal += value; |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | | void cmPropertyMap::RemoveProperty(std::string const& name) |
41 | 0 | { |
42 | 0 | this->Map_.erase(name); |
43 | 0 | } |
44 | | |
45 | | cmValue cmPropertyMap::GetPropertyValue(std::string const& name) const |
46 | 0 | { |
47 | 0 | auto it = this->Map_.find(name); |
48 | 0 | if (it != this->Map_.end()) { |
49 | 0 | return cmValue(it->second); |
50 | 0 | } |
51 | 0 | return nullptr; |
52 | 0 | } |
53 | | |
54 | | std::vector<std::string> cmPropertyMap::GetKeys() const |
55 | 0 | { |
56 | 0 | std::vector<std::string> keyList; |
57 | 0 | keyList.reserve(this->Map_.size()); |
58 | 0 | for (auto const& item : this->Map_) { |
59 | 0 | keyList.push_back(item.first); |
60 | 0 | } |
61 | 0 | std::sort(keyList.begin(), keyList.end()); |
62 | 0 | return keyList; |
63 | 0 | } |
64 | | |
65 | | std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const |
66 | 0 | { |
67 | 0 | using StringPair = std::pair<std::string, std::string>; |
68 | 0 | std::vector<StringPair> kvList; |
69 | 0 | kvList.reserve(this->Map_.size()); |
70 | 0 | for (auto const& item : this->Map_) { |
71 | 0 | kvList.emplace_back(item.first, item.second); |
72 | 0 | } |
73 | 0 | std::sort(kvList.begin(), kvList.end(), |
74 | 0 | [](StringPair const& a, StringPair const& b) { |
75 | 0 | return a.first < b.first; |
76 | 0 | }); |
77 | 0 | return kvList; |
78 | 0 | } |