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:32:03 UTC

[10/50] mesos git commit: Added a `Representation` abstraction to stout.

Added a `Representation` abstraction to stout.

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


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

Branch: refs/heads/0.26.x
Commit: 74df9179c88a6ea3e993a739e2704b392dcbf04a
Parents: 138fab3
Author: Michael Park <mp...@apache.org>
Authored: Tue Jan 5 14:34:05 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Feb 26 20:59:04 2016 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  1 +
 .../stout/include/stout/representation.hpp      | 83 ++++++++++++++++++++
 2 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/74df9179/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index d6b12f9..51bfcd7 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -118,6 +118,7 @@ nobase_include_HEADERS =		\
   stout/posix/gzip.hpp			\
   stout/posix/os.hpp			\
   stout/recordio.hpp			\
+  stout/representation.hpp			\
   stout/result.hpp			\
   stout/set.hpp				\
   stout/some.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/74df9179/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
new file mode 100644
index 0000000..22f70f7
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
@@ -0,0 +1,83 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_REPRESENTATION_HPP__
+#define __STOUT_REPRESENTATION_HPP__
+
+#include <functional>
+
+// The class template `Representation` is a generic base class to support types
+// that have multiple human-readable representations of itself.
+//
+// `Time` is a good example of such a type. Even though the __underlying__
+// representation may be a `std::chrono::time_point` or even a `time_t`, there
+// are multiple formats in which we can print them out.
+//
+// NOTE: These classes are light-weight objects that simply holds a reference to
+// a type `T`, and therefore cannot be used with a temporary.
+//
+// NOTE: The pattern is to inherit from `Representation`, and pull in
+// `Representation`'s constructors with using declarations. The explicit `using`
+// declarations are necessary since inheritance does not inherit the base class'
+// constructors. Also note that a type alias is not sufficient, since we need to
+// give rise to distinct types.
+//
+// Example:
+//
+// ```
+// // Two different representations of `Time`.
+//
+// struct RFC1123 : Representation<Time>
+// {
+//   using Representation<Time>::Representation;
+// };
+//
+// struct RFC3339 : Representation<Time>
+// {
+//   using Representation<Time>::Representation;
+// };
+//
+// // `operator<<` for the two different representations of `Time`.
+//
+// std::ostream& operator<<(std::ostream& stream, const RFC1123& rfc1123)
+// {
+//    const Time& t = rfc1123;
+//    // Print in `RFC1123` format.
+// }
+//
+// std::ostream& operator<<(std::ostream& stream, const RFC3339& rfc3339)
+// {
+//    const Time& t = rfc1123;
+//    // Print in `RFC3339` format.
+// }
+//
+// int main()
+// {
+//   Time t = ...;
+//   std::cout << RFC1123(t);  // Print in `RFC1123` format.
+//   std::cout << RFC3339(t);  // Print in `RFC1123` format.
+// }
+// ```
+
+template <typename T>
+struct Representation : std::reference_wrapper<const T>
+{
+  // We pull in `std::reference_wrapper`'s constructors since inheritance does
+  // not inherit the base class' constructors.
+  using std::reference_wrapper<const T>::reference_wrapper;
+
+  // Disallow rebinding.
+  Representation& operator=(const Representation&) = delete;
+  Representation& operator=(Representation&&) = delete;
+};
+
+#endif // __STOUT_REPRESENTATION_HPP__