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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <limits> | 11 #include <limits> |
12 #include <new> | 12 #include <new> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "mojo/public/c/system/macros.h" | 15 #include "mojo/public/c/system/macros.h" |
| 16 #include "mojo/public/cpp/bindings/bindings_export.h" |
16 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 17 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
17 #include "mojo/public/cpp/bindings/lib/buffer.h" | 18 #include "mojo/public/cpp/bindings/lib/buffer.h" |
18 #include "mojo/public/cpp/bindings/lib/serialization_util.h" | 19 #include "mojo/public/cpp/bindings/lib/serialization_util.h" |
19 #include "mojo/public/cpp/bindings/lib/template_util.h" | 20 #include "mojo/public/cpp/bindings/lib/template_util.h" |
20 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 21 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
21 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 22 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
22 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 23 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
23 #include "mojo/public/cpp/bindings/lib/validation_util.h" | 24 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
24 | 25 |
25 namespace mojo { | 26 namespace mojo { |
26 namespace internal { | 27 namespace internal { |
27 | 28 |
28 template <typename K, typename V> | 29 template <typename K, typename V> |
29 class Map_Data; | 30 class Map_Data; |
30 | 31 |
31 std::string MakeMessageWithArrayIndex(const char* message, | 32 MOJO_CPP_BINDINGS_EXPORT std::string |
32 size_t size, | 33 MakeMessageWithArrayIndex(const char* message, size_t size, size_t index); |
33 size_t index); | |
34 | 34 |
35 std::string MakeMessageWithExpectedArraySize(const char* message, | 35 MOJO_CPP_BINDINGS_EXPORT std::string MakeMessageWithExpectedArraySize( |
36 size_t size, | 36 const char* message, |
37 size_t expected_size); | 37 size_t size, |
| 38 size_t expected_size); |
38 | 39 |
39 template <typename T> | 40 template <typename T> |
40 struct ArrayDataTraits { | 41 struct ArrayDataTraits { |
41 using StorageType = T; | 42 using StorageType = T; |
42 using Ref = T&; | 43 using Ref = T&; |
43 using ConstRef = const T&; | 44 using ConstRef = const T&; |
44 | 45 |
45 static const uint32_t kMaxNumElements = | 46 static const uint32_t kMaxNumElements = |
46 (std::numeric_limits<uint32_t>::max() - sizeof(ArrayHeader)) / | 47 (std::numeric_limits<uint32_t>::max() - sizeof(ArrayHeader)) / |
47 sizeof(StorageType); | 48 sizeof(StorageType); |
(...skipping 12 matching lines...) Loading... |
60 | 61 |
61 // Specialization of Arrays for bools, optimized for space. It has the | 62 // Specialization of Arrays for bools, optimized for space. It has the |
62 // following differences from a generalized Array: | 63 // following differences from a generalized Array: |
63 // * Each element takes up a single bit of memory. | 64 // * Each element takes up a single bit of memory. |
64 // * Accessing a non-const single element uses a helper class |BitRef|, which | 65 // * Accessing a non-const single element uses a helper class |BitRef|, which |
65 // emulates a reference to a bool. | 66 // emulates a reference to a bool. |
66 template <> | 67 template <> |
67 struct ArrayDataTraits<bool> { | 68 struct ArrayDataTraits<bool> { |
68 // Helper class to emulate a reference to a bool, used for direct element | 69 // Helper class to emulate a reference to a bool, used for direct element |
69 // access. | 70 // access. |
70 class BitRef { | 71 class MOJO_CPP_BINDINGS_EXPORT BitRef { |
71 public: | 72 public: |
72 ~BitRef(); | 73 ~BitRef(); |
73 BitRef& operator=(bool value); | 74 BitRef& operator=(bool value); |
74 BitRef& operator=(const BitRef& value); | 75 BitRef& operator=(const BitRef& value); |
75 operator bool() const; | 76 operator bool() const; |
76 | 77 |
77 private: | 78 private: |
78 friend struct ArrayDataTraits<bool>; | 79 friend struct ArrayDataTraits<bool>; |
79 BitRef(uint8_t* storage, uint8_t mask); | 80 BitRef(uint8_t* storage, uint8_t mask); |
80 BitRef(); | 81 BitRef(); |
(...skipping 277 matching lines...) Loading... |
358 }; | 359 }; |
359 static_assert(sizeof(Array_Data<char>) == 8, "Bad sizeof(Array_Data)"); | 360 static_assert(sizeof(Array_Data<char>) == 8, "Bad sizeof(Array_Data)"); |
360 | 361 |
361 // UTF-8 encoded | 362 // UTF-8 encoded |
362 using String_Data = Array_Data<char>; | 363 using String_Data = Array_Data<char>; |
363 | 364 |
364 } // namespace internal | 365 } // namespace internal |
365 } // namespace mojo | 366 } // namespace mojo |
366 | 367 |
367 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 368 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
OLD | NEW |