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

Side by Side Diff: base/values.cc

Issue 2799093006: Remove base::BinaryValue (Closed)
Patch Set: Rebase Created 3 years, 8 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') | 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 static_cast<const DictionaryValue&>(node)); 69 static_cast<const DictionaryValue&>(node));
70 70
71 default: 71 default:
72 return MakeUnique<Value>(node); 72 return MakeUnique<Value>(node);
73 } 73 }
74 } 74 }
75 75
76 } // namespace 76 } // namespace
77 77
78 // static 78 // static
79 std::unique_ptr<BinaryValue> BinaryValue::CreateWithCopiedBuffer( 79 std::unique_ptr<Value> Value::CreateWithCopiedBuffer(const char* buffer,
80 const char* buffer, 80 size_t size) {
81 size_t size) { 81 return MakeUnique<Value>(std::vector<char>(buffer, buffer + size));
82 return MakeUnique<BinaryValue>(std::vector<char>(buffer, buffer + size));
83 } 82 }
84 83
85 Value::Value(const Value& that) { 84 Value::Value(const Value& that) {
86 InternalCopyConstructFrom(that); 85 InternalCopyConstructFrom(that);
87 } 86 }
88 87
89 Value::Value(Value&& that) noexcept { 88 Value::Value(Value&& that) noexcept {
90 InternalMoveConstructFrom(std::move(that)); 89 InternalMoveConstructFrom(std::move(that));
91 } 90 }
92 91
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 290 }
292 291
293 bool Value::GetAsString(StringPiece* out_value) const { 292 bool Value::GetAsString(StringPiece* out_value) const {
294 if (out_value && is_string()) { 293 if (out_value && is_string()) {
295 *out_value = *string_value_; 294 *out_value = *string_value_;
296 return true; 295 return true;
297 } 296 }
298 return is_string(); 297 return is_string();
299 } 298 }
300 299
301 bool Value::GetAsBinary(const BinaryValue** out_value) const { 300 bool Value::GetAsBinary(const Value** out_value) const {
302 if (out_value && is_blob()) { 301 if (out_value && is_blob()) {
303 *out_value = this; 302 *out_value = this;
304 return true; 303 return true;
305 } 304 }
306 return is_blob(); 305 return is_blob();
307 } 306 }
308 307
309 bool Value::GetAsList(ListValue** out_value) { 308 bool Value::GetAsList(ListValue** out_value) {
310 if (out_value && is_list()) { 309 if (out_value && is_list()) {
311 *out_value = static_cast<ListValue*>(this); 310 *out_value = static_cast<ListValue*>(this);
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 if (!IsStringASCII(out)) { 787 if (!IsStringASCII(out)) {
789 NOTREACHED(); 788 NOTREACHED();
790 return false; 789 return false;
791 } 790 }
792 791
793 out_value->assign(out); 792 out_value->assign(out);
794 return true; 793 return true;
795 } 794 }
796 795
797 bool DictionaryValue::GetBinary(StringPiece path, 796 bool DictionaryValue::GetBinary(StringPiece path,
798 const BinaryValue** out_value) const { 797 const Value** out_value) const {
799 const Value* value; 798 const Value* value;
800 bool result = Get(path, &value); 799 bool result = Get(path, &value);
801 if (!result || !value->IsType(Type::BINARY)) 800 if (!result || !value->IsType(Type::BINARY))
802 return false; 801 return false;
803 802
804 if (out_value) 803 if (out_value)
805 *out_value = value; 804 *out_value = value;
806 805
807 return true; 806 return true;
808 } 807 }
809 808
810 bool DictionaryValue::GetBinary(StringPiece path, BinaryValue** out_value) { 809 bool DictionaryValue::GetBinary(StringPiece path, Value** out_value) {
811 return static_cast<const DictionaryValue&>(*this).GetBinary( 810 return static_cast<const DictionaryValue&>(*this).GetBinary(
812 path, 811 path, const_cast<const Value**>(out_value));
813 const_cast<const BinaryValue**>(out_value));
814 } 812 }
815 813
816 bool DictionaryValue::GetDictionary(StringPiece path, 814 bool DictionaryValue::GetDictionary(StringPiece path,
817 const DictionaryValue** out_value) const { 815 const DictionaryValue** out_value) const {
818 const Value* value; 816 const Value* value;
819 bool result = Get(path, &value); 817 bool result = Get(path, &value);
820 if (!result || !value->IsType(Type::DICTIONARY)) 818 if (!result || !value->IsType(Type::DICTIONARY))
821 return false; 819 return false;
822 820
823 if (out_value) 821 if (out_value)
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 } 1147 }
1150 1148
1151 bool ListValue::GetString(size_t index, string16* out_value) const { 1149 bool ListValue::GetString(size_t index, string16* out_value) const {
1152 const Value* value; 1150 const Value* value;
1153 if (!Get(index, &value)) 1151 if (!Get(index, &value))
1154 return false; 1152 return false;
1155 1153
1156 return value->GetAsString(out_value); 1154 return value->GetAsString(out_value);
1157 } 1155 }
1158 1156
1159 bool ListValue::GetBinary(size_t index, const BinaryValue** out_value) const { 1157 bool ListValue::GetBinary(size_t index, const Value** out_value) const {
1160 const Value* value; 1158 const Value* value;
1161 bool result = Get(index, &value); 1159 bool result = Get(index, &value);
1162 if (!result || !value->IsType(Type::BINARY)) 1160 if (!result || !value->IsType(Type::BINARY))
1163 return false; 1161 return false;
1164 1162
1165 if (out_value) 1163 if (out_value)
1166 *out_value = value; 1164 *out_value = value;
1167 1165
1168 return true; 1166 return true;
1169 } 1167 }
1170 1168
1171 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) { 1169 bool ListValue::GetBinary(size_t index, Value** out_value) {
1172 return static_cast<const ListValue&>(*this).GetBinary( 1170 return static_cast<const ListValue&>(*this).GetBinary(
1173 index, 1171 index, const_cast<const Value**>(out_value));
1174 const_cast<const BinaryValue**>(out_value));
1175 } 1172 }
1176 1173
1177 bool ListValue::GetDictionary(size_t index, 1174 bool ListValue::GetDictionary(size_t index,
1178 const DictionaryValue** out_value) const { 1175 const DictionaryValue** out_value) const {
1179 const Value* value; 1176 const Value* value;
1180 bool result = Get(index, &value); 1177 bool result = Get(index, &value);
1181 if (!result || !value->IsType(Type::DICTIONARY)) 1178 if (!result || !value->IsType(Type::DICTIONARY))
1182 return false; 1179 return false;
1183 1180
1184 if (out_value) 1181 if (out_value)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 } 1338 }
1342 1339
1343 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { 1340 std::ostream& operator<<(std::ostream& out, const Value::Type& type) {
1344 if (static_cast<int>(type) < 0 || 1341 if (static_cast<int>(type) < 0 ||
1345 static_cast<size_t>(type) >= arraysize(kTypeNames)) 1342 static_cast<size_t>(type) >= arraysize(kTypeNames))
1346 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; 1343 return out << "Invalid Type (index = " << static_cast<int>(type) << ")";
1347 return out << Value::GetTypeName(type); 1344 return out << Value::GetTypeName(type);
1348 } 1345 }
1349 1346
1350 } // namespace base 1347 } // 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