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

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

Issue 507173003: Change TypeConverter<X,Y>::ConvertFrom and ConvertTo into a single symmetric (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile for real Created 6 years, 3 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
« no previous file with comments | « mojo/public/cpp/bindings/array.h ('k') | mojo/public/cpp/bindings/struct_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/string.h
diff --git a/mojo/public/cpp/bindings/string.h b/mojo/public/cpp/bindings/string.h
index 872dbca87f237869a50b3ebcbf6990ee332ee59a..cd7db26e8230a8f1fa1df62822e3d972bb60e571 100644
--- a/mojo/public/cpp/bindings/string.h
+++ b/mojo/public/cpp/bindings/string.h
@@ -32,12 +32,12 @@ class String {
template <typename U>
static String From(const U& other) {
- return TypeConverter<String, U>::ConvertFrom(other);
+ return TypeConverter<String, U>::Convert(other);
}
template <typename U>
U To() const {
- return TypeConverter<String, U>::ConvertTo(*this);
+ return TypeConverter<U, String>::Convert(*this);
}
String& operator=(const std::string& str) {
@@ -113,20 +113,18 @@ inline std::ostream& operator<<(std::ostream& out, const String& s) {
// TODO(darin): Add similar variants of operator<,<=,>,>=
template <>
-class TypeConverter<String, std::string> {
- public:
- static String ConvertFrom(const std::string& input) {
- return String(input);
- }
- static std::string ConvertTo(const String& input) {
- return input;
- }
+struct TypeConverter<String, std::string> {
+ static String Convert(const std::string& input) { return String(input); }
+};
+
+template <>
+struct TypeConverter<std::string, String> {
+ static std::string Convert(const String& input) { return input; }
};
template <size_t N>
-class TypeConverter<String, char[N]> {
- public:
- static String ConvertFrom(const char input[N]) {
+struct TypeConverter<String, char[N]> {
+ static String Convert(const char input[N]) {
MOJO_DCHECK(input);
return String(input, N-1);
}
@@ -134,21 +132,17 @@ class TypeConverter<String, char[N]> {
// Appease MSVC.
template <size_t N>
-class TypeConverter<String, const char[N]> {
- public:
- static String ConvertFrom(const char input[N]) {
+struct TypeConverter<String, const char[N]> {
+ static String Convert(const char input[N]) {
MOJO_DCHECK(input);
return String(input, N-1);
}
};
template <>
-class TypeConverter<String, const char*> {
- public:
+struct TypeConverter<String, const char*> {
// |input| may be null, in which case a null String will be returned.
- static String ConvertFrom(const char* input) {
- return String(input);
- }
+ static String Convert(const char* input) { return String(input); }
};
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/array.h ('k') | mojo/public/cpp/bindings/struct_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698