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_LIB_ARRAY_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
7 | 7 |
8 #include <new> | 8 #include <new> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return sizeof(StorageType) * num_elements; | 47 return sizeof(StorageType) * num_elements; |
48 } | 48 } |
49 static Ref ToRef(StorageType* storage, size_t offset) { | 49 static Ref ToRef(StorageType* storage, size_t offset) { |
50 return storage[offset].ptr; | 50 return storage[offset].ptr; |
51 } | 51 } |
52 static ConstRef ToConstRef(const StorageType* storage, size_t offset) { | 52 static ConstRef ToConstRef(const StorageType* storage, size_t offset) { |
53 return storage[offset].ptr; | 53 return storage[offset].ptr; |
54 } | 54 } |
55 }; | 55 }; |
56 | 56 |
| 57 template <typename T> |
| 58 struct ArrayDataTraits<Array_Data<T>*> { |
| 59 typedef ArrayPointer<T> StorageType; |
| 60 typedef Array_Data<T>*& Ref; |
| 61 typedef Array_Data<T>* const& ConstRef; |
| 62 |
| 63 static size_t GetStorageSize(size_t num_elements) { |
| 64 return sizeof(StorageType) * num_elements; |
| 65 } |
| 66 static Ref ToRef(StorageType* storage, size_t offset) { |
| 67 return storage[offset].ptr; |
| 68 } |
| 69 static ConstRef ToConstRef(const StorageType* storage, size_t offset) { |
| 70 return storage[offset].ptr; |
| 71 } |
| 72 }; |
| 73 |
57 // Specialization of Arrays for bools, optimized for space. It has the | 74 // Specialization of Arrays for bools, optimized for space. It has the |
58 // following differences from a generalized Array: | 75 // following differences from a generalized Array: |
59 // * Each element takes up a single bit of memory. | 76 // * Each element takes up a single bit of memory. |
60 // * Accessing a non-const single element uses a helper class |BitRef|, which | 77 // * Accessing a non-const single element uses a helper class |BitRef|, which |
61 // emulates a reference to a bool. | 78 // emulates a reference to a bool. |
62 template <> | 79 template <> |
63 struct ArrayDataTraits<bool> { | 80 struct ArrayDataTraits<bool> { |
64 // Helper class to emulate a reference to a bool, used for direct element | 81 // Helper class to emulate a reference to a bool, used for direct element |
65 // access. | 82 // access. |
66 class BitRef { | 83 class BitRef { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 }; | 375 }; |
359 | 376 |
360 template <> struct WrapperTraits<String, false> { | 377 template <> struct WrapperTraits<String, false> { |
361 typedef String_Data* DataType; | 378 typedef String_Data* DataType; |
362 }; | 379 }; |
363 | 380 |
364 } // namespace internal | 381 } // namespace internal |
365 } // namespace mojo | 382 } // namespace mojo |
366 | 383 |
367 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 384 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
OLD | NEW |