• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
8 #include <stdint.h>
9 
10 #include <sstream>
11 
12 namespace mojo {
13 namespace internal {
14 
MakeMessageWithArrayIndex(const char * message,size_t size,size_t index)15 std::string MakeMessageWithArrayIndex(const char* message,
16                                       size_t size,
17                                       size_t index) {
18   std::ostringstream stream;
19   stream << message << ": array size - " << size << "; index - " << index;
20   return stream.str();
21 }
22 
MakeMessageWithExpectedArraySize(const char * message,size_t size,size_t expected_size)23 std::string MakeMessageWithExpectedArraySize(const char* message,
24                                              size_t size,
25                                              size_t expected_size) {
26   std::ostringstream stream;
27   stream << message << ": array size - " << size << "; expected size - "
28          << expected_size;
29   return stream.str();
30 }
31 
~BitRef()32 ArrayDataTraits<bool>::BitRef::~BitRef() {
33 }
34 
BitRef(uint8_t * storage,uint8_t mask)35 ArrayDataTraits<bool>::BitRef::BitRef(uint8_t* storage, uint8_t mask)
36     : storage_(storage), mask_(mask) {
37 }
38 
operator =(bool value)39 ArrayDataTraits<bool>::BitRef& ArrayDataTraits<bool>::BitRef::operator=(
40     bool value) {
41   if (value) {
42     *storage_ |= mask_;
43   } else {
44     *storage_ &= ~mask_;
45   }
46   return *this;
47 }
48 
operator =(const BitRef & value)49 ArrayDataTraits<bool>::BitRef& ArrayDataTraits<bool>::BitRef::operator=(
50     const BitRef& value) {
51   return (*this) = static_cast<bool>(value);
52 }
53 
operator bool() const54 ArrayDataTraits<bool>::BitRef::operator bool() const {
55   return (*storage_ & mask_) != 0;
56 }
57 
58 }  // namespace internal
59 }  // namespace mojo
60