1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
11 #include <cm/string_view>
16 cmValue() noexcept = default;
17 cmValue(std::nullptr_t) noexcept {}
18 explicit cmValue(const std::string* value) noexcept
22 explicit cmValue(const std::string& value) noexcept
26 cmValue(const cmValue& other) noexcept = default;
28 cmValue& operator=(const cmValue& other) noexcept = default;
29 cmValue& operator=(std::nullptr_t) noexcept
31 this->Value = nullptr;
35 const std::string* Get() const noexcept { return this->Value; }
36 const char* GetCStr() const noexcept
38 return this->Value == nullptr ? nullptr : this->Value->c_str();
41 const std::string* operator->() const noexcept
43 return this->Value == nullptr ? &cmValue::Empty : this->Value;
45 const std::string& operator*() const noexcept
47 return this->Value == nullptr ? cmValue::Empty : *this->Value;
50 explicit operator bool() const noexcept { return this->Value != nullptr; }
51 operator const std::string&() const noexcept { return this->operator*(); }
52 explicit operator cm::string_view() const noexcept
54 return this->operator*();
58 * Does the value indicate a true or ON value?
60 bool IsOn() const noexcept
62 return this->Value != nullptr &&
63 cmValue::IsOn(cm::string_view(*this->Value));
66 * Does the value indicate a false or off value ? Note that this is
67 * not the same as !IsOn(...) because there are a number of
68 * ambiguous values such as "/usr/local/bin" a path will result in
69 * IsOn and IsOff both returning false. Note that the special path
70 * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
72 bool IsOff() const noexcept
74 return this->Value == nullptr ||
75 cmValue::IsOff(cm::string_view(*this->Value));
77 /** Return true if value is NOTFOUND or ends in -NOTFOUND. */
78 bool IsNOTFOUND() const noexcept
80 return this->Value != nullptr &&
81 cmValue::IsNOTFOUND(cm::string_view(*this->Value));
83 bool IsEmpty() const noexcept
85 return this->Value == nullptr || this->Value->empty();
89 * Does a string indicates that CMake/CPack/CTest internally
90 * forced this value. This is not the same as On, but this
91 * may be considered as "internally switched on".
93 bool IsInternallyOn() const noexcept
95 return this->Value != nullptr &&
96 cmValue::IsInternallyOn(cm::string_view(*this->Value));
99 bool IsSet() const noexcept
101 return !this->IsEmpty() && !this->IsNOTFOUND();
105 * Does a string indicate a true or ON value?
107 static bool IsOn(const char* value) noexcept
109 return value != nullptr && IsOn(cm::string_view(value));
111 static bool IsOn(cm::string_view) noexcept;
114 * Compare method has same semantic as std::optional::compare
116 int Compare(cmValue value) const noexcept;
117 int Compare(cm::string_view value) const noexcept;
120 * Does a string indicate a false or off value ? Note that this is
121 * not the same as !IsOn(...) because there are a number of
122 * ambiguous values such as "/usr/local/bin" a path will result in
123 * IsOn and IsOff both returning false. Note that the special path
124 * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
126 static bool IsOff(const char* value) noexcept
128 return value == nullptr || IsOff(cm::string_view(value));
130 static bool IsOff(cm::string_view) noexcept;
132 /** Return true if value is NOTFOUND or ends in -NOTFOUND. */
133 static bool IsNOTFOUND(const char* value) noexcept
135 return value == nullptr || IsNOTFOUND(cm::string_view(value));
137 static bool IsNOTFOUND(cm::string_view) noexcept;
139 static bool IsEmpty(const char* value) noexcept
141 return value == nullptr || *value == '\0';
143 static bool IsEmpty(cm::string_view value) noexcept { return value.empty(); }
146 * Does a string indicates that CMake/CPack/CTest internally
147 * forced this value. This is not the same as On, but this
148 * may be considered as "internally switched on".
150 static bool IsInternallyOn(const char* value) noexcept
152 return value != nullptr && IsInternallyOn(cm::string_view(value));
154 static bool IsInternallyOn(cm::string_view) noexcept;
157 static std::string Empty;
158 const std::string* Value = nullptr;
161 std::ostream& operator<<(std::ostream& o, cmValue v);
163 inline bool operator==(cmValue l, cmValue r) noexcept
165 return l.Compare(r) == 0;
167 inline bool operator!=(cmValue l, cmValue r) noexcept
169 return l.Compare(r) != 0;
171 inline bool operator<(cmValue l, cmValue r) noexcept
173 return l.Compare(r) < 0;
175 inline bool operator<=(cmValue l, cmValue r) noexcept
177 return l.Compare(r) <= 0;
179 inline bool operator>(cmValue l, cmValue r) noexcept
181 return l.Compare(r) > 0;
183 inline bool operator>=(cmValue l, cmValue r) noexcept
185 return l.Compare(r) >= 0;
188 inline bool operator==(cmValue l, cm::string_view r) noexcept
190 return l.Compare(r) == 0;
192 inline bool operator!=(cmValue l, cm::string_view r) noexcept
194 return l.Compare(r) != 0;
196 inline bool operator<(cmValue l, cm::string_view r) noexcept
198 return l.Compare(r) < 0;
200 inline bool operator<=(cmValue l, cm::string_view r) noexcept
202 return l.Compare(r) <= 0;
204 inline bool operator>(cmValue l, cm::string_view r) noexcept
206 return l.Compare(r) > 0;
208 inline bool operator>=(cmValue l, cm::string_view r) noexcept
210 return l.Compare(r) >= 0;
213 inline bool operator==(cmValue l, std::nullptr_t) noexcept
215 return l.Compare(cmValue{}) == 0;
217 inline bool operator!=(cmValue l, std::nullptr_t) noexcept
219 return l.Compare(cmValue{}) != 0;
221 inline bool operator<(cmValue l, std::nullptr_t) noexcept
223 return l.Compare(cmValue{}) < 0;
225 inline bool operator<=(cmValue l, std::nullptr_t) noexcept
227 return l.Compare(cmValue{}) <= 0;
229 inline bool operator>(cmValue l, std::nullptr_t) noexcept
231 return l.Compare(cmValue{}) > 0;
233 inline bool operator>=(cmValue l, std::nullptr_t) noexcept
235 return l.Compare(cmValue{}) >= 0;
239 * Does a string indicate a true or ON value? This is not the same as ifdef.
241 inline bool cmIsOn(cm::string_view val)
243 return cmValue::IsOn(val);
245 inline bool cmIsOn(const char* val)
247 return cmValue::IsOn(val);
249 inline bool cmIsOn(cmValue val)
255 * Does a string indicate a false or off value ? Note that this is
256 * not the same as !IsOn(...) because there are a number of
257 * ambiguous values such as "/usr/local/bin" a path will result in
258 * IsON and IsOff both returning false. Note that the special path
259 * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
261 inline bool cmIsOff(cm::string_view val)
263 return cmValue::IsOff(val);
265 inline bool cmIsOff(const char* val)
267 return cmValue::IsOff(val);
269 inline bool cmIsOff(cmValue val)
274 /** Return true if value is NOTFOUND or ends in -NOTFOUND. */
275 inline bool cmIsNOTFOUND(cm::string_view val)
277 return cmValue::IsNOTFOUND(val);
279 inline bool cmIsNOTFOUND(cmValue val)
281 return val.IsNOTFOUND();
284 /** Check for non-empty Property/Variable value. */
285 inline bool cmNonempty(cm::string_view val)
287 return !cmValue::IsEmpty(val);
289 inline bool cmNonempty(const char* val)
291 return !cmValue::IsEmpty(val);
293 inline bool cmNonempty(cmValue val)
295 return !val.IsEmpty();
299 * Does a string indicates that CMake/CPack/CTest internally
300 * forced this value. This is not the same as On, but this
301 * may be considered as "internally switched on".
303 inline bool cmIsInternallyOn(cm::string_view val)
305 return cmValue::IsInternallyOn(val);
307 inline bool cmIsInternallyOn(const char* val)
309 return cmValue::IsInternallyOn(val);
311 inline bool cmIsInternallyOn(cmValue val)
313 return val.IsInternallyOn();