| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_STRINGS_NULLABLE_STRING16_H_ | 5 #ifndef BASE_STRINGS_NULLABLE_STRING16_H_ |
| 6 #define BASE_STRINGS_NULLABLE_STRING16_H_ | 6 #define BASE_STRINGS_NULLABLE_STRING16_H_ |
| 7 | 7 |
| 8 #include <iosfwd> |
| 9 |
| 10 #include "base/base_export.h" |
| 8 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 9 | 12 |
| 10 namespace base { | 13 namespace base { |
| 11 | 14 |
| 12 // This class is a simple wrapper for string16 which also contains a null | 15 // This class is a simple wrapper for string16 which also contains a null |
| 13 // state. This should be used only where the difference between null and | 16 // state. This should be used only where the difference between null and |
| 14 // empty is meaningful. | 17 // empty is meaningful. |
| 15 class NullableString16 { | 18 class NullableString16 { |
| 16 public: | 19 public: |
| 17 NullableString16() : is_null_(false) { } | 20 NullableString16() : is_null_(true) { } |
| 18 explicit NullableString16(bool is_null) : is_null_(is_null) { } | 21 explicit NullableString16(bool is_null) : is_null_(is_null) { } |
| 19 NullableString16(const string16& string, bool is_null) | 22 NullableString16(const string16& string, bool is_null) |
| 20 : string_(string), is_null_(is_null) { | 23 : string_(string), is_null_(is_null) { |
| 21 } | 24 } |
| 22 | 25 |
| 23 const string16& string() const { return string_; } | 26 const string16& string() const { return string_; } |
| 24 bool is_null() const { return is_null_; } | 27 bool is_null() const { return is_null_; } |
| 25 | 28 |
| 26 private: | 29 private: |
| 27 string16 string_; | 30 string16 string_; |
| 28 bool is_null_; | 31 bool is_null_; |
| 29 }; | 32 }; |
| 30 | 33 |
| 34 inline bool operator==(const NullableString16& a, const NullableString16& b) { |
| 35 return a.is_null() == b.is_null() && a.string() == b.string(); |
| 36 } |
| 37 |
| 38 inline bool operator!=(const NullableString16& a, const NullableString16& b) { |
| 39 return !(a == b); |
| 40 } |
| 41 |
| 42 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
| 43 const NullableString16& value); |
| 44 |
| 31 } // namespace | 45 } // namespace |
| 32 | 46 |
| 33 // TODO(avi) update users of NullableString16 to use the namespace and remove | 47 // TODO(avi) update users of NullableString16 to use the namespace and remove |
| 34 // this "using". | 48 // this "using". |
| 35 using base::NullableString16; | 49 using base::NullableString16; |
| 36 | 50 |
| 37 #endif // BASE_STRINGS_NULLABLE_STRING16_H_ | 51 #endif // BASE_STRINGS_NULLABLE_STRING16_H_ |
| OLD | NEW |