Go to the documentation of this file.
16 #ifndef UTILS_RESULT_H_
17 #define UTILS_RESULT_H_
24 #include "flex/utils/error_pb/interactive.pb.h"
26 #include "glog/logging.h"
102 template <
typename T>
111 #define RETURN_IF_NOT_OK(expr) \
113 auto status = (expr); \
114 if (!status.ok()) { \
125 #define ASSIGN_AND_RETURN_IF_RESULT_NOT_OK(var, expr) \
127 auto&& FLEX_TMP_VAR = expr; \
129 ::gs::is_gs_result_type< \
130 typename std::decay<decltype(FLEX_TMP_VAR)>::type>::value, \
131 "The expression must return a Result type"); \
132 if (!FLEX_TMP_VAR.ok()) { \
133 return FLEX_TMP_VAR; \
135 var = std::forward<decltype(FLEX_TMP_VAR)>(FLEX_TMP_VAR).move_value(); \
138 #define ASSIGN_AND_RETURN_IF_STATUS_NOT_OK(var, expr) \
140 auto&& FLEX_TMP_VAR = expr; \
142 ::gs::is_gs_status_type< \
143 typename std::decay<decltype(FLEX_TMP_VAR)>::type>::value, \
144 "The expression must return a Status type"); \
145 if (!FLEX_TMP_VAR.ok()) { \
146 return FLEX_TMP_VAR; \
148 var = std::forward<decltype(FLEX_TMP_VAR)>(FLEX_TMP_VAR).move_value(); \
155 #define FLEX_AUTO(var, expr) ASSIGN_AND_RETURN_IF_NOT_OK(auto var, expr)
159 #define RETURN_FLEX_LEAF_ERROR(code, msg) \
160 return ::boost::leaf::new_error( \
161 gs::Status(::gs::flex::interactive::Code::code, msg))
166 inline std::string
to_string(
const gs::flex::interactive::Code& status) {
168 std::stringstream ss;
169 ss <<
"05-" << std::setw(4) << std::setfill(
'0')
170 <<
static_cast<int32_t
>(status);
175 #endif // UTILS_RESULT_H_
bool ok() const
Definition: result.cc:33
ValueType value_
Definition: result.h:93
ValueType && move_value() noexcept
Definition: result.h:89
Status() noexcept
Definition: result.cc:19
Result(const Status &status)
Definition: result.h:72
std::string to_string(const gs::flex::interactive::Code &status)
Definition: result.h:166
static Status OK()
Definition: result.cc:35
Definition: adj_list.h:23
Result(const Status &status, ValueType &&value)
Definition: result.h:69
std::string error_msg_
Definition: result.h:48
StatusCode error_code() const
Definition: result.cc:31
ValueType & value() noexcept
Definition: result.h:86
StatusCode error_code_
Definition: result.h:47
Result(const ValueType &value)
Definition: result.h:66
const Status & status() const noexcept
Definition: result.h:85
bool ok() const noexcept
Definition: result.h:83
Result(ValueType &&value)
Definition: result.h:67
Definition: loading_config.h:232
std::string ToString() const
Definition: result.cc:37
gs::flex::interactive::Code StatusCode
Definition: result.h:30
Result()
Definition: result.h:65
std::string error_message() const
Definition: result.cc:29
Result(StatusCode code, std::string &&error_msg, const ValueType &value)
Definition: result.h:80
Result(const Status &status, const ValueType &value)
Definition: result.h:74
Result(StatusCode code, const std::string &error_msg, const ValueType &value)
Definition: result.h:77
Status status_
Definition: result.h:92
T ValueType
Definition: result.h:64