You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/05/29 19:41:12 UTC
[34/35] git commit: Added stout specific 'CHECK' constructs.
Added stout specific 'CHECK' constructs.
Review: https://reviews.apache.org/r/11472
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/72395798
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/72395798
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/72395798
Branch: refs/heads/master
Commit: 723957980974ddbf5b206500b894731fcce7699d
Parents: 71a01bd
Author: Benjamin Hindman <be...@twitter.com>
Authored: Mon May 27 12:10:52 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Tue May 28 14:20:25 2013 -0700
----------------------------------------------------------------------
3rdparty/libprocess/3rdparty/stout/Makefile.am | 1 +
.../3rdparty/stout/include/stout/check.hpp | 89 +++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/72395798/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index fdd3482..4fdee2c 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -7,6 +7,7 @@ AUTOMAKE_OPTIONS = foreign
EXTRA_DIST = \
include/stout/bytes.hpp \
include/stout/cache.hpp \
+ include/stout/check.hpp \
include/stout/duration.hpp \
include/stout/error.hpp \
include/stout/exit.hpp \
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/72395798/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
new file mode 100644
index 0000000..0165d42
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
@@ -0,0 +1,89 @@
+#ifndef __STOUT_CHECK_HPP__
+#define __STOUT_CHECK_HPP__
+
+#include <ostream>
+#include <sstream>
+#include <string>
+
+#include <glog/logging.h> // Includes LOG(*), PLOG(*), CHECK, etc.
+
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+// Provides a CHECK_SOME macro, akin to CHECK.
+// This appends the error if possible to the end of the log message, so there's
+// no need to append the error message explicitly.
+#define CHECK_SOME(expression) \
+ for (const Option<std::string>& _error = _check(expression); \
+ _error.isSome();) \
+ _CheckSome(__FILE__, __LINE__, #expression, _error.get()).stream() \
+
+// Private structs/functions used for CHECK_SOME.
+
+template <typename T>
+Option<std::string> _check(const Option<T>& o)
+{
+ if (o.isNone()) {
+ return Option<std::string>::some("is NONE");
+ }
+ return None();
+}
+
+
+template <typename T>
+Option<std::string> _check(const Try<T>& t)
+{
+ if (t.isError()) {
+ return t.error();
+ }
+ return None();
+}
+
+
+template <typename T>
+Option<std::string> _check(const Result<T>& r)
+{
+ if (r.isError()) {
+ return r.error();
+ } else if (r.isNone()) {
+ return Option<std::string>::some("is NONE");
+ }
+ return None();
+}
+
+
+struct _CheckSome
+{
+ _CheckSome(const char* _file,
+ int _line,
+ const char* _expression,
+ const std::string& _error)
+ : file(_file),
+ line(_line),
+ expression(_expression),
+ error(_error)
+ {
+ out << "CHECK_SOME(" << expression << "): ";
+ }
+
+ ~_CheckSome()
+ {
+ out << error;
+ google::LogMessageFatal(file.c_str(), line).stream() << out.str();
+ }
+
+ std::ostream& stream()
+ {
+ return out;
+ }
+
+ const std::string file;
+ const int line;
+ const std::string expression;
+ const std::string error;
+ std::ostringstream out;
+};
+
+#endif // __STOUT_CHECK_HPP__