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

Side by Side Diff: base/values.cc

Issue 13358: Revert "Added std::string to Value via Set/GetString overloading." (Closed)
Patch Set: Removed file. Created 12 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/logging.h" 5 #include "base/logging.h"
6 #include "base/string_util.h"
7 #include "base/values.h" 6 #include "base/values.h"
8 7
9 ///////////////////// Value //////////////////// 8 ///////////////////// Value ////////////////////
10 9
11 Value::~Value() { 10 Value::~Value() {
12 } 11 }
13 12
14 // static 13 // static
15 Value* Value::CreateNullValue() { 14 Value* Value::CreateNullValue() {
16 return new Value(TYPE_NULL); 15 return new Value(TYPE_NULL);
17 } 16 }
18 17
19 // static 18 // static
20 Value* Value::CreateBooleanValue(bool in_value) { 19 Value* Value::CreateBooleanValue(bool in_value) {
21 return new FundamentalValue(in_value); 20 return new FundamentalValue(in_value);
22 } 21 }
23 22
24 // static 23 // static
25 Value* Value::CreateIntegerValue(int in_value) { 24 Value* Value::CreateIntegerValue(int in_value) {
26 return new FundamentalValue(in_value); 25 return new FundamentalValue(in_value);
27 } 26 }
28 27
29 // static 28 // static
30 Value* Value::CreateRealValue(double in_value) { 29 Value* Value::CreateRealValue(double in_value) {
31 return new FundamentalValue(in_value); 30 return new FundamentalValue(in_value);
32 } 31 }
33 32
34 // static 33 // static
35 Value* Value::CreateStringValue(const std::string& in_value) { 34 Value* Value::CreateStringValue(const std::wstring& in_value) {
36 return new StringValue(in_value); 35 return new StringValue(in_value);
37 } 36 }
38 37
39 // static 38 // static
40 Value* Value::CreateStringValue(const std::wstring& in_value) {
41 return new StringValue(WideToUTF8(in_value));
42 }
43
44 // static
45 BinaryValue* Value::CreateBinaryValue(char* buffer, size_t size) { 39 BinaryValue* Value::CreateBinaryValue(char* buffer, size_t size) {
46 return BinaryValue::Create(buffer, size); 40 return BinaryValue::Create(buffer, size);
47 } 41 }
48 42
49 bool Value::GetAsBoolean(bool* in_value) const { 43 bool Value::GetAsBoolean(bool* in_value) const {
50 return false; 44 return false;
51 } 45 }
52 46
53 bool Value::GetAsInteger(int* in_value) const { 47 bool Value::GetAsInteger(int* in_value) const {
54 return false; 48 return false;
55 } 49 }
56 50
57 bool Value::GetAsReal(double* in_value) const { 51 bool Value::GetAsReal(double* in_value) const {
58 return false; 52 return false;
59 } 53 }
60 54
61 bool Value::GetAsString(std::string* in_value) const {
62 return false;
63 }
64
65 bool Value::GetAsString(std::wstring* in_value) const { 55 bool Value::GetAsString(std::wstring* in_value) const {
66 return false; 56 return false;
67 } 57 }
68 58
69 Value* Value::DeepCopy() const { 59 Value* Value::DeepCopy() const {
70 // This method should only be getting called for null Values--all subclasses 60 // This method should only be getting called for null Values--all subclasses
71 // need to provide their own implementation;. 61 // need to provide their own implementation;.
72 DCHECK(IsType(TYPE_NULL)); 62 DCHECK(IsType(TYPE_NULL));
73 return CreateNullValue(); 63 return CreateNullValue();
74 } 64 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return GetAsReal(&lhs) && other->GetAsReal(&rhs) && lhs == rhs; 128 return GetAsReal(&lhs) && other->GetAsReal(&rhs) && lhs == rhs;
139 } 129 }
140 default: 130 default:
141 NOTREACHED(); 131 NOTREACHED();
142 return false; 132 return false;
143 } 133 }
144 } 134 }
145 135
146 ///////////////////// StringValue //////////////////// 136 ///////////////////// StringValue ////////////////////
147 137
148 StringValue::StringValue(const std::string& in_value)
149 : Value(TYPE_STRING),
150 value_(in_value) {
151 DCHECK(IsStringUTF8(in_value));
152 }
153
154 StringValue::~StringValue() { 138 StringValue::~StringValue() {
155 } 139 }
156 140
157 bool StringValue::GetAsString(std::string* out_value) const { 141 bool StringValue::GetAsString(std::wstring* out_value) const {
158 if (out_value) 142 if (out_value)
159 *out_value = value_; 143 *out_value = value_;
160 return true; 144 return true;
161 } 145 }
162 146
163 bool StringValue::GetAsString(std::wstring* out_value) const {
164 if (out_value)
165 *out_value = UTF8ToWide(value_);
166 return true;
167 }
168
169 Value* StringValue::DeepCopy() const { 147 Value* StringValue::DeepCopy() const {
170 return CreateStringValue(value_); 148 return CreateStringValue(value_);
171 } 149 }
172 150
173 bool StringValue::Equals(const Value* other) const { 151 bool StringValue::Equals(const Value* other) const {
174 if (other->GetType() != GetType()) 152 if (other->GetType() != GetType())
175 return false; 153 return false;
176 std::string lhs, rhs; 154 std::wstring lhs, rhs;
177 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; 155 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs;
178 } 156 }
179 157
180 ///////////////////// BinaryValue //////////////////// 158 ///////////////////// BinaryValue ////////////////////
181 159
182 //static 160 //static
183 BinaryValue* BinaryValue::Create(char* buffer, size_t size) { 161 BinaryValue* BinaryValue::Create(char* buffer, size_t size) {
184 if (!buffer) 162 if (!buffer)
185 return NULL; 163 return NULL;
186 164
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 269
292 bool DictionaryValue::SetInteger(const std::wstring& path, int in_value) { 270 bool DictionaryValue::SetInteger(const std::wstring& path, int in_value) {
293 return Set(path, CreateIntegerValue(in_value)); 271 return Set(path, CreateIntegerValue(in_value));
294 } 272 }
295 273
296 bool DictionaryValue::SetReal(const std::wstring& path, double in_value) { 274 bool DictionaryValue::SetReal(const std::wstring& path, double in_value) {
297 return Set(path, CreateRealValue(in_value)); 275 return Set(path, CreateRealValue(in_value));
298 } 276 }
299 277
300 bool DictionaryValue::SetString(const std::wstring& path, 278 bool DictionaryValue::SetString(const std::wstring& path,
301 const std::string& in_value) {
302 return Set(path, CreateStringValue(in_value));
303 }
304
305 bool DictionaryValue::SetString(const std::wstring& path,
306 const std::wstring& in_value) { 279 const std::wstring& in_value) {
307 return Set(path, CreateStringValue(in_value)); 280 return Set(path, CreateStringValue(in_value));
308 } 281 }
309 282
310 bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const { 283 bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const {
311 std::wstring key = path; 284 std::wstring key = path;
312 285
313 size_t delimiter_position = path.find_first_of(L".", 0); 286 size_t delimiter_position = path.find_first_of(L".", 0);
314 if (delimiter_position != std::wstring::npos) { 287 if (delimiter_position != std::wstring::npos) {
315 key = path.substr(0, delimiter_position); 288 key = path.substr(0, delimiter_position);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 bool DictionaryValue::GetReal(const std::wstring& path, 328 bool DictionaryValue::GetReal(const std::wstring& path,
356 double* out_value) const { 329 double* out_value) const {
357 Value* value; 330 Value* value;
358 if (!Get(path, &value)) 331 if (!Get(path, &value))
359 return false; 332 return false;
360 333
361 return value->GetAsReal(out_value); 334 return value->GetAsReal(out_value);
362 } 335 }
363 336
364 bool DictionaryValue::GetString(const std::wstring& path, 337 bool DictionaryValue::GetString(const std::wstring& path,
365 std::string* out_value) const {
366 Value* value;
367 if (!Get(path, &value))
368 return false;
369
370 return value->GetAsString(out_value);
371 }
372
373 bool DictionaryValue::GetString(const std::wstring& path,
374 std::wstring* out_value) const { 338 std::wstring* out_value) const {
375 Value* value; 339 Value* value;
376 if (!Get(path, &value)) 340 if (!Get(path, &value))
377 return false; 341 return false;
378 342
379 return value->GetAsString(out_value); 343 return value->GetAsString(out_value);
380 } 344 }
381 345
382 bool DictionaryValue::GetBinary(const std::wstring& path, 346 bool DictionaryValue::GetBinary(const std::wstring& path,
383 BinaryValue** out_value) const { 347 BinaryValue** out_value) const {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 ++lhs_it, ++rhs_it) { 549 ++lhs_it, ++rhs_it) {
586 if (!(*lhs_it)->Equals(*rhs_it)) 550 if (!(*lhs_it)->Equals(*rhs_it))
587 return false; 551 return false;
588 } 552 }
589 if (lhs_it != end() || rhs_it != other_list->end()) 553 if (lhs_it != end() || rhs_it != other_list->end())
590 return false; 554 return false;
591 555
592 return true; 556 return true;
593 } 557 }
594 558
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