54 return codeStr +
": " +
message + (
path.empty() ?
"" :
" (path: " +
path +
")");
81 const std::string &path =
"") {
86 const std::string &details =
"") {
92 template <
typename T,
typename E>
112 explicit operator bool() const noexcept {
120 throw std::logic_error(
"Accessing value of Result with error");
122 return std::get<T>(data_);
128 throw std::logic_error(
"Accessing value of Result with error");
130 return std::get<T>(data_);
136 throw std::logic_error(
"Accessing value of Result with error");
138 return std::get<T>(std::move(data_));
145 throw std::logic_error(
"Accessing error of Result with value");
147 return std::get<E>(data_);
153 throw std::logic_error(
"Accessing error of Result with value");
155 return std::get<E>(data_);
161 throw std::logic_error(
"Accessing error of Result with value");
163 return std::get<E>(std::move(data_));
189 return std::move(
value());
193 template <
typename U>
196 return hasValue_ ? std::get<T>(data_) :
static_cast<T
>(std::forward<U>(defaultValue));
199 template <
typename U>
202 return hasValue_ ? std::get<T>(std::move(data_))
203 :
static_cast<T
>(std::forward<U>(defaultValue));
207 std::variant<T, E> data_;
212 template <
typename E>
216 Result() : error_(std::nullopt), hasValue_(true) {}
229 explicit operator bool() const noexcept {
236 throw std::logic_error(
"Accessing error of successful Result");
244 throw std::logic_error(
"Accessing error of successful Result");
250 std::optional<E> error_;
bool hasValue() const noexcept
Definition UtilsError.hpp:224
Result()
Definition UtilsError.hpp:216
Result(E &&error)
Definition UtilsError.hpp:221
Result(const E &error)
Definition UtilsError.hpp:219
E & error() &
Definition UtilsError.hpp:234
const E & error() const &
Definition UtilsError.hpp:242
T & operator*() &
Definition UtilsError.hpp:178
T valueOr(U &&defaultValue) &&
Definition UtilsError.hpp:201
T & value() &
Definition UtilsError.hpp:118
Result(const E &error)
Definition UtilsError.hpp:101
Result(const T &value)
Definition UtilsError.hpp:96
E & error() &
Definition UtilsError.hpp:143
bool hasValue() const noexcept
Definition UtilsError.hpp:107
T valueOr(U &&defaultValue) const &
Definition UtilsError.hpp:195
T * operator->()
Definition UtilsError.hpp:168
const T * operator->() const
Definition UtilsError.hpp:173
T && value() &&
Definition UtilsError.hpp:134
T && operator*() &&
Definition UtilsError.hpp:188
const T & operator*() const &
Definition UtilsError.hpp:183
const E & error() const &
Definition UtilsError.hpp:151
Result(E &&error)
Definition UtilsError.hpp:103
const T & value() const &
Definition UtilsError.hpp:126
Result(T &&value)
Definition UtilsError.hpp:98
E && error() &&
Definition UtilsError.hpp:159
Definition DirectoryManager.cpp:5
JsonError makeJsonError(JsonErrorCode code, const std::string &message, const std::string &details="")
Definition UtilsError.hpp:85
FileError makeFileError(FileErrorCode code, const std::string &message, const std::string &path="")
Definition UtilsError.hpp:80
FileErrorCode
Definition UtilsError.hpp:12
@ NotFound
Definition UtilsError.hpp:13
@ WriteError
Definition UtilsError.hpp:17
@ IsDirectory
Definition UtilsError.hpp:19
@ InvalidPath
Definition UtilsError.hpp:18
@ Unknown
Definition UtilsError.hpp:21
@ AlreadyExists
Definition UtilsError.hpp:15
@ NotDirectory
Definition UtilsError.hpp:20
@ AccessDenied
Definition UtilsError.hpp:14
@ ReadError
Definition UtilsError.hpp:16
@ Unknown
Definition IPlatformInfo.hpp:10
JsonErrorCode
Definition UtilsError.hpp:25
@ FileNotFound
Definition UtilsError.hpp:28
@ MissingKey
Definition UtilsError.hpp:30
@ Unknown
Definition UtilsError.hpp:31
@ InvalidType
Definition UtilsError.hpp:29
@ ParseError
Definition UtilsError.hpp:26
@ InvalidStructure
Definition UtilsError.hpp:27
Definition UtilsError.hpp:35
std::string message
Definition UtilsError.hpp:37
std::string toString() const
Definition UtilsError.hpp:41
FileErrorCode code
Definition UtilsError.hpp:36
std::string path
Definition UtilsError.hpp:38
Definition UtilsError.hpp:59
std::string details
Definition UtilsError.hpp:62
JsonErrorCode code
Definition UtilsError.hpp:60
std::string toString() const
Definition UtilsError.hpp:65
std::string message
Definition UtilsError.hpp:61