You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/04/25 23:31:58 UTC
[05/50] mesos git commit: Updated `json` to handle integral types
comprehensively.
Updated `json` to handle integral types comprehensively.
Review: https://reviews.apache.org/r/42543
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/61fcc82b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/61fcc82b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/61fcc82b
Branch: refs/heads/0.26.x
Commit: 61fcc82b192b96978a20aafae01cee69065150ba
Parents: 8f32e53
Author: Michael Park <mp...@apache.org>
Authored: Tue Jan 19 20:08:53 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Feb 26 20:59:04 2016 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/jsonify.hpp | 103 +++++++++++++++----
1 file changed, 83 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/61fcc82b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
index a87b9e2..5e1df28 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
@@ -127,7 +127,7 @@ class NumberWriter
{
public:
NumberWriter(std::ostream* stream)
- : stream_(stream), type_(INT64), int64_(0) {}
+ : stream_(stream), type_(INT), int_(0) {}
NumberWriter(const NumberWriter&) = delete;
NumberWriter(NumberWriter&&) = delete;
@@ -135,12 +135,12 @@ public:
~NumberWriter()
{
switch (type_) {
- case INT64: {
- *stream_ << int64_;
+ case INT: {
+ *stream_ << int_;
break;
}
- case UINT64: {
- *stream_ << uint64_;
+ case UINT: {
+ *stream_ << uint_;
break;
}
case DOUBLE: {
@@ -169,20 +169,52 @@ public:
NumberWriter& operator=(const NumberWriter&) = delete;
NumberWriter& operator=(NumberWriter&&) = delete;
- void set(int32_t value) { set(static_cast<int64_t>(value)); }
+ // NOTE 1: We enumerate overloads for all of the integral types here to avoid
+ // ambiguities between signed and unsigned conversions. If we were to only
+ // overload for `long long int` and `unsigned long long int`, passing an
+ // argument of `0` would be ambiguous since `0` has type `int`, and cost of
+ // conversion to `long long int` or `unsigned long long int` is equivalent.
- void set(int64_t value)
+ // NOTE 2: We use the various modifiers on `int` as opposed to fixed size
+ // types such as `int32_t` and `int64_t` because these types do not cover all
+ // of the integral types. For example, `uint32_t` may map to `unsigned int`,
+ // and `uint64_t` to `unsigned long long int`. If `size_t` maps to `unsigned
+ // long int`, it is ambiguous to pass an instance of `size_t`. defining an
+ // overload for `size_t` would solve the problem on a specific platform, but
+ // we can run into issues again on another platform if `size_t` maps to
+ // `unsigned long long int`, since we would get a redefinition error.
+
+ void set(short int value) { set(static_cast<long long int>(value)); }
+
+ void set(int value) { set(static_cast<long long int>(value)); }
+
+ void set(long int value) { set(static_cast<long long int>(value)); }
+
+ void set(long long int value)
{
- type_ = INT64;
- int64_ = value;
+ type_ = INT;
+ int_ = value;
}
- void set(uint32_t value) { set(static_cast<uint64_t>(value)); }
+ void set(unsigned short int value)
+ {
+ set(static_cast<unsigned long long int>(value));
+ }
+
+ void set(unsigned int value)
+ {
+ set(static_cast<unsigned long long int>(value));
+ }
- void set(uint64_t value)
+ void set(unsigned long int value)
{
- type_ = UINT64;
- uint64_ = value;
+ set(static_cast<unsigned long long int>(value));
+ }
+
+ void set(unsigned long long int value)
+ {
+ type_ = UINT;
+ uint_ = value;
}
void set(float value) { set(static_cast<double>(value)); }
@@ -196,12 +228,12 @@ public:
private:
std::ostream* stream_;
- enum { INT64, UINT64, DOUBLE } type_;
+ enum { INT, UINT, DOUBLE } type_;
union
{
- int64_t int64_;
- uint64_t uint64_;
+ long long int int_;
+ unsigned long long int uint_;
double double_;
};
};
@@ -335,10 +367,41 @@ inline void json(BooleanWriter* writer, bool value) { writer->set(value); }
// `json` functions for numbers.
-inline void json(NumberWriter* writer, int32_t value) { writer->set(value); }
-inline void json(NumberWriter* writer, int64_t value) { writer->set(value); }
-inline void json(NumberWriter* writer, uint32_t value) { writer->set(value); }
-inline void json(NumberWriter* writer, uint64_t value) { writer->set(value); }
+inline void json(NumberWriter* writer, short int value) { writer->set(value); }
+inline void json(NumberWriter* writer, int value) { writer->set(value); }
+inline void json(NumberWriter* writer, long int value) { writer->set(value); }
+
+
+inline void json(NumberWriter* writer, long long int value)
+{
+ writer->set(value);
+}
+
+
+inline void json(NumberWriter* writer, unsigned short int value)
+{
+ writer->set(value);
+}
+
+
+inline void json(NumberWriter* writer, unsigned int value)
+{
+ writer->set(value);
+}
+
+
+inline void json(NumberWriter* writer, unsigned long int value)
+{
+ writer->set(value);
+}
+
+
+inline void json(NumberWriter* writer, unsigned long long int value)
+{
+ writer->set(value);
+}
+
+
inline void json(NumberWriter* writer, float value) { writer->set(value); }
inline void json(NumberWriter* writer, double value) { writer->set(value); }