Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: base/values.cc

Issue 2336863003: Change more base::ListValue methods to use std::unique_ptr. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/values.h ('k') | chrome/browser/chromeos/extensions/users_private/users_private_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_.push_back(std::move(in_value));
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
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
OLDNEW
« no previous file with comments | « base/values.h ('k') | chrome/browser/chromeos/extensions/users_private/users_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698