OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 } | 1074 } |
1075 } | 1075 } |
1076 | 1076 |
1077 void ListValue::AppendStrings(const std::vector<string16>& in_values) { | 1077 void ListValue::AppendStrings(const std::vector<string16>& in_values) { |
1078 for (std::vector<string16>::const_iterator it = in_values.begin(); | 1078 for (std::vector<string16>::const_iterator it = in_values.begin(); |
1079 it != in_values.end(); ++it) { | 1079 it != in_values.end(); ++it) { |
1080 AppendString(*it); | 1080 AppendString(*it); |
1081 } | 1081 } |
1082 } | 1082 } |
1083 | 1083 |
1084 bool ListValue::AppendIfNotPresent(Value* in_value) { | 1084 bool ListValue::AppendIfNotPresent(std::unique_ptr<Value> in_value) { |
1085 DCHECK(in_value); | 1085 DCHECK(in_value); |
1086 for (const auto& entry : list_) { | 1086 for (const auto& entry : list_) { |
1087 if (entry->Equals(in_value)) { | 1087 if (entry->Equals(in_value.get())) { |
1088 delete in_value; | |
1089 return false; | 1088 return false; |
1090 } | 1089 } |
1091 } | 1090 } |
1092 list_.emplace_back(in_value); | 1091 list_.emplace_back(std::move(in_value)); |
danakj
2016/09/13 23:58:37
push back? you have the type going into the list a
dcheng
2016/09/14 01:16:51
Done.
| |
1093 return true; | 1092 return true; |
1094 } | 1093 } |
1095 | 1094 |
1096 bool ListValue::Insert(size_t index, Value* in_value) { | 1095 bool ListValue::Insert(size_t index, std::unique_ptr<Value> in_value) { |
1097 DCHECK(in_value); | 1096 DCHECK(in_value); |
1098 if (index > list_.size()) | 1097 if (index > list_.size()) |
1099 return false; | 1098 return false; |
1100 | 1099 |
1101 list_.insert(list_.begin() + index, WrapUnique(in_value)); | 1100 list_.insert(list_.begin() + index, std::move(in_value)); |
1102 return true; | 1101 return true; |
1103 } | 1102 } |
1104 | 1103 |
1105 ListValue::const_iterator ListValue::Find(const Value& value) const { | 1104 ListValue::const_iterator ListValue::Find(const Value& value) const { |
1106 return std::find_if(list_.begin(), list_.end(), | 1105 return std::find_if(list_.begin(), list_.end(), |
1107 [&value](const std::unique_ptr<Value>& entry) { | 1106 [&value](const std::unique_ptr<Value>& entry) { |
1108 return entry->Equals(&value); | 1107 return entry->Equals(&value); |
1109 }); | 1108 }); |
1110 } | 1109 } |
1111 | 1110 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 ValueDeserializer::~ValueDeserializer() { | 1162 ValueDeserializer::~ValueDeserializer() { |
1164 } | 1163 } |
1165 | 1164 |
1166 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1165 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1167 std::string json; | 1166 std::string json; |
1168 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 1167 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
1169 return out << json; | 1168 return out << json; |
1170 } | 1169 } |
1171 | 1170 |
1172 } // namespace base | 1171 } // namespace base |
OLD | NEW |