Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Unified Diff: mojo/public/cpp/bindings/type_converter.h

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/type_converter.h
diff --git a/mojo/public/cpp/bindings/type_converter.h b/mojo/public/cpp/bindings/type_converter.h
index 83597747c55d2887b8ca1531a328ab448fd02730..6c34d68998482552a6b6055c90c4de620c124824 100644
--- a/mojo/public/cpp/bindings/type_converter.h
+++ b/mojo/public/cpp/bindings/type_converter.h
@@ -18,7 +18,7 @@ namespace mojo {
// template <>
// class TypeConverter<T, U> {
// public:
-// static T ConvertFrom(const U& input, Buffer* buf);
+// static T ConvertFrom(const U& input);
// static U ConvertTo(const T& input);
//
// // Maybe (mutually exclusive):
yzshen1 2014/05/27 22:16:59 Please remove all comments about the macros.
@@ -43,17 +43,16 @@ namespace mojo {
//
// namespace mojo {
// template <>
-// class TypeConverter<geometry::Point, gfx::Point> {
+// class TypeConverter<geometry::PointPtr, gfx::Point> {
// public:
-// static geometry::Point ConvertFrom(const gfx::Point& input,
-// Buffer* buf) {
-// geometry::Point::Builder builder(buf);
-// builder.set_x(input.x());
-// builder.set_y(input.y());
-// return builder.Finish();
+// static geometry::PointPtr ConvertFrom(const gfx::Point& input) {
+// geometry::PointPtr result;
+// result->x = input.x();
+// result->y = input.y();
+// return result.Pass();
// }
-// static gfx::Point ConvertTo(const geometry::Point& input) {
-// return gfx::Point(input.x(), input.y());
+// static gfx::Point ConvertTo(const geometry::PointPtr& input) {
+// return input ? gfx::Point(input->x, input->y) : gfx::Point();
// }
// };
// }
@@ -75,7 +74,7 @@ namespace mojo {
//
// To be exact, this macro enables:
// - converting constructor:
-// T(const U& u, mojo::Buffer* buf = mojo::Buffer::current());
+// T(const U& u);
// - assignment operator:
// T& operator=(const U& u);
// - conversion operator:
@@ -112,14 +111,16 @@ namespace mojo {
// please use them wisely.
template <typename T, typename U> class TypeConverter;
-} // namespace mojo
-
-#define MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION() \
- static void AssertAllowImplicitTypeConversion() {}
-
-#define MOJO_INHERIT_IMPLICIT_TYPE_CONVERSION(T, U) \
- static void AssertAllowImplicitTypeConversion() { \
- TypeConverter<T, U>::AssertAllowImplicitTypeConversion(); \
+template <typename T> class TypeConverter<T, T> {
yzshen1 2014/05/27 22:16:59 This probably won't work for move only types like
+ public:
+ static T ConvertFrom(const T& obj) {
+ return obj;
}
+ static T ConvertTo(const T& obj) {
+ return obj;
+ }
+};
+
+} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_TYPE_CONVERTER_H_

Powered by Google App Engine
This is Rietveld 408576698