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

Unified Diff: base/values.cc

Issue 254473002: Add support for int64 and uint64 in values.h's API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test compile Created 6 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 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 f27c09567eee61c55aafa398d9302a7bd8faeeac..85e4e4dbd9494fd9be4bec3f7dde642e97cdb3b0 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -13,6 +13,7 @@
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/move.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -138,6 +139,14 @@ bool Value::GetAsString(const StringValue** out_value) const {
return false;
}
+bool Value::GetAsInt64(int64* out_value) const {
+ return false;
+}
+
+bool Value::GetAsUint64(uint64* out_value) const {
+ return false;
+}
+
bool Value::GetAsList(ListValue** out_value) {
return false;
}
@@ -279,6 +288,14 @@ StringValue::StringValue(const string16& in_value)
value_(UTF16ToUTF8(in_value)) {
}
+StringValue::StringValue(int64 in_value)
+ : Value(TYPE_STRING), value_(Int64ToString(in_value)) {
+}
+
+StringValue::StringValue(uint64 in_value)
+ : Value(TYPE_STRING), value_(Uint64ToString(in_value)) {
+}
+
StringValue::~StringValue() {
}
@@ -308,6 +325,22 @@ bool StringValue::GetAsString(const StringValue** out_value) const {
return true;
}
+bool StringValue::GetAsInt64(int64* out_value) const {
+ int64 stored_value;
+ bool valid = StringToInt64(value_, &stored_value);
+ if (valid && out_value)
+ *out_value = stored_value;
+ return valid;
+}
+
+bool StringValue::GetAsUint64(uint64* out_value) const {
+ uint64 stored_value;
+ bool valid = base::StringToUint64(value_, &stored_value);
+ if (valid && out_value)
+ *out_value = stored_value;
+ return valid;
+}
+
StringValue* StringValue::DeepCopy() const {
return new StringValue(value_);
}
@@ -442,6 +475,14 @@ void DictionaryValue::SetString(const std::string& path,
Set(path, new StringValue(in_value));
}
+void DictionaryValue::SetInt64(const std::string& path, int64 in_value) {
+ Set(path, new StringValue(in_value));
+}
+
+void DictionaryValue::SetUint64(const std::string& path, uint64 in_value) {
+ Set(path, new StringValue(in_value));
+}
+
void DictionaryValue::SetWithoutPathExpansion(const std::string& key,
Value* in_value) {
// If there's an existing value here, we need to delete it, because
@@ -480,6 +521,16 @@ void DictionaryValue::SetStringWithoutPathExpansion(
SetWithoutPathExpansion(path, new StringValue(in_value));
}
+void DictionaryValue::SetInt64WithoutPathExpansion(const std::string& path,
+ int64 in_value) {
+ SetWithoutPathExpansion(path, new StringValue(in_value));
+}
+
+void DictionaryValue::SetUint64WithoutPathExpansion(const std::string& path,
+ uint64 in_value) {
+ SetWithoutPathExpansion(path, new StringValue(in_value));
+}
+
bool DictionaryValue::Get(const std::string& path,
const Value** out_value) const {
DCHECK(IsStringUTF8(path));
@@ -551,6 +602,24 @@ bool DictionaryValue::GetString(const std::string& path,
return value->GetAsString(out_value);
}
+bool DictionaryValue::GetInt64(const std::string& path,
+ int64* out_value) const {
+ const Value* value;
+ if (!Get(path, &value))
+ return false;
+
+ return value->GetAsInt64(out_value);
+}
+
+bool DictionaryValue::GetUint64(const std::string& path,
+ uint64* out_value) const {
+ const Value* value;
+ if (!Get(path, &value))
+ return false;
+
+ return value->GetAsUint64(out_value);
+}
+
bool DictionaryValue::GetStringASCII(const std::string& path,
std::string* out_value) const {
std::string out;
@@ -691,6 +760,24 @@ bool DictionaryValue::GetStringWithoutPathExpansion(const std::string& key,
return value->GetAsString(out_value);
}
+bool DictionaryValue::GetInt64WithoutPathExpansion(const std::string& key,
+ int64* out_value) const {
+ const Value* value;
+ if (!GetWithoutPathExpansion(key, &value))
+ return false;
+
+ return value->GetAsInt64(out_value);
+}
+
+bool DictionaryValue::GetUint64WithoutPathExpansion(const std::string& key,
+ uint64* out_value) const {
+ const Value* value;
+ if (!GetWithoutPathExpansion(key, &value))
+ return false;
+
+ return value->GetAsUint64(out_value);
+}
+
bool DictionaryValue::GetDictionaryWithoutPathExpansion(
const std::string& key,
const DictionaryValue** out_value) const {
@@ -944,6 +1031,22 @@ bool ListValue::GetString(size_t index, string16* out_value) const {
return value->GetAsString(out_value);
}
+bool ListValue::GetInt64(size_t index, int64* out_value) const {
+ const Value* value;
+ if (!Get(index, &value))
+ return false;
+
+ return value->GetAsInt64(out_value);
+}
+
+bool ListValue::GetUint64(size_t index, uint64* out_value) const {
+ const Value* value;
+ if (!Get(index, &value))
+ return false;
+
+ return value->GetAsUint64(out_value);
+}
+
bool ListValue::GetBinary(size_t index, const BinaryValue** out_value) const {
const Value* value;
bool result = Get(index, &value);
@@ -1062,6 +1165,14 @@ void ListValue::AppendString(const string16& in_value) {
Append(new StringValue(in_value));
}
+void ListValue::AppendInt64(int64 in_value) {
+ Append(new StringValue(in_value));
+}
+
+void ListValue::AppendUint64(uint64 in_value) {
+ Append(new StringValue(in_value));
+}
+
void ListValue::AppendStrings(const std::vector<std::string>& in_values) {
for (std::vector<std::string>::const_iterator it = in_values.begin();
it != in_values.end(); ++it) {
« 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