13 #ifndef __STOUT_CHECK_HPP__ 14 #define __STOUT_CHECK_HPP__ 20 #include <glog/logging.h> 32 template <
typename T,
typename E>
41 #define CHECK_STATE(name, check, expression) \ 42 for (const Option<Error> _error = check(expression); _error.isSome();) \ 43 _CheckFatal(__FILE__, \ 47 _error.get()).stream() 50 #define CHECK_SOME(expression) \ 51 CHECK_STATE(CHECK_SOME, _check_some, expression) 54 #define CHECK_NONE(expression) \ 55 CHECK_STATE(CHECK_NONE, _check_none, expression) 58 #define CHECK_ERROR(expression) \ 59 CHECK_STATE(CHECK_ERROR, _check_error, expression) 71 google::LogMessageFatal(file, line,
new std::string(message));
73 return std::move(t).get();
84 google::LogMessageFatal(file, line,
new std::string(message));
97 google::LogMessageFatal(file, line,
new std::string(message));
103 #define CHECK_NOTNONE(expression) \ 107 "'" #expression "' Must be SOME", \ 113 template <
typename T,
typename E>
120 google::LogMessageFatal(
124 std::string(message) +
": " +
Error(t.error()).message));
126 return std::move(t).get();
130 template <
typename T,
typename E>
137 google::LogMessageFatal(
141 std::string(message) +
": " +
Error(t.
error()).message));
147 template <
typename T,
typename E>
154 google::LogMessageFatal(
158 std::string(message) +
": " +
Error(t.
error()).message));
164 #define CHECK_NOTERROR(expression) \ 168 "'" #expression "' Must be SOME", \ 174 template <
typename T>
178 return Error(
"is NONE");
186 template <
typename T,
typename E>
198 template <
typename T>
204 return Error(
"is NONE");
212 template <
typename T>
216 return Error(
"is SOME");
224 template <
typename T>
228 return Error(
"is ERROR");
230 return Error(
"is SOME");
238 template <
typename T,
typename E>
242 return Error(
"is SOME");
250 template <
typename T>
254 return Error(
"is NONE");
256 return Error(
"is SOME");
269 const char* expression,
274 out << type <<
"(" << expression <<
"): " << error.
message <<
" ";
298 #define CHECK_CONTAINS(container, key) \ 299 if (!(container).contains(key)) \ 300 google::LogMessageFatal(__FILE__, __LINE__).stream() \ 301 << "Check failed: " << #container << " does not contain " << (key) \ 309 #define CHECK_NOT_CONTAINS(container, key) \ 310 if ((container).contains(key)) \ 311 google::LogMessageFatal(__FILE__, __LINE__).stream() \ 312 << "Check failed: " << #container << " already contains " << (key) \ 314 #endif // __STOUT_CHECK_HPP__ std::ostream & stream()
Definition: check.hpp:282
bool isNone() const
Definition: result.hpp:113
Option< Error > _check_some(const Option< T > &o)
Definition: check.hpp:175
Definition: errorbase.hpp:36
Definition: option.hpp:29
T & get()&
Definition: try.hpp:80
const int line
Definition: check.hpp:288
const std::string file
Definition: check.hpp:287
static Result< T > error(const std::string &message)
Definition: result.hpp:54
~_CheckFatal()
Definition: check.hpp:277
bool isSome() const
Definition: option.hpp:116
URI file(const std::string &path)
Creates a file URI with the given path on the local host.
Definition: file.hpp:33
Definition: check.hpp:264
_CheckFatal(const char *_file, int _line, const char *type, const char *expression, const Error &error)
Definition: check.hpp:266
Option< Error > _check_none(const Option< T > &o)
Definition: check.hpp:213
bool isSome() const
Definition: try.hpp:77
const T & get() const &
Definition: option.hpp:119
static Try error(const E &e)
Definition: try.hpp:43
const std::string message
Definition: errorbase.hpp:46
bool isError() const
Definition: try.hpp:78
std::string error(const std::string &msg, uint32_t code)
Try< uint32_t > type(const std::string &path)
bool isNone() const
Definition: option.hpp:117
bool isSome() const
Definition: result.hpp:112
bool isError() const
Definition: result.hpp:114
Option< Error > _check_error(const Try< T, E > &t)
Definition: check.hpp:239
std::ostringstream out
Definition: check.hpp:289
T && _check_not_none(const char *file, int line, const char *message, Option< T > &&t)
Definition: check.hpp:65
T && _check_not_error(const char *file, int line, const char *message, Try< T, E > &&t)
Definition: check.hpp:114