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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 InternalCleanup(); | 193 InternalCleanup(); |
194 InternalMoveConstructFrom(std::move(that)); | 194 InternalMoveConstructFrom(std::move(that)); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 return *this; | 198 return *this; |
199 } | 199 } |
200 | 200 |
201 Value::~Value() { | 201 Value::~Value() { |
202 InternalCleanup(); | 202 InternalCleanup(); |
203 alive_ = false; | |
204 } | 203 } |
205 | 204 |
206 // static | 205 // static |
207 const char* Value::GetTypeName(Value::Type type) { | 206 const char* Value::GetTypeName(Value::Type type) { |
208 DCHECK_GE(static_cast<int>(type), 0); | 207 DCHECK_GE(static_cast<int>(type), 0); |
209 DCHECK_LT(static_cast<size_t>(type), arraysize(kTypeNames)); | 208 DCHECK_LT(static_cast<size_t>(type), arraysize(kTypeNames)); |
210 return kTypeNames[static_cast<size_t>(type)]; | 209 return kTypeNames[static_cast<size_t>(type)]; |
211 } | 210 } |
212 | 211 |
213 bool Value::GetBool() const { | 212 bool Value::GetBool() const { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 case Type::DICTIONARY: | 582 case Type::DICTIONARY: |
584 *dict_ptr_ = std::move(*that.dict_ptr_); | 583 *dict_ptr_ = std::move(*that.dict_ptr_); |
585 return; | 584 return; |
586 case Type::LIST: | 585 case Type::LIST: |
587 *list_ = std::move(*that.list_); | 586 *list_ = std::move(*that.list_); |
588 return; | 587 return; |
589 } | 588 } |
590 } | 589 } |
591 | 590 |
592 void Value::InternalCleanup() { | 591 void Value::InternalCleanup() { |
593 CHECK(alive_); | |
594 | |
595 switch (type_) { | 592 switch (type_) { |
596 case Type::NONE: | 593 case Type::NONE: |
597 case Type::BOOLEAN: | 594 case Type::BOOLEAN: |
598 case Type::INTEGER: | 595 case Type::INTEGER: |
599 case Type::DOUBLE: | 596 case Type::DOUBLE: |
600 // Nothing to do | 597 // Nothing to do |
601 return; | 598 return; |
602 | 599 |
603 case Type::STRING: | 600 case Type::STRING: |
604 string_value_.Destroy(); | 601 string_value_.Destroy(); |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1355 } |
1359 | 1356 |
1360 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { | 1357 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { |
1361 if (static_cast<int>(type) < 0 || | 1358 if (static_cast<int>(type) < 0 || |
1362 static_cast<size_t>(type) >= arraysize(kTypeNames)) | 1359 static_cast<size_t>(type) >= arraysize(kTypeNames)) |
1363 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; | 1360 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; |
1364 return out << Value::GetTypeName(type); | 1361 return out << Value::GetTypeName(type); |
1365 } | 1362 } |
1366 | 1363 |
1367 } // namespace base | 1364 } // namespace base |
OLD | NEW |