16 #ifndef UTILS_RESULT_H_
17 #define UTILS_RESULT_H_
25 #include "flex/utils/error_pb/interactive.pb.h"
27 #include "glog/logging.h"
100 template <
typename T>
103 template <
typename T>
112 #define RETURN_IF_NOT_OK(expr) \
114 auto status = (expr); \
115 if (!status.ok()) { \
126 #define ASSIGN_AND_RETURN_IF_RESULT_NOT_OK(var, expr) \
128 auto&& FLEX_TMP_VAR = expr; \
130 ::gs::is_gs_result_type< \
131 typename std::decay<decltype(FLEX_TMP_VAR)>::type>::value, \
132 "The expression must return a Result type"); \
133 if (!FLEX_TMP_VAR.ok()) { \
134 return FLEX_TMP_VAR; \
136 var = std::forward<decltype(FLEX_TMP_VAR)>(FLEX_TMP_VAR).move_value(); \
139 #define ASSIGN_AND_RETURN_IF_STATUS_NOT_OK(var, expr) \
141 auto&& FLEX_TMP_VAR = expr; \
143 ::gs::is_gs_status_type< \
144 typename std::decay<decltype(FLEX_TMP_VAR)>::type>::value, \
145 "The expression must return a Status type"); \
146 if (!FLEX_TMP_VAR.ok()) { \
147 return FLEX_TMP_VAR; \
149 var = std::forward<decltype(FLEX_TMP_VAR)>(FLEX_TMP_VAR).move_value(); \
156 #define FLEX_AUTO(var, expr) ASSIGN_AND_RETURN_IF_NOT_OK(auto var, expr)
160 #define RETURN_FLEX_LEAF_ERROR(code, msg) \
161 return ::boost::leaf::new_error( \
162 gs::Status(::gs::flex::interactive::Code::code, msg))
167 inline std::string
to_string(
const gs::flex::interactive::Code& status) {
169 std::stringstream ss;
170 ss <<
"05-" << std::setw(4) << std::setfill(
'0')
171 <<
static_cast<int32_t
>(status);
T ValueType
Definition: result.h:65
Result(const Status &status, const ValueType &value)
Definition: result.h:75
Status status_
Definition: result.h:93
Result(const Status &status, ValueType &&value)
Definition: result.h:70
Result(StatusCode code, std::string &&error_msg, const ValueType &value)
Definition: result.h:81
Result(StatusCode code, const std::string &error_msg, const ValueType &value)
Definition: result.h:78
ValueType value_
Definition: result.h:94
Result()
Definition: result.h:66
bool ok() const noexcept
Definition: result.h:84
ValueType & value() noexcept
Definition: result.h:87
Result(ValueType &&value)
Definition: result.h:68
Result(const Status &status)
Definition: result.h:73
const Status & status() const noexcept
Definition: result.h:86
ValueType && move_value() noexcept
Definition: result.h:90
Result(const ValueType &value)
Definition: result.h:67
bool ok() const
Definition: result.cc:33
StatusCode error_code_
Definition: result.h:48
Status() noexcept
Definition: result.cc:19
std::string error_message() const
Definition: result.cc:29
std::string error_msg_
Definition: result.h:49
std::string ToString() const
Definition: result.cc:37
StatusCode error_code() const
Definition: result.cc:31
static Status OK()
Definition: result.cc:35
Definition: adj_list.h:23
gs::flex::interactive::Code StatusCode
Definition: result.h:31
Definition: loading_config.h:232
std::string to_string(const gs::flex::interactive::Code &status)
Definition: result.h:167