namespace art { // Result of a type-parsing attempt. If successful holds the strongly-typed value, // otherwise it holds either a help or a failure string message that should be displayed back // to the user. // // CmdlineType::Parse/CmdlineType::ParseAndAppend must return this type. template <typename T> struct CmdlineParseResult : CmdlineResult { using CmdlineResult::CmdlineResult;
// Create an error result with the help error code and the specified message. static CmdlineParseResult Help(const std::string& message) { return CmdlineParseResult(kHelp, message);
}
// Create an error result with the failure error code and no message. static CmdlineParseResult<T> Failure() { return CmdlineParseResult(kFailure);
}
// Create an error result with the failure error code and no message. static CmdlineParseResult<T> Failure(const std::string& message) { return CmdlineParseResult(kFailure, message);
}
// Create a successful result which holds the specified value. static CmdlineParseResult<T> Success(const T& value) { return CmdlineParseResult(value);
}
// Create a successful result, taking over the value. static CmdlineParseResult<T> Success(T&& value) { return CmdlineParseResult(std::forward<T>(value));
}
// Create succesful result, without any values. Used when a value was successfully appended // into an existing object. static CmdlineParseResult<T> SuccessNoValue() { return CmdlineParseResult(T {});
}
// Create an error result with the Invalid error and the specified message. static CmdlineParseResult<T> Invalid(const std::string& message) { return CmdlineParseResult(kInvalid, message);
}
// Create an error result with the OutOfRange code and a custom message // which is printed from the actual/min/max values. // Values are converted to string using the ostream<< operator. static CmdlineParseResult<T> OutOfRange(const T& value, const T& min, const T& max) { return CmdlineParseResult::Invalid("actual: " + art::detail::ToStringAny(value) + ", min: " + art::detail::ToStringAny(min) + ", max: " + art::detail::ToStringAny(max));
}
// Get a read-only reference to the underlying value. // The result must have been successful and must have a value. const T& GetValue() const {
assert(IsSuccess());
assert(has_value_); return value_;
}
// Get a mutable reference to the underlying value. // The result must have been successful and must have a value.
T& GetValue() {
assert(IsSuccess());
assert(has_value_); return value_;
}
// Take over the value. // The result must have been successful and must have a value.
T&& ReleaseValue() {
assert(IsSuccess());
assert(has_value_); return std::move(value_);
}
// Whether or not the result has a value (e.g. created with Result::Success). // Error results never have values, success results commonly, but not always, have values. bool HasValue() const { return has_value_;
}
// Cast an error-result from type T2 to T1. // Safe since error-results don't store a typed value. template <typename T2> static CmdlineParseResult<T> CastError(const CmdlineParseResult<T2>& other) {
assert(other.IsError()); return CmdlineParseResult<T>(other.GetStatus());
}
// Make sure copying is allowed
CmdlineParseResult(const CmdlineParseResult&) = default; // Make sure moving is cheap
CmdlineParseResult(CmdlineParseResult&&) noexcept = default;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.