| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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<Value> Value::CreateWithCopiedBuffer(const char* buffer, | 79 std::unique_ptr<Value> Value::CreateWithCopiedBuffer(const char* buffer, |
| 80 size_t size) { | 80 size_t size) { |
| 81 return MakeUnique<Value>(std::vector<char>(buffer, buffer + size)); | 81 return MakeUnique<Value>(BlobStorage(buffer, buffer + size)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 Value::Value(const Value& that) { | 84 Value::Value(const Value& that) { |
| 85 InternalCopyConstructFrom(that); | 85 InternalCopyConstructFrom(that); |
| 86 } | 86 } |
| 87 | 87 |
| 88 Value::Value(Value&& that) noexcept { | 88 Value::Value(Value&& that) noexcept { |
| 89 InternalMoveConstructFrom(std::move(that)); | 89 InternalMoveConstructFrom(std::move(that)); |
| 90 } | 90 } |
| 91 | 91 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 Value::Value(const char16* in_string) : type_(Type::STRING) { | 151 Value::Value(const char16* in_string) : type_(Type::STRING) { |
| 152 string_value_.Init(UTF16ToUTF8(in_string)); | 152 string_value_.Init(UTF16ToUTF8(in_string)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 Value::Value(const string16& in_string) : type_(Type::STRING) { | 155 Value::Value(const string16& in_string) : type_(Type::STRING) { |
| 156 string_value_.Init(UTF16ToUTF8(in_string)); | 156 string_value_.Init(UTF16ToUTF8(in_string)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 Value::Value(StringPiece in_string) : Value(in_string.as_string()) {} | 159 Value::Value(StringPiece in_string) : Value(in_string.as_string()) {} |
| 160 | 160 |
| 161 Value::Value(const std::vector<char>& in_blob) : type_(Type::BINARY) { | 161 Value::Value(const BlobStorage& in_blob) : type_(Type::BINARY) { |
| 162 binary_value_.Init(in_blob); | 162 binary_value_.Init(in_blob); |
| 163 } | 163 } |
| 164 | 164 |
| 165 Value::Value(std::vector<char>&& in_blob) noexcept : type_(Type::BINARY) { | 165 Value::Value(BlobStorage&& in_blob) noexcept : type_(Type::BINARY) { |
| 166 binary_value_.Init(std::move(in_blob)); | 166 binary_value_.Init(std::move(in_blob)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 Value::Value(DictStorage&& in_dict) noexcept : type_(Type::DICTIONARY) { | 169 Value::Value(DictStorage&& in_dict) noexcept : type_(Type::DICTIONARY) { |
| 170 dict_.Init(std::move(in_dict)); | 170 dict_.Init(std::move(in_dict)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 Value& Value::operator=(const Value& that) { | 173 Value& Value::operator=(const Value& that) { |
| 174 if (type_ == that.type_) { | 174 if (type_ == that.type_) { |
| 175 InternalCopyAssignFromSameType(that); | 175 InternalCopyAssignFromSameType(that); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 return int_value_; | 217 return int_value_; |
| 218 CHECK(false); | 218 CHECK(false); |
| 219 return 0.0; | 219 return 0.0; |
| 220 } | 220 } |
| 221 | 221 |
| 222 const std::string& Value::GetString() const { | 222 const std::string& Value::GetString() const { |
| 223 CHECK(is_string()); | 223 CHECK(is_string()); |
| 224 return *string_value_; | 224 return *string_value_; |
| 225 } | 225 } |
| 226 | 226 |
| 227 const std::vector<char>& Value::GetBlob() const { | 227 const Value::BlobStorage& Value::GetBlob() const { |
| 228 CHECK(is_blob()); | 228 CHECK(is_blob()); |
| 229 return *binary_value_; | 229 return *binary_value_; |
| 230 } | 230 } |
| 231 | 231 |
| 232 size_t Value::GetSize() const { | 232 size_t Value::GetSize() const { |
| 233 return GetBlob().size(); | 233 return GetBlob().size(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 const char* Value::GetBuffer() const { | 236 const char* Value::GetBuffer() const { |
| 237 return GetBlob().data(); | 237 return GetBlob().data(); |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { | 1317 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { |
| 1318 if (static_cast<int>(type) < 0 || | 1318 if (static_cast<int>(type) < 0 || |
| 1319 static_cast<size_t>(type) >= arraysize(kTypeNames)) | 1319 static_cast<size_t>(type) >= arraysize(kTypeNames)) |
| 1320 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; | 1320 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; |
| 1321 return out << Value::GetTypeName(type); | 1321 return out << Value::GetTypeName(type); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 } // namespace base | 1324 } // namespace base |
| OLD | NEW |