| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 void Swap(Array* other) { | 99 void Swap(Array* other) { |
| 100 std::swap(is_null_, other->is_null_); | 100 std::swap(is_null_, other->is_null_); |
| 101 vec_.swap(other->vec_); | 101 vec_.swap(other->vec_); |
| 102 } | 102 } |
| 103 void Swap(std::vector<StorageType>* other) { | 103 void Swap(std::vector<StorageType>* other) { |
| 104 is_null_ = false; | 104 is_null_ = false; |
| 105 vec_.swap(*other); | 105 vec_.swap(*other); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Please note that calling this method will fail compilation if the element |
| 109 // type cannot be cloned (which usually means that it is a Mojo handle type or |
| 110 // a type contains Mojo handles). |
| 111 Array Clone() const { |
| 112 Array result; |
| 113 result.is_null_ = is_null_; |
| 114 Traits::Clone(vec_, &result.vec_); |
| 115 return result.Pass(); |
| 116 } |
| 117 |
| 108 private: | 118 private: |
| 109 typedef std::vector<StorageType> Array::*Testable; | 119 typedef std::vector<StorageType> Array::*Testable; |
| 110 | 120 |
| 111 public: | 121 public: |
| 112 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } | 122 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } |
| 113 | 123 |
| 114 private: | 124 private: |
| 115 void Take(Array* other) { | 125 void Take(Array* other) { |
| 116 reset(); | 126 reset(); |
| 117 Swap(other); | 127 Swap(other); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 for (size_t i = 0; i < input.size(); ++i) | 150 for (size_t i = 0; i < input.size(); ++i) |
| 141 result[i] = TypeConverter<E, T>::Convert(input[i]); | 151 result[i] = TypeConverter<E, T>::Convert(input[i]); |
| 142 } | 152 } |
| 143 return result; | 153 return result; |
| 144 } | 154 } |
| 145 }; | 155 }; |
| 146 | 156 |
| 147 } // namespace mojo | 157 } // namespace mojo |
| 148 | 158 |
| 149 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 159 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| OLD | NEW |