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 2014/03/04 23:35:50 UTC
git commit: Made visitors be top-level structs.
Repository: mesos
Updated Branches:
refs/heads/master a77d9b65e -> 087ed2805
Made visitors be top-level structs.
When compiling with GCC 4.2 we need to keep Boost visitors as
top-level classes instead of nest them in functions.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/087ed280
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/087ed280
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/087ed280
Branch: refs/heads/master
Commit: 087ed280519b9b62d6c744d54f9d77704dba6eff
Parents: a77d9b6
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Mar 4 14:34:04 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Tue Mar 4 14:35:44 2014 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/json.hpp | 87 ++---
.../3rdparty/stout/include/stout/protobuf.hpp | 367 ++++++++++---------
2 files changed, 231 insertions(+), 223 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/087ed280/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
index e52be56..0ce002c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
@@ -173,63 +173,64 @@ struct Value : internal::Variant
};
-inline bool operator == (const Value& lhs, const Value& rhs)
+struct Comparator : boost::static_visitor<bool>
{
- struct Visitor : boost::static_visitor<bool>
- {
- Visitor(const Value& _value)
- : value(_value) {}
+ Comparator(const Value& _value)
+ : value(_value) {}
- bool operator () (const Object& object) const
- {
- if (value.is<Object>()) {
- return value.as<Object>().values == object.values;
- }
- return false;
+ bool operator () (const Object& object) const
+ {
+ if (value.is<Object>()) {
+ return value.as<Object>().values == object.values;
}
+ return false;
+ }
- bool operator () (const String& string) const
- {
- if (value.is<String>()) {
- return value.as<String>().value == string.value;
- }
- return false;
+ bool operator () (const String& string) const
+ {
+ if (value.is<String>()) {
+ return value.as<String>().value == string.value;
}
+ return false;
+ }
- bool operator () (const Number& number) const
- {
- if (value.is<Number>()) {
- return value.as<Number>().value == number.value;
- }
- return false;
+ bool operator () (const Number& number) const
+ {
+ if (value.is<Number>()) {
+ return value.as<Number>().value == number.value;
}
+ return false;
+ }
- bool operator () (const Array& array) const
- {
- if (value.is<Array>()) {
- return value.as<Array>().values == array.values;
- }
- return false;
+ bool operator () (const Array& array) const
+ {
+ if (value.is<Array>()) {
+ return value.as<Array>().values == array.values;
}
+ return false;
+ }
- bool operator () (const Boolean& boolean) const
- {
- if (value.is<Boolean>()) {
- return value.as<Boolean>().value == boolean.value;
- }
- return false;
+ bool operator () (const Boolean& boolean) const
+ {
+ if (value.is<Boolean>()) {
+ return value.as<Boolean>().value == boolean.value;
}
+ return false;
+ }
- bool operator () (const Null&) const
- {
- return value.is<Null>();
- }
+ bool operator () (const Null&) const
+ {
+ return value.is<Null>();
+ }
+
+private:
+ const Value& value;
+};
- private:
- const Value& value;
- };
- return boost::apply_visitor(Visitor(lhs), rhs);
+inline bool operator == (const Value& lhs, const Value& rhs)
+{
+ return boost::apply_visitor(Comparator(lhs), rhs);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/087ed280/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index 75b0827..6fe795f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -180,203 +180,210 @@ inline Result<T> read(const std::string& path)
namespace internal {
-inline Try<Nothing> parse(
+// Forward declaration.
+Try<Nothing> parse(
google::protobuf::Message* message,
- const JSON::Object& object)
+ const JSON::Object& object);
+
+
+struct Parser : boost::static_visitor<Try<Nothing> >
{
- struct Visitor : boost::static_visitor<Try<Nothing> >
+ Parser(google::protobuf::Message* _message,
+ const google::protobuf::FieldDescriptor* _field)
+ : message(_message),
+ reflection(message->GetReflection()),
+ field(_field) {}
+
+ Try<Nothing> operator () (const JSON::Object& object) const
{
- Visitor(google::protobuf::Message* _message,
- const google::protobuf::FieldDescriptor* _field)
- : message(_message),
- reflection(message->GetReflection()),
- field(_field) {}
-
- Try<Nothing> operator () (const JSON::Object& object) const
- {
- switch (field->type()) {
- case google::protobuf::FieldDescriptor::TYPE_MESSAGE:
- if (field->is_repeated()) {
- parse(reflection->AddMessage(message, field), object);
- } else {
- parse(reflection->MutableMessage(message, field), object);
- }
- break;
- default:
- return Error("Not expecting a JSON object for field '" +
- field->name() + "'");
- }
- return Nothing();
+ switch (field->type()) {
+ case google::protobuf::FieldDescriptor::TYPE_MESSAGE:
+ if (field->is_repeated()) {
+ parse(reflection->AddMessage(message, field), object);
+ } else {
+ parse(reflection->MutableMessage(message, field), object);
+ }
+ break;
+ default:
+ return Error("Not expecting a JSON object for field '" +
+ field->name() + "'");
}
+ return Nothing();
+ }
- Try<Nothing> operator () (const JSON::String& string) const
- {
- switch (field->type()) {
- case google::protobuf::FieldDescriptor::TYPE_STRING:
- case google::protobuf::FieldDescriptor::TYPE_BYTES:
- if (field->is_repeated()) {
- reflection->AddString(message, field, string.value);
- } else {
- reflection->SetString(message, field, string.value);
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_ENUM:
- if (field->is_repeated()) {
- reflection->AddEnum(
- message,
- field,
- field->enum_type()->FindValueByName(
- strings::upper(string.value)));
- } else {
- reflection->SetEnum(
- message,
- field,
- field->enum_type()->FindValueByName(
- strings::upper(string.value)));
- }
- break;
- default:
- return Error("Not expecting a JSON string for field '" +
- field->name() + "'");
- }
- return Nothing();
+ Try<Nothing> operator () (const JSON::String& string) const
+ {
+ switch (field->type()) {
+ case google::protobuf::FieldDescriptor::TYPE_STRING:
+ case google::protobuf::FieldDescriptor::TYPE_BYTES:
+ if (field->is_repeated()) {
+ reflection->AddString(message, field, string.value);
+ } else {
+ reflection->SetString(message, field, string.value);
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_ENUM:
+ if (field->is_repeated()) {
+ reflection->AddEnum(
+ message,
+ field,
+ field->enum_type()->FindValueByName(
+ strings::upper(string.value)));
+ } else {
+ reflection->SetEnum(
+ message,
+ field,
+ field->enum_type()->FindValueByName(
+ strings::upper(string.value)));
+ }
+ break;
+ default:
+ return Error("Not expecting a JSON string for field '" +
+ field->name() + "'");
}
+ return Nothing();
+ }
- Try<Nothing> operator () (const JSON::Number& number) const
- {
- switch (field->type()) {
- case google::protobuf::FieldDescriptor::TYPE_DOUBLE:
- if (field->is_repeated()) {
- reflection->AddDouble(message, field, number.value);
- } else {
- reflection->SetDouble(message, field, number.value);
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_FLOAT:
- if (field->is_repeated()) {
- reflection->AddFloat(
- message,
- field,
- static_cast<float>(number.value));
- } else {
- reflection->SetFloat(
- message,
- field,
- static_cast<float>(number.value));
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_INT64:
- case google::protobuf::FieldDescriptor::TYPE_SINT64:
- case google::protobuf::FieldDescriptor::TYPE_SFIXED64:
- if (field->is_repeated()) {
- reflection->AddInt64(
- message,
- field,
- static_cast<int64_t>(number.value));
- } else {
- reflection->SetInt64(
- message,
- field,
- static_cast<int64_t>(number.value));
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_UINT64:
- case google::protobuf::FieldDescriptor::TYPE_FIXED64:
- if (field->is_repeated()) {
- reflection->AddUInt64(
- message,
- field,
- static_cast<uint64_t>(number.value));
- } else {
- reflection->SetUInt64(
- message,
- field,
- static_cast<uint64_t>(number.value));
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_INT32:
- case google::protobuf::FieldDescriptor::TYPE_SINT32:
- case google::protobuf::FieldDescriptor::TYPE_SFIXED32:
- if (field->is_repeated()) {
- reflection->AddInt32(
- message,
- field,
- static_cast<int32_t>(number.value));
- } else {
- reflection->SetInt32(
- message,
- field,
- static_cast<int32_t>(number.value));
- }
- break;
- case google::protobuf::FieldDescriptor::TYPE_UINT32:
- case google::protobuf::FieldDescriptor::TYPE_FIXED32:
- if (field->is_repeated()) {
- reflection->AddUInt32(
- message,
- field,
- static_cast<uint32_t>(number.value));
- } else {
- reflection->SetUInt32(
- message,
- field,
- static_cast<uint32_t>(number.value));
- }
- break;
- default:
- return Error("Not expecting a JSON number for field '" +
- field->name() + "'");
- }
- return Nothing();
+ Try<Nothing> operator () (const JSON::Number& number) const
+ {
+ switch (field->type()) {
+ case google::protobuf::FieldDescriptor::TYPE_DOUBLE:
+ if (field->is_repeated()) {
+ reflection->AddDouble(message, field, number.value);
+ } else {
+ reflection->SetDouble(message, field, number.value);
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_FLOAT:
+ if (field->is_repeated()) {
+ reflection->AddFloat(
+ message,
+ field,
+ static_cast<float>(number.value));
+ } else {
+ reflection->SetFloat(
+ message,
+ field,
+ static_cast<float>(number.value));
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_INT64:
+ case google::protobuf::FieldDescriptor::TYPE_SINT64:
+ case google::protobuf::FieldDescriptor::TYPE_SFIXED64:
+ if (field->is_repeated()) {
+ reflection->AddInt64(
+ message,
+ field,
+ static_cast<int64_t>(number.value));
+ } else {
+ reflection->SetInt64(
+ message,
+ field,
+ static_cast<int64_t>(number.value));
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_UINT64:
+ case google::protobuf::FieldDescriptor::TYPE_FIXED64:
+ if (field->is_repeated()) {
+ reflection->AddUInt64(
+ message,
+ field,
+ static_cast<uint64_t>(number.value));
+ } else {
+ reflection->SetUInt64(
+ message,
+ field,
+ static_cast<uint64_t>(number.value));
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_INT32:
+ case google::protobuf::FieldDescriptor::TYPE_SINT32:
+ case google::protobuf::FieldDescriptor::TYPE_SFIXED32:
+ if (field->is_repeated()) {
+ reflection->AddInt32(
+ message,
+ field,
+ static_cast<int32_t>(number.value));
+ } else {
+ reflection->SetInt32(
+ message,
+ field,
+ static_cast<int32_t>(number.value));
+ }
+ break;
+ case google::protobuf::FieldDescriptor::TYPE_UINT32:
+ case google::protobuf::FieldDescriptor::TYPE_FIXED32:
+ if (field->is_repeated()) {
+ reflection->AddUInt32(
+ message,
+ field,
+ static_cast<uint32_t>(number.value));
+ } else {
+ reflection->SetUInt32(
+ message,
+ field,
+ static_cast<uint32_t>(number.value));
+ }
+ break;
+ default:
+ return Error("Not expecting a JSON number for field '" +
+ field->name() + "'");
}
+ return Nothing();
+ }
- Try<Nothing> operator () (const JSON::Array& array) const
- {
- if (!field->is_repeated()) {
- return Error("Not expecting a JSON array for field '" +
- field->name() + "'");
- }
+ Try<Nothing> operator () (const JSON::Array& array) const
+ {
+ if (!field->is_repeated()) {
+ return Error("Not expecting a JSON array for field '" +
+ field->name() + "'");
+ }
- foreach (const JSON::Value& value, array.values) {
- Try<Nothing> apply =
- boost::apply_visitor(Visitor(message, field), value);
+ foreach (const JSON::Value& value, array.values) {
+ Try<Nothing> apply =
+ boost::apply_visitor(Parser(message, field), value);
- if (apply.isError()) {
- return Error(apply.error());
- }
+ if (apply.isError()) {
+ return Error(apply.error());
}
-
- return Nothing();
}
- Try<Nothing> operator () (const JSON::Boolean& boolean) const
- {
- switch (field->type()) {
- case google::protobuf::FieldDescriptor::TYPE_BOOL:
- if (field->is_repeated()) {
- reflection->AddBool(message, field, boolean.value);
- } else {
- reflection->SetBool(message, field, boolean.value);
- }
- break;
- default:
- return Error("Not expecting a JSON boolean for field '" +
- field->name() + "'");
- }
- return Nothing();
- }
+ return Nothing();
+ }
- Try<Nothing> operator () (const JSON::Null&) const
- {
- return Error("Not expecting a JSON null");
+ Try<Nothing> operator () (const JSON::Boolean& boolean) const
+ {
+ switch (field->type()) {
+ case google::protobuf::FieldDescriptor::TYPE_BOOL:
+ if (field->is_repeated()) {
+ reflection->AddBool(message, field, boolean.value);
+ } else {
+ reflection->SetBool(message, field, boolean.value);
+ }
+ break;
+ default:
+ return Error("Not expecting a JSON boolean for field '" +
+ field->name() + "'");
}
+ return Nothing();
+ }
- private:
- google::protobuf::Message* message;
- const google::protobuf::Reflection* reflection;
- const google::protobuf::FieldDescriptor* field;
- };
+ Try<Nothing> operator () (const JSON::Null&) const
+ {
+ return Error("Not expecting a JSON null");
+ }
+private:
+ google::protobuf::Message* message;
+ const google::protobuf::Reflection* reflection;
+ const google::protobuf::FieldDescriptor* field;
+};
+
+
+inline Try<Nothing> parse(
+ google::protobuf::Message* message,
+ const JSON::Object& object)
+{
foreachpair (
const std::string& name, const JSON::Value& value, object.values) {
// Look for a field by this name.
@@ -385,7 +392,7 @@ inline Try<Nothing> parse(
if (field != NULL) {
Try<Nothing> apply =
- boost::apply_visitor(Visitor(message, field), value);
+ boost::apply_visitor(Parser(message, field), value);
if (apply.isError()) {
return Error(apply.error());