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

Side by Side Diff: mojo/public/cpp/bindings/lib/array_internal.h

Issue 340223002: Add ArrayDataTraits<> specialization for Array_Data<T>*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/data/validation/conformance_mthd6_good.data » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/data/validation/conformance_mthd6_good.data » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698