1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
#include <cm/string_view>
class cmValue
{
public:
cmValue() noexcept = default;
cmValue(std::nullptr_t) noexcept {}
explicit cmValue(const std::string* value) noexcept
: Value(value)
{
}
explicit cmValue(const std::string& value) noexcept
: Value(&value)
{
}
cmValue(const cmValue& other) noexcept = default;
cmValue& operator=(const cmValue& other) noexcept = default;
cmValue& operator=(std::nullptr_t) noexcept
{
this->Value = nullptr;
return *this;
}
const std::string* Get() const noexcept { return this->Value; }
const char* GetCStr() const noexcept
{
return this->Value ? this->Value->c_str() : nullptr;
}
const std::string* operator->() const noexcept
{
return this->Value ? this->Value : &cmValue::Empty;
}
const std::string& operator*() const noexcept
{
return this->Value ? *this->Value : cmValue::Empty;
}
explicit operator bool() const noexcept { return this->Value != nullptr; }
operator const std::string&() const noexcept { return this->operator*(); }
explicit operator cm::string_view() const noexcept
{
return this->operator*();
}
/**
* Does the value indicate a true or ON value?
*/
bool IsOn() const noexcept
{
return this->Value && cmValue::IsOn(cm::string_view(*this->Value));
}
/**
* Does the value indicate a false or off value ? Note that this is
* not the same as !IsOn(...) because there are a number of
* ambiguous values such as "/usr/local/bin" a path will result in
* IsOn and IsOff both returning false. Note that the special path
* NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
*/
bool IsOff() const noexcept
{
return !this->Value || cmValue::IsOff(cm::string_view(*this->Value));
}
/** Return true if value is NOTFOUND or ends in -NOTFOUND. */
bool IsNOTFOUND() const noexcept
{
return this->Value && cmValue::IsNOTFOUND(cm::string_view(*this->Value));
}
bool IsEmpty() const noexcept
{
return !this->Value || this->Value->empty();
}
/**
* Does a string indicates that CMake/CPack/CTest internally
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
bool IsInternallyOn() const noexcept
{
return this->Value &&
cmValue::IsInternallyOn(cm::string_view(*this->Value));
}
bool IsSet() const noexcept
{
return !this->IsEmpty() && !this->IsNOTFOUND();
}
/**
* Does a string indicate a true or ON value?
*/
static bool IsOn(const char* value) noexcept
{
return value && IsOn(cm::string_view(value));
}
static bool IsOn(cm::string_view) noexcept;
/**
* Compare method has same semantic as std::optional::compare
*/
int Compare(cmValue value) const noexcept;
int Compare(cm::string_view value) const noexcept;
/**
* Does a string indicate a false or off value ? Note that this is
* not the same as !IsOn(...) because there are a number of
* ambiguous values such as "/usr/local/bin" a path will result in
* IsOn and IsOff both returning false. Note that the special path
* NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
*/
static bool IsOff(const char* value) noexcept
{
return !value || IsOff(cm::string_view(value));
}
static bool IsOff(cm::string_view) noexcept;
/** Return true if value is NOTFOUND or ends in -NOTFOUND. */
static bool IsNOTFOUND(const char* value) noexcept
{
return !value || IsNOTFOUND(cm::string_view(value));
}
static bool IsNOTFOUND(cm::string_view) noexcept;
static bool IsEmpty(const char* value) noexcept
{
return !value || *value == '\0';
}
static bool IsEmpty(cm::string_view value) noexcept { return value.empty(); }
/**
* Does a string indicates that CMake/CPack/CTest internally
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
static bool IsInternallyOn(const char* value) noexcept
{
return value && IsInternallyOn(cm::string_view(value));
}
static bool IsInternallyOn(cm::string_view) noexcept;
private:
static std::string Empty;
const std::string* Value = nullptr;
};
std::ostream& operator<<(std::ostream& o, cmValue v);
inline bool operator==(cmValue l, cmValue r) noexcept
{
return l.Compare(r) == 0;
}
inline bool operator!=(cmValue l, cmValue r) noexcept
{
return l.Compare(r) != 0;
}
inline bool operator<(cmValue l, cmValue r) noexcept
{
return l.Compare(r) < 0;
}
inline bool operator<=(cmValue l, cmValue r) noexcept
{
return l.Compare(r) <= 0;
}
inline bool operator>(cmValue l, cmValue r) noexcept
{
return l.Compare(r) > 0;
}
inline bool operator>=(cmValue l, cmValue r) noexcept
{
return l.Compare(r) >= 0;
}
inline bool operator==(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) == 0;
}
inline bool operator!=(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) != 0;
}
inline bool operator<(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) < 0;
}
inline bool operator<=(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) <= 0;
}
inline bool operator>(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) > 0;
}
inline bool operator>=(cmValue l, cm::string_view r) noexcept
{
return l.Compare(r) >= 0;
}
inline bool operator==(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) == 0;
}
inline bool operator!=(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) != 0;
}
inline bool operator<(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) < 0;
}
inline bool operator<=(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) <= 0;
}
inline bool operator>(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) > 0;
}
inline bool operator>=(cmValue l, std::nullptr_t) noexcept
{
return l.Compare(cmValue{}) >= 0;
}
/**
* Does a string indicate a true or ON value? This is not the same as ifdef.
*/
inline bool cmIsOn(cm::string_view val)
{
return cmValue::IsOn(val);
}
inline bool cmIsOn(const char* val)
{
return cmValue::IsOn(val);
}
inline bool cmIsOn(cmValue val)
{
return val.IsOn();
}
/**
* Does a string indicate a false or off value ? Note that this is
* not the same as !IsOn(...) because there are a number of
* ambiguous values such as "/usr/local/bin" a path will result in
* IsON and IsOff both returning false. Note that the special path
* NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
*/
inline bool cmIsOff(cm::string_view val)
{
return cmValue::IsOff(val);
}
inline bool cmIsOff(const char* val)
{
return cmValue::IsOff(val);
}
inline bool cmIsOff(cmValue val)
{
return val.IsOff();
}
/** Return true if value is NOTFOUND or ends in -NOTFOUND. */
inline bool cmIsNOTFOUND(cm::string_view val)
{
return cmValue::IsNOTFOUND(val);
}
inline bool cmIsNOTFOUND(cmValue val)
{
return val.IsNOTFOUND();
}
/** Check for non-empty Property/Variable value. */
inline bool cmNonempty(cm::string_view val)
{
return !cmValue::IsEmpty(val);
}
inline bool cmNonempty(const char* val)
{
return !cmValue::IsEmpty(val);
}
inline bool cmNonempty(cmValue val)
{
return !val.IsEmpty();
}
/**
* Does a string indicates that CMake/CPack/CTest internally
* forced this value. This is not the same as On, but this
* may be considered as "internally switched on".
*/
inline bool cmIsInternallyOn(cm::string_view val)
{
return cmValue::IsInternallyOn(val);
}
inline bool cmIsInternallyOn(const char* val)
{
return cmValue::IsInternallyOn(val);
}
inline bool cmIsInternallyOn(cmValue val)
{
return val.IsInternallyOn();
}
|