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

Side by Side Diff: mojo/public/bindings/type_converter.h

Issue 218613010: Mojo: Move mojo/public/bindings/*.h to mojo/public/cpp/bindings/*.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/tests/type_conversion_unittest.cc ('k') | mojo/public/cpp/bindings/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_BINDINGS_TYPE_CONVERTER_H_
6 #define MOJO_PUBLIC_BINDINGS_TYPE_CONVERTER_H_
7
8 namespace mojo {
9
10 // Specialize to perform type conversion for Mojom-defined structs and arrays.
11 // Here, T is the Mojom-defined struct or array, and U is some other non-Mojom
12 // struct or array type.
13 //
14 // EXAMPLE:
15 //
16 // Suppose you have the following Mojom-defined struct:
17 //
18 // module geometry {
19 // struct Point {
20 // int32 x;
21 // int32 y;
22 // };
23 // }
24 //
25 // Now, imagine you wanted to write a TypeConverter specialization for
26 // gfx::Point. It might look like this:
27 //
28 // namespace mojo {
29 // template <>
30 // class TypeConverter<geometry::Point, gfx::Point> {
31 // public:
32 // static geometry::Point ConvertFrom(const gfx::Point& input,
33 // Buffer* buf) {
34 // geometry::Point::Builder builder(buf);
35 // builder.set_x(input.x());
36 // builder.set_y(input.y());
37 // return builder.Finish();
38 // }
39 // static gfx::Point ConvertTo(const geometry::Point& input) {
40 // return gfx::Point(input.x(), input.y());
41 // }
42 // };
43 // }
44 //
45 // With the above TypeConverter defined, it is possible to write code like this:
46 //
47 // void SomeFunction(const gfx::Point& pt);
48 //
49 // void AcceptPoint(const geometry::Point& input) {
50 // // With an explicit cast using the .To<> method.
51 // gfx::Point pt = input.To<gfx::Point>();
52 //
53 // // With an implicit copy conversion:
54 // SomeFunction(input);
55 //
56 // mojo::AllocationScope scope;
57 // // With an implicit copy conversion:
58 // geometry::Point output = pt;
59 // }
60 //
61 template <typename T, typename U> class TypeConverter {
62 // static T ConvertFrom(const U& input, Buffer* buf);
63 // static U ConvertTo(const T& input);
64 };
65
66 } // namespace mojo
67
68 #endif // MOJO_PUBLIC_BINDINGS_TYPE_CONVERTER_H_
OLDNEW
« no previous file with comments | « mojo/public/bindings/tests/type_conversion_unittest.cc ('k') | mojo/public/cpp/bindings/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698