Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / public / cpp / bindings / lib / array_internal.cc
blob9f62aa2b20ce5fc4458a29a60bb1baaea8552bab
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.
5 #include "mojo/public/cpp/bindings/lib/array_internal.h"
7 #include <sstream>
9 namespace mojo {
10 namespace internal {
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();
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();
29 ArrayDataTraits<bool>::BitRef::~BitRef() {
32 ArrayDataTraits<bool>::BitRef::BitRef(uint8_t* storage, uint8_t mask)
33 : storage_(storage),
34 mask_(mask) {
37 ArrayDataTraits<bool>::BitRef&
38 ArrayDataTraits<bool>::BitRef::operator=(bool value) {
39 if (value) {
40 *storage_ |= mask_;
41 } else {
42 *storage_ &= ~mask_;
44 return *this;
47 ArrayDataTraits<bool>::BitRef&
48 ArrayDataTraits<bool>::BitRef::operator=(const BitRef& value) {
49 return (*this) = static_cast<bool>(value);
52 ArrayDataTraits<bool>::BitRef::operator bool() const {
53 return (*storage_ & mask_) != 0;
56 // static
57 void ArraySerializationHelper<Handle, true>::EncodePointersAndHandles(
58 const ArrayHeader* header,
59 ElementType* elements,
60 std::vector<Handle>* handles) {
61 for (uint32_t i = 0; i < header->num_elements; ++i)
62 EncodeHandle(&elements[i], handles);
65 // static
66 void ArraySerializationHelper<Handle, true>::DecodePointersAndHandles(
67 const ArrayHeader* header,
68 ElementType* elements,
69 std::vector<Handle>* handles) {
70 for (uint32_t i = 0; i < header->num_elements; ++i)
71 DecodeHandle(&elements[i], handles);
74 } // namespace internal
75 } // namespace mojo