| 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_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 6 #define MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <new> | 8 #include <new> |
| 9 | 9 |
| 10 #include "mojo/public/bindings/lib/buffer.h" | 10 #include "mojo/public/bindings/lib/buffer.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 static Array_Data<T>* New(size_t num_elements, Buffer* buf) { | 156 static Array_Data<T>* New(size_t num_elements, Buffer* buf) { |
| 157 size_t num_bytes = sizeof(Array_Data<T>) + | 157 size_t num_bytes = sizeof(Array_Data<T>) + |
| 158 sizeof(StorageType) * num_elements; | 158 sizeof(StorageType) * num_elements; |
| 159 return new (buf->Allocate(num_bytes)) Array_Data<T>(num_bytes, | 159 return new (buf->Allocate(num_bytes)) Array_Data<T>(num_bytes, |
| 160 num_elements); | 160 num_elements); |
| 161 } | 161 } |
| 162 | 162 |
| 163 size_t size() const { return header_.num_elements; } | 163 size_t size() const { return header_.num_elements; } |
| 164 | 164 |
| 165 T& at(size_t offset) { | 165 T& at(size_t offset) { |
| 166 assert(offset < static_cast<size_t>(header_.num_elements)); |
| 166 return Traits::ToRef(storage()[offset]); | 167 return Traits::ToRef(storage()[offset]); |
| 167 } | 168 } |
| 168 | 169 |
| 169 const T& at(size_t offset) const { | 170 const T& at(size_t offset) const { |
| 171 assert(offset < static_cast<size_t>(header_.num_elements)); |
| 170 return Traits::ToConstRef(storage()[offset]); | 172 return Traits::ToConstRef(storage()[offset]); |
| 171 } | 173 } |
| 172 | 174 |
| 173 StorageType* storage() { | 175 StorageType* storage() { |
| 174 return reinterpret_cast<StorageType*>( | 176 return reinterpret_cast<StorageType*>( |
| 175 reinterpret_cast<char*>(this) + sizeof(*this)); | 177 reinterpret_cast<char*>(this) + sizeof(*this)); |
| 176 } | 178 } |
| 177 | 179 |
| 178 const StorageType* storage() const { | 180 const StorageType* storage() const { |
| 179 return reinterpret_cast<const StorageType*>( | 181 return reinterpret_cast<const StorageType*>( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 return value; | 222 return value; |
| 221 } | 223 } |
| 222 static T& ToRef(T& data) { return data; } | 224 static T& ToRef(T& data) { return data; } |
| 223 static const T& ToConstRef(const T& data) { return data; } | 225 static const T& ToConstRef(const T& data) { return data; } |
| 224 }; | 226 }; |
| 225 | 227 |
| 226 } // namespace internal | 228 } // namespace internal |
| 227 } // namespace mojo | 229 } // namespace mojo |
| 228 | 230 |
| 229 #endif // MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 231 #endif // MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| OLD | NEW |