You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ch...@apache.org on 2018/11/29 18:32:06 UTC
[mesos] 07/09: Cleaned up `include/mesos/type_utils.hpp`.
This is an automated email from the ASF dual-hosted git repository.
chhsiao pushed a commit to branch 1.7.x
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 0ae89dc43872166e9f83e5ab1cd3c63efab4bb4a
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Wed Nov 14 20:13:53 2018 -0800
Cleaned up `include/mesos/type_utils.hpp`.
This patch does the following cleanups:
1. Moved `google::protobuf::Map` equality operator to `type_utils.hpp`.
2. Moved the type helper templates for the protobuf library that do not
involve mesos protobufs into the `google::protobuf` namespaces so ADL
works appropriately.
3. Removed the type helper templates for the protobuf library from
`mesos/v1/mesos.hpp` to avoid redefinition.
Review: https://reviews.apache.org/r/69363
---
include/mesos/type_utils.hpp | 46 ++++++++++++++++++++--
include/mesos/v1/mesos.hpp | 27 +------------
.../storage/uri_disk_profile_adaptor.cpp | 26 +-----------
3 files changed, 47 insertions(+), 52 deletions(-)
diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp
index 19ea817..f276697 100644
--- a/include/mesos/type_utils.hpp
+++ b/include/mesos/type_utils.hpp
@@ -23,6 +23,7 @@
#include <boost/functional/hash.hpp>
+#include <google/protobuf/map.h>
#include <google/protobuf/repeated_field.h>
#include <mesos/mesos.hpp>
@@ -475,7 +476,7 @@ std::ostream& operator<<(
template <typename T>
inline std::ostream& operator<<(
std::ostream& stream,
- const google::protobuf::RepeatedPtrField<T>& messages)
+ const std::vector<T>& messages)
{
stream << "[ ";
for (auto it = messages.begin(); it != messages.end(); ++it) {
@@ -488,11 +489,48 @@ inline std::ostream& operator<<(
return stream;
}
+} // namespace mesos {
+
+
+/**
+ * Type utilities for the protobuf library that are not specific to particular
+ * protobuf classes. They are defined in the `google::protobuf` namespace for
+ * argument-dependent lookup.
+ */
+namespace google {
+namespace protobuf {
+
+template <typename Key, typename Value>
+inline bool operator==(
+ const Map<Key, Value>& left, const Map<Key, Value>& right)
+{
+ if (left.size() != right.size()) {
+ return false;
+ }
+
+ for (auto it = left.begin(); it != left.end(); ++it) {
+ auto found = right.find(it->first);
+ if (found == right.end() || found->second != it->second) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+template <typename Key, typename Value>
+inline bool operator!=(
+ const Map<Key, Value>& left, const Map<Key, Value>& right)
+{
+ return !(left == right);
+}
+
template <typename T>
inline std::ostream& operator<<(
std::ostream& stream,
- const std::vector<T>& messages)
+ const RepeatedPtrField<T>& messages)
{
stream << "[ ";
for (auto it = messages.begin(); it != messages.end(); ++it) {
@@ -505,7 +543,9 @@ inline std::ostream& operator<<(
return stream;
}
-} // namespace mesos {
+} // namespace protobuf {
+} // namespace google {
+
namespace std {
diff --git a/include/mesos/v1/mesos.hpp b/include/mesos/v1/mesos.hpp
index fda3eb4..a6a9320 100644
--- a/include/mesos/v1/mesos.hpp
+++ b/include/mesos/v1/mesos.hpp
@@ -23,8 +23,6 @@
#include <boost/functional/hash.hpp>
-#include <google/protobuf/repeated_field.h>
-
#include <mesos/v1/mesos.pb.h> // ONLY USEFUL AFTER RUNNING PROTOC.
#include <stout/strings.hpp>
@@ -32,7 +30,7 @@
// This file includes definitions for operators on public protobuf
// classes (defined in mesos.proto, module.proto, etc.) that don't
// have these operators generated by the protobuf compiler. The
-// corresponding definitions are in src/v1/type_utils.cpp.
+// corresponding definitions are in src/v1/mesos.cpp.
//
// Mesos modules need some of the protobuf classes defined in
// mesos.proto, module.proto, etc., and require some of these
@@ -469,23 +467,6 @@ std::ostream& operator<<(
template <typename T>
inline std::ostream& operator<<(
std::ostream& stream,
- const google::protobuf::RepeatedPtrField<T>& messages)
-{
- stream << "[ ";
- for (auto it = messages.begin(); it != messages.end(); ++it) {
- if (it != messages.begin()) {
- stream << ", ";
- }
- stream << *it;
- }
- stream << " ]";
- return stream;
-}
-
-
-template <typename T>
-inline std::ostream& operator<<(
- std::ostream& stream,
const std::vector<T>& messages)
{
stream << "[ ";
@@ -499,14 +480,10 @@ inline std::ostream& operator<<(
return stream;
}
-
-std::ostream& operator<<(
- std::ostream& stream,
- const hashmap<std::string, std::string>& map);
-
} // namespace v1 {
} // namespace mesos {
+
namespace std {
template <>
diff --git a/src/resource_provider/storage/uri_disk_profile_adaptor.cpp b/src/resource_provider/storage/uri_disk_profile_adaptor.cpp
index 6c998ef..cb574be 100644
--- a/src/resource_provider/storage/uri_disk_profile_adaptor.cpp
+++ b/src/resource_provider/storage/uri_disk_profile_adaptor.cpp
@@ -22,6 +22,8 @@
#include <csi/spec.hpp>
+#include <mesos/type_utils.hpp>
+
#include <mesos/module/disk_profile_adaptor.hpp>
#include <process/defer.hpp>
@@ -58,30 +60,6 @@ namespace mesos {
namespace internal {
namespace storage {
-bool operator==(
- const Map<string, string>& left,
- const Map<string, string>& right) {
- if (left.size() != right.size()) {
- return false;
- }
-
- typename Map<string, string>::const_iterator iterator = left.begin();
- while (iterator != left.end()) {
- if (right.count(iterator->first) != 1) {
- return false;
- }
-
- if (iterator->second != right.at(iterator->first)) {
- return false;
- }
-
- ++iterator;
- }
-
- return true;
-}
-
-
UriDiskProfileAdaptor::UriDiskProfileAdaptor(const Flags& _flags)
: flags(_flags),
process(new UriDiskProfileAdaptorProcess(flags))