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

Unified Diff: base/values.cc

Issue 8962042: Add TYPE_INTEGER64 type to base::Value. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 8d7ca351d1e9cc6db28489f822a9f341906f04b5..dca6f5e6887d921dd0305d0ec1684c23d0c9c27b 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -101,6 +101,11 @@ FundamentalValue* Value::CreateIntegerValue(int in_value) {
}
// static
+FundamentalValue* Value::CreateInteger64Value(int64 in_value) {
+ return new FundamentalValue(in_value);
+}
+
+// static
FundamentalValue* Value::CreateDoubleValue(double in_value) {
return new FundamentalValue(in_value);
}
@@ -123,6 +128,10 @@ bool Value::GetAsInteger(int* out_value) const {
return false;
}
+bool Value::GetAsInteger64(int64* out_value) const {
+ return false;
+}
+
bool Value::GetAsDouble(double* out_value) const {
return false;
}
@@ -185,6 +194,10 @@ FundamentalValue::FundamentalValue(int in_value)
: Value(TYPE_INTEGER), integer_value_(in_value) {
}
+FundamentalValue::FundamentalValue(int64 in_value)
+ : Value(TYPE_INTEGER64), integer_value_(in_value) {
+}
+
FundamentalValue::FundamentalValue(double in_value)
: Value(TYPE_DOUBLE), double_value_(in_value) {
if (!IsFinite(double_value_)) {
@@ -209,6 +222,14 @@ bool FundamentalValue::GetAsInteger(int* out_value) const {
return (IsType(TYPE_INTEGER));
}
+bool FundamentalValue::GetAsInteger64(int64* out_value) const {
+ if (out_value && IsType(TYPE_INTEGER64))
+ *out_value = integer_value_;
+ else if (out_value && IsType(TYPE_INTEGER))
+ *out_value = integer_value_;
+ return (IsType(TYPE_INTEGER64) || IsType(TYPE_INTEGER));
+}
+
bool FundamentalValue::GetAsDouble(double* out_value) const {
if (out_value && IsType(TYPE_DOUBLE))
*out_value = double_value_;
@@ -225,6 +246,9 @@ FundamentalValue* FundamentalValue::DeepCopy() const {
case TYPE_INTEGER:
return CreateIntegerValue(integer_value_);
+ case TYPE_INTEGER64:
+ return CreateInteger64Value(integer_value_);
+
case TYPE_DOUBLE:
return CreateDoubleValue(double_value_);
@@ -243,9 +267,10 @@ bool FundamentalValue::Equals(const Value* other) const {
bool lhs, rhs;
return GetAsBoolean(&lhs) && other->GetAsBoolean(&rhs) && lhs == rhs;
}
- case TYPE_INTEGER: {
- int lhs, rhs;
- return GetAsInteger(&lhs) && other->GetAsInteger(&rhs) && lhs == rhs;
+ case TYPE_INTEGER:
+ case TYPE_INTEGER64: {
+ int64 lhs, rhs;
+ return GetAsInteger64(&lhs) && other->GetAsInteger64(&rhs) && lhs == rhs;
}
case TYPE_DOUBLE: {
double lhs, rhs;
@@ -414,6 +439,10 @@ void DictionaryValue::SetInteger(const std::string& path, int in_value) {
Set(path, CreateIntegerValue(in_value));
}
+void DictionaryValue::SetInteger64(const std::string& path, int64 in_value) {
+ Set(path, CreateInteger64Value(in_value));
+}
+
void DictionaryValue::SetDouble(const std::string& path, double in_value) {
Set(path, CreateDoubleValue(in_value));
}
@@ -478,6 +507,15 @@ bool DictionaryValue::GetInteger(const std::string& path,
return value->GetAsInteger(out_value);
}
+bool DictionaryValue::GetInteger64(const std::string& path,
+ int64* out_value) const {
+ Value* value;
+ if (!Get(path, &value))
+ return false;
+
+ return value->GetAsInteger64(out_value);
+}
+
bool DictionaryValue::GetDouble(const std::string& path,
double* out_value) const {
Value* value;
@@ -581,6 +619,15 @@ bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::string& key,
return value->GetAsInteger(out_value);
}
+bool DictionaryValue::GetInteger64WithoutPathExpansion(const std::string& key,
+ int64* out_value) const {
+ Value* value;
+ if (!GetWithoutPathExpansion(key, &value))
+ return false;
+
+ return value->GetAsInteger64(out_value);
+}
+
bool DictionaryValue::GetDoubleWithoutPathExpansion(const std::string& key,
double* out_value) const {
Value* value;
@@ -790,6 +837,14 @@ bool ListValue::GetInteger(size_t index, int* out_value) const {
return value->GetAsInteger(out_value);
}
+bool ListValue::GetInteger64(size_t index, int64* out_value) const {
+ Value* value;
+ if (!Get(index, &value))
+ return false;
+
+ return value->GetAsInteger64(out_value);
+}
+
bool ListValue::GetDouble(size_t index, double* out_value) const {
Value* value;
if (!Get(index, &value))
« 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