OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/values.h" | |
10 | |
11 namespace bluez { | |
12 | |
13 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( | |
14 Type type, | |
15 size_t size, | |
16 base::Value* value) | |
17 : type_(type), size_(size) { | |
18 CHECK_NE(type, SEQUENCE); | |
19 value_.value = value; | |
20 } | |
21 | |
22 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( | |
23 Type type, | |
24 size_t size, | |
25 Sequence* sequence) | |
26 : type_(type), size_(size) { | |
27 CHECK_EQ(type, SEQUENCE); | |
xiyuan
2016/06/22 15:53:05
Since SEQUENCE is the only allowed type, why not o
rkc
2016/06/22 21:06:36
Makes sense.
Done.
| |
28 CHECK_EQ(sequence->size(), size); | |
xiyuan
2016/06/22 15:53:05
Same here. It seems we can init |size_| with seque
rkc
2016/06/22 21:06:36
Done.
| |
29 this->value_.sequence = sequence; | |
30 } | |
31 | |
32 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( | |
33 const BluetoothServiceAttributeValueBlueZ& attribute) { | |
34 this->type_ = attribute.type_; | |
35 this->size_ = attribute.size_; | |
36 | |
37 if (attribute.type_ != SEQUENCE) { | |
38 this->value_.value = attribute.value_.value->DeepCopy(); | |
39 return; | |
40 } | |
41 | |
42 this->value_.sequence = | |
43 new std::vector<BluetoothServiceAttributeValueBlueZ>(); | |
44 for (const auto& v : *attribute.value_.sequence) | |
xiyuan
2016/06/22 15:53:05
Can we do:
this->value_.sequence = new std::vec
rkc
2016/06/22 21:06:36
Done.
| |
45 this->value_.sequence->push_back(v); | |
46 } | |
47 | |
48 BluetoothServiceAttributeValueBlueZ::~BluetoothServiceAttributeValueBlueZ() { | |
49 // value_ is a union of two pointers, so we can check either. | |
50 if (!value_.value) | |
51 return; | |
52 | |
53 if (type_ == SEQUENCE) { | |
54 delete value_.sequence; | |
55 } else { | |
56 delete value_.value; | |
57 } | |
58 } | |
59 | |
60 } // namespace bluez | |
OLD | NEW |