You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/07/21 19:07:16 UTC

[2/2] mesos git commit: Replaced boost::lexical_cast with numify when parsing Value.

Replaced boost::lexical_cast with numify when parsing Value.

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


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

Branch: refs/heads/master
Commit: 19bfd89849883033e17bd20f410139e2311da060
Parents: 723f308
Author: Klaus Ma <kl...@gmail.com>
Authored: Thu Jul 21 12:06:32 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Thu Jul 21 12:06:45 2016 -0700

----------------------------------------------------------------------
 src/common/values.cpp | 21 +++++++++++----------
 src/v1/values.cpp     | 21 +++++++++++----------
 2 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/19bfd898/src/common/values.cpp
----------------------------------------------------------------------
diff --git a/src/common/values.cpp b/src/common/values.cpp
index c0f5b32..cc87d94 100644
--- a/src/common/values.cpp
+++ b/src/common/values.cpp
@@ -26,8 +26,6 @@
 
 #include <glog/logging.h>
 
-#include <boost/lexical_cast.hpp>
-
 #include <mesos/resources.hpp>
 #include <mesos/values.hpp>
 
@@ -601,13 +599,15 @@ Try<Value> parse(const string& text)
         Value::Range* range = ranges->add_range();
 
         int j = i;
-        try {
-          range->set_begin(boost::lexical_cast<uint64_t>((tokens[j++])));
-          range->set_end(boost::lexical_cast<uint64_t>(tokens[j++]));
-        } catch (const boost::bad_lexical_cast&) {
+        Try<uint64_t> begin = numify<uint64_t>(tokens[j++]);
+        Try<uint64_t> end = numify<uint64_t>(tokens[j++]);
+        if (begin.isError() || end.isError()) {
           return Error(
               "Expecting non-negative integers in '" + tokens[j - 1] + "'");
         }
+
+        range->set_begin(begin.get());
+        range->set_end(end.get());
       }
 
       coalesce(ranges);
@@ -626,13 +626,14 @@ Try<Value> parse(const string& text)
       }
       return value;
     } else if (index == string::npos) {
-      try {
+      Try<double> value_ = numify<double>(temp);
+      if (!value_.isError()) {
         // This is a scalar.
-        value.set_type(Value::SCALAR);
         Value::Scalar* scalar = value.mutable_scalar();
-        scalar->set_value(boost::lexical_cast<double>(temp));
+        value.set_type(Value::SCALAR);
+        scalar->set_value(value_.get());
         return value;
-      } catch (const boost::bad_lexical_cast&) {
+      } else {
         // This is a text.
         value.set_type(Value::TEXT);
         Value::Text* text = value.mutable_text();

http://git-wip-us.apache.org/repos/asf/mesos/blob/19bfd898/src/v1/values.cpp
----------------------------------------------------------------------
diff --git a/src/v1/values.cpp b/src/v1/values.cpp
index 122c84a..6e3617e 100644
--- a/src/v1/values.cpp
+++ b/src/v1/values.cpp
@@ -26,8 +26,6 @@
 
 #include <glog/logging.h>
 
-#include <boost/lexical_cast.hpp>
-
 #include <mesos/v1/resources.hpp>
 #include <mesos/v1/values.hpp>
 
@@ -602,13 +600,15 @@ Try<Value> parse(const string& text)
         Value::Range* range = ranges->add_range();
 
         int j = i;
-        try {
-          range->set_begin(boost::lexical_cast<uint64_t>((tokens[j++])));
-          range->set_end(boost::lexical_cast<uint64_t>(tokens[j++]));
-        } catch (const boost::bad_lexical_cast&) {
+        Try<uint64_t> begin = numify<uint64_t>(tokens[j++]);
+        Try<uint64_t> end = numify<uint64_t>(tokens[j++]);
+        if (begin.isError() || end.isError()) {
           return Error(
               "Expecting non-negative integers in '" + tokens[j - 1] + "'");
         }
+
+        range->set_begin(begin.get());
+        range->set_end(end.get());
       }
 
       coalesce(ranges);
@@ -627,13 +627,14 @@ Try<Value> parse(const string& text)
       }
       return value;
     } else if (index == string::npos) {
-      try {
+      Try<double> value_ = numify<double>(temp);
+      if (!value_.isError()) {
         // This is a scalar.
-        value.set_type(Value::SCALAR);
         Value::Scalar* scalar = value.mutable_scalar();
-        scalar->set_value(boost::lexical_cast<double>(temp));
+        value.set_type(Value::SCALAR);
+        scalar->set_value(value_.get());
         return value;
-      } catch (const boost::bad_lexical_cast&) {
+      } else {
         // This is a text.
         value.set_type(Value::TEXT);
         Value::Text* text = value.mutable_text();