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

Side by Side Diff: base/values.cc

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month 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') | base/values_unittest.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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 bool Value::GetAsDictionary(const DictionaryValue** out_value) const { 181 bool Value::GetAsDictionary(const DictionaryValue** out_value) const {
182 return false; 182 return false;
183 } 183 }
184 184
185 Value* Value::DeepCopy() const { 185 Value* Value::DeepCopy() const {
186 // This method should only be getting called for null Values--all subclasses 186 // This method should only be getting called for null Values--all subclasses
187 // need to provide their own implementation;. 187 // need to provide their own implementation;.
188 switch (type()) { 188 switch (type()) {
189 case TYPE_NULL: 189 case TYPE_NULL:
190 return CreateNullValue().release(); 190 return CreateNullValue().release();
191
192 // For now, make FundamentalValues for backward-compatibility. Convert to
193 // Value when that code is deleted.
194 case TYPE_BOOLEAN: 191 case TYPE_BOOLEAN:
195 return new FundamentalValue(bool_value_); 192 return new Value(bool_value_);
196 case TYPE_INTEGER: 193 case TYPE_INTEGER:
197 return new FundamentalValue(int_value_); 194 return new Value(int_value_);
198 case TYPE_DOUBLE: 195 case TYPE_DOUBLE:
199 return new FundamentalValue(double_value_); 196 return new Value(double_value_);
200 197
201 default: 198 default:
202 // All other types should be handled by subclasses. 199 // All other types should be handled by subclasses.
203 NOTREACHED(); 200 NOTREACHED();
204 return nullptr; 201 return nullptr;
205 } 202 }
206 } 203 }
207 204
208 std::unique_ptr<Value> Value::CreateDeepCopy() const { 205 std::unique_ptr<Value> Value::CreateDeepCopy() const {
209 return WrapUnique(DeepCopy()); 206 return WrapUnique(DeepCopy());
(...skipping 29 matching lines...) Expand all
239 236
240 Value::Value(Type type) : type_(type) {} 237 Value::Value(Type type) : type_(type) {}
241 238
242 Value::Value(const Value& that) : type_(that.type_) {} 239 Value::Value(const Value& that) : type_(that.type_) {}
243 240
244 Value& Value::operator=(const Value& that) { 241 Value& Value::operator=(const Value& that) {
245 type_ = that.type_; 242 type_ = that.type_;
246 return *this; 243 return *this;
247 } 244 }
248 245
249 ///////////////////// FundamentalValue ////////////////////
250
251 FundamentalValue::FundamentalValue(bool in_value)
252 : Value(in_value) {
253 }
254
255 FundamentalValue::FundamentalValue(int in_value)
256 : Value(in_value) {
257 }
258
259 FundamentalValue::FundamentalValue(double in_value)
260 : Value(in_value) {
261 }
262
263 FundamentalValue::~FundamentalValue() {
264 }
265
266 ///////////////////// StringValue //////////////////// 246 ///////////////////// StringValue ////////////////////
267 247
268 StringValue::StringValue(StringPiece in_value) 248 StringValue::StringValue(StringPiece in_value)
269 : Value(TYPE_STRING), value_(in_value.as_string()) { 249 : Value(TYPE_STRING), value_(in_value.as_string()) {
270 DCHECK(IsStringUTF8(in_value)); 250 DCHECK(IsStringUTF8(in_value));
271 } 251 }
272 252
273 StringValue::StringValue(const string16& in_value) 253 StringValue::StringValue(const string16& in_value)
274 : Value(TYPE_STRING), 254 : Value(TYPE_STRING),
275 value_(UTF16ToUTF8(in_value)) { 255 value_(UTF16ToUTF8(in_value)) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 404
425 current_dictionary->SetWithoutPathExpansion(current_path, 405 current_dictionary->SetWithoutPathExpansion(current_path,
426 std::move(in_value)); 406 std::move(in_value));
427 } 407 }
428 408
429 void DictionaryValue::Set(StringPiece path, Value* in_value) { 409 void DictionaryValue::Set(StringPiece path, Value* in_value) {
430 Set(path, WrapUnique(in_value)); 410 Set(path, WrapUnique(in_value));
431 } 411 }
432 412
433 void DictionaryValue::SetBoolean(StringPiece path, bool in_value) { 413 void DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
434 Set(path, new FundamentalValue(in_value)); 414 Set(path, new Value(in_value));
435 } 415 }
436 416
437 void DictionaryValue::SetInteger(StringPiece path, int in_value) { 417 void DictionaryValue::SetInteger(StringPiece path, int in_value) {
438 Set(path, new FundamentalValue(in_value)); 418 Set(path, new Value(in_value));
439 } 419 }
440 420
441 void DictionaryValue::SetDouble(StringPiece path, double in_value) { 421 void DictionaryValue::SetDouble(StringPiece path, double in_value) {
442 Set(path, new FundamentalValue(in_value)); 422 Set(path, new Value(in_value));
443 } 423 }
444 424
445 void DictionaryValue::SetString(StringPiece path, StringPiece in_value) { 425 void DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
446 Set(path, new StringValue(in_value)); 426 Set(path, new StringValue(in_value));
447 } 427 }
448 428
449 void DictionaryValue::SetString(StringPiece path, const string16& in_value) { 429 void DictionaryValue::SetString(StringPiece path, const string16& in_value) {
450 Set(path, new StringValue(in_value)); 430 Set(path, new StringValue(in_value));
451 } 431 }
452 432
453 void DictionaryValue::SetWithoutPathExpansion(StringPiece key, 433 void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
454 std::unique_ptr<Value> in_value) { 434 std::unique_ptr<Value> in_value) {
455 dictionary_[key.as_string()] = std::move(in_value); 435 dictionary_[key.as_string()] = std::move(in_value);
456 } 436 }
457 437
458 void DictionaryValue::SetWithoutPathExpansion(StringPiece key, 438 void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
459 Value* in_value) { 439 Value* in_value) {
460 SetWithoutPathExpansion(key, WrapUnique(in_value)); 440 SetWithoutPathExpansion(key, WrapUnique(in_value));
461 } 441 }
462 442
463 void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path, 443 void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path,
464 bool in_value) { 444 bool in_value) {
465 SetWithoutPathExpansion(path, 445 SetWithoutPathExpansion(path, new Value(in_value));
466 base::MakeUnique<base::FundamentalValue>(in_value));
467 } 446 }
468 447
469 void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path, 448 void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path,
470 int in_value) { 449 int in_value) {
471 SetWithoutPathExpansion(path, 450 SetWithoutPathExpansion(path, new Value(in_value));
472 base::MakeUnique<base::FundamentalValue>(in_value));
473 } 451 }
474 452
475 void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path, 453 void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path,
476 double in_value) { 454 double in_value) {
477 SetWithoutPathExpansion(path, 455 SetWithoutPathExpansion(path, new Value(in_value));
478 base::MakeUnique<base::FundamentalValue>(in_value));
479 } 456 }
480 457
481 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, 458 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
482 StringPiece in_value) { 459 StringPiece in_value) {
483 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value)); 460 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value));
484 } 461 }
485 462
486 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path, 463 void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
487 const string16& in_value) { 464 const string16& in_value) {
488 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value)); 465 SetWithoutPathExpansion(path, base::MakeUnique<base::StringValue>(in_value));
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 } 1037 }
1061 1038
1062 #if !defined(OS_LINUX) 1039 #if !defined(OS_LINUX)
1063 void ListValue::Append(Value* in_value) { 1040 void ListValue::Append(Value* in_value) {
1064 DCHECK(in_value); 1041 DCHECK(in_value);
1065 Append(WrapUnique(in_value)); 1042 Append(WrapUnique(in_value));
1066 } 1043 }
1067 #endif 1044 #endif
1068 1045
1069 void ListValue::AppendBoolean(bool in_value) { 1046 void ListValue::AppendBoolean(bool in_value) {
1070 Append(MakeUnique<FundamentalValue>(in_value)); 1047 Append(MakeUnique<Value>(in_value));
1071 } 1048 }
1072 1049
1073 void ListValue::AppendInteger(int in_value) { 1050 void ListValue::AppendInteger(int in_value) {
1074 Append(MakeUnique<FundamentalValue>(in_value)); 1051 Append(MakeUnique<Value>(in_value));
1075 } 1052 }
1076 1053
1077 void ListValue::AppendDouble(double in_value) { 1054 void ListValue::AppendDouble(double in_value) {
1078 Append(MakeUnique<FundamentalValue>(in_value)); 1055 Append(MakeUnique<Value>(in_value));
1079 } 1056 }
1080 1057
1081 void ListValue::AppendString(StringPiece in_value) { 1058 void ListValue::AppendString(StringPiece in_value) {
1082 Append(MakeUnique<StringValue>(in_value)); 1059 Append(MakeUnique<StringValue>(in_value));
1083 } 1060 }
1084 1061
1085 void ListValue::AppendString(const string16& in_value) { 1062 void ListValue::AppendString(const string16& in_value) {
1086 Append(MakeUnique<StringValue>(in_value)); 1063 Append(MakeUnique<StringValue>(in_value));
1087 } 1064 }
1088 1065
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 ValueDeserializer::~ValueDeserializer() { 1158 ValueDeserializer::~ValueDeserializer() {
1182 } 1159 }
1183 1160
1184 std::ostream& operator<<(std::ostream& out, const Value& value) { 1161 std::ostream& operator<<(std::ostream& out, const Value& value) {
1185 std::string json; 1162 std::string json;
1186 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); 1163 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json);
1187 return out << json; 1164 return out << json;
1188 } 1165 }
1189 1166
1190 } // namespace base 1167 } // namespace base
OLDNEW
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698