OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/public/cpp/bindings/lib/array_internal.h" | |
6 | |
7 #include <sstream> | |
8 | |
9 namespace mojo { | |
10 namespace internal { | |
11 | |
12 std::string MakeMessageWithArrayIndex(const char* message, | |
13 size_t size, | |
14 size_t index) { | |
15 std::ostringstream stream; | |
16 stream << message << ": array size - " << size << "; index - " << index; | |
17 return stream.str(); | |
18 } | |
19 | |
20 std::string MakeMessageWithExpectedArraySize(const char* message, | |
21 size_t size, | |
22 size_t expected_size) { | |
23 std::ostringstream stream; | |
24 stream << message << ": array size - " << size << "; expected size - " | |
25 << expected_size; | |
26 return stream.str(); | |
27 } | |
28 | |
29 ArrayDataTraits<bool>::BitRef::~BitRef() { | |
30 } | |
31 | |
32 ArrayDataTraits<bool>::BitRef::BitRef(uint8_t* storage, uint8_t mask) | |
33 : storage_(storage), mask_(mask) { | |
34 } | |
35 | |
36 ArrayDataTraits<bool>::BitRef& ArrayDataTraits<bool>::BitRef::operator=( | |
37 bool value) { | |
38 if (value) { | |
39 *storage_ |= mask_; | |
40 } else { | |
41 *storage_ &= ~mask_; | |
42 } | |
43 return *this; | |
44 } | |
45 | |
46 ArrayDataTraits<bool>::BitRef& ArrayDataTraits<bool>::BitRef::operator=( | |
47 const BitRef& value) { | |
48 return (*this) = static_cast<bool>(value); | |
49 } | |
50 | |
51 ArrayDataTraits<bool>::BitRef::operator bool() const { | |
52 return (*storage_ & mask_) != 0; | |
53 } | |
54 | |
55 // static | |
56 void ArraySerializationHelper<Handle, true>::EncodePointersAndHandles( | |
57 const ArrayHeader* header, | |
58 ElementType* elements, | |
59 std::vector<Handle>* handles) { | |
60 for (uint32_t i = 0; i < header->num_elements; ++i) | |
61 EncodeHandle(&elements[i], handles); | |
62 } | |
63 | |
64 // static | |
65 void ArraySerializationHelper<Handle, true>::DecodePointersAndHandles( | |
66 const ArrayHeader* header, | |
67 ElementType* elements, | |
68 std::vector<Handle>* handles) { | |
69 for (uint32_t i = 0; i < header->num_elements; ++i) | |
70 DecodeHandle(&elements[i], handles); | |
71 } | |
72 | |
73 } // namespace internal | |
74 } // namespace mojo | |
OLD | NEW |