Repository: mesos
Updated Branches:
  refs/heads/master 763364e86 -> 26527296f


stout: Introduce CHECK_NONE and CHECK_ERROR.

Review: https://reviews.apache.org/r/35422


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5f7c5a7d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5f7c5a7d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5f7c5a7d

Branch: refs/heads/master
Commit: 5f7c5a7d95aa4065e85accf13149b4eb3d798e8c
Parents: 93b60ab
Author: Michael Park <[email protected]>
Authored: Sat Jun 13 05:24:24 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Sun Jun 14 02:42:59 2015 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/check.hpp      | 115 ++++++++++++++++---
 1 file changed, 96 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5f7c5a7d/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
index 3972383..b550bfe 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
@@ -21,52 +21,129 @@
 #include <glog/logging.h>
 
 #include <stout/abort.hpp>
+#include <stout/error.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
 #include <stout/result.hpp>
 #include <stout/some.hpp>
 #include <stout/try.hpp>
 
-// Provides a CHECK_SOME macro, akin to CHECK.
+// A generic macro to faciliate definitions of CHECK_*, 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();)                                                \
-    _CheckFatal(__FILE__, __LINE__, "CHECK_SOME",                       \
-                #expression, _error.get()).stream()
+// To define a new CHECK_*, provide the name, the function that performs the
+// check, and the expression. See below for examples (e.g. CHECK_SOME).
+#define CHECK_STATE(name, check, expression)                             \
+  for (const Option<Error> _error = check(expression); _error.isSome();) \
+    _CheckFatal(__FILE__,                                                \
+                __LINE__,                                                \
+                #name,                                                   \
+                #expression,                                             \
+                _error.get()).stream()
+
+
+#define CHECK_SOME(expression) \
+  CHECK_STATE(CHECK_SOME, _check_some, expression)
+
+
+#define CHECK_NONE(expression) \
+  CHECK_STATE(CHECK_NONE, _check_none, expression)
+
+
+#define CHECK_ERROR(expression) \
+  CHECK_STATE(CHECK_ERROR, _check_error, expression)
+
+
+// Private structs/functions used for CHECK_*.
 
-// Private structs/functions used for CHECK_SOME.
 
 template <typename T>
-Option<std::string> _check(const Option<T>& o)
+Option<Error> _check_some(const Option<T>& o)
 {
   if (o.isNone()) {
-    return Some("is NONE");
+    return Error("is NONE");
+  } else {
+    CHECK(o.isSome());
+    return None();
   }
-  return None();
 }
 
 
 template <typename T>
-Option<std::string> _check(const Try<T>& t)
+Option<Error> _check_some(const Try<T>& t)
 {
   if (t.isError()) {
-    return t.error();
+    return Error(t.error());
+  } else {
+    CHECK(t.isSome());
+    return None();
   }
-  return None();
 }
 
 
 template <typename T>
-Option<std::string> _check(const Result<T>& r)
+Option<Error> _check_some(const Result<T>& r)
 {
   if (r.isError()) {
-    return r.error();
+    return Error(r.error());
   } else if (r.isNone()) {
-    return Some("is NONE");
+    return Error("is NONE");
+  } else {
+    CHECK(r.isSome());
+    return None();
+  }
+}
+
+
+template <typename T>
+Option<Error> _check_none(const Option<T>& o)
+{
+  if (o.isSome()) {
+    return Error("is SOME");
+  } else {
+    CHECK(o.isNone());
+    return None();
+  }
+}
+
+
+template <typename T>
+Option<Error> _check_none(const Result<T>& r)
+{
+  if (r.isError()) {
+    return Error("is ERROR");
+  } else if (r.isSome()) {
+    return Error("is SOME");
+  } else {
+    CHECK(r.isNone());
+    return None();
+  }
+}
+
+
+template <typename T>
+Option<Error> _check_error(const Try<T>& t)
+{
+  if (t.isSome()) {
+    return Error("is SOME");
+  } else {
+    CHECK(t.isError());
+    return None();
+  }
+}
+
+
+template <typename T>
+Option<Error> _check_error(const Result<T>& r)
+{
+  if (r.isNone()) {
+    return Error("is NONE");
+  } else if (r.isSome()) {
+    return Error("is SOME");
+  } else {
+    CHECK(r.isError());
+    return None();
   }
-  return None();
 }
 
 
@@ -76,11 +153,11 @@ struct _CheckFatal
               int _line,
               const char* type,
               const char* expression,
-              const std::string& error)
+              const Error& error)
       : file(_file),
         line(_line)
   {
-    out << type << "(" << expression << "): " << error << " ";
+    out << type << "(" << expression << "): " << error.message << " ";
   }
 
   ~_CheckFatal()

Reply via email to