13 #ifndef __STOUT_CHECK_HPP__
14 #define __STOUT_CHECK_HPP__
20 #include <glog/logging.h>
35 #define CHECK_STATE(name, check, expression) \
36 for (const Option<Error> _error = check(expression); _error.isSome();) \
37 _CheckFatal(__FILE__, \
41 _error.get()).stream()
44 #define CHECK_SOME(expression) \
45 CHECK_STATE(CHECK_SOME, _check_some, expression)
48 #define CHECK_NONE(expression) \
49 CHECK_STATE(CHECK_NONE, _check_none, expression)
52 #define CHECK_ERROR(expression) \
53 CHECK_STATE(CHECK_ERROR, _check_error, expression)
65 google::LogMessageFatal(file, line,
new std::string(message));
67 return std::move(t).get();
78 google::LogMessageFatal(file, line,
new std::string(message));
91 google::LogMessageFatal(file, line,
new std::string(message));
97 #define CHECK_NOTNONE(expression) \
101 "'" #expression "' Must be SOME", \
107 template <
typename T>
111 return Error(
"is NONE");
119 template <
typename T>
131 template <
typename T>
137 return Error(
"is NONE");
145 template <
typename T>
149 return Error(
"is SOME");
157 template <
typename T>
161 return Error(
"is ERROR");
163 return Error(
"is SOME");
171 template <
typename T>
175 return Error(
"is SOME");
183 template <
typename T>
187 return Error(
"is NONE");
189 return Error(
"is SOME");
202 const char* expression,
207 out << type <<
"(" << expression <<
"): " << error.
message <<
" ";
225 #endif // __STOUT_CHECK_HPP__
std::ostream & stream()
Definition: check.hpp:215
bool isNone() const
Definition: result.hpp:112
Option< Error > _check_some(const Option< T > &o)
Definition: check.hpp:108
Definition: errorbase.hpp:35
Definition: option.hpp:28
const int line
Definition: check.hpp:221
const std::string file
Definition: check.hpp:220
static Result< T > error(const std::string &message)
Definition: result.hpp:53
~_CheckFatal()
Definition: check.hpp:210
Definition: result.hpp:40
bool isSome() const
Definition: option.hpp:115
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:197
_CheckFatal(const char *_file, int _line, const char *type, const char *expression, const Error &error)
Definition: check.hpp:199
Option< Error > _check_none(const Option< T > &o)
Definition: check.hpp:146
bool isSome() const
Definition: try.hpp:70
const T & get() const &
Definition: option.hpp:118
static Try error(const E &e)
Definition: try.hpp:42
Option< Error > _check_error(const Try< T > &t)
Definition: check.hpp:172
const std::string message
Definition: errorbase.hpp:45
bool isError() const
Definition: try.hpp:71
std::string error(const std::string &msg, uint32_t code)
Try< uint32_t > type(const std::string &path)
bool isNone() const
Definition: option.hpp:116
bool isSome() const
Definition: result.hpp:111
bool isError() const
Definition: result.hpp:113
std::ostringstream out
Definition: check.hpp:222
T && _check_not_none(const char *file, int line, const char *message, Option< T > &&t)
Definition: check.hpp:59