Index: base/values.h |
diff --git a/base/values.h b/base/values.h |
index c478e3ac79e199ca4a79540ac29a59850789f632..3439687c89628548de4fd1f21071c10c8ecc7d51 100644 |
--- a/base/values.h |
+++ b/base/values.h |
@@ -92,6 +92,8 @@ class BASE_EXPORT Value { |
virtual bool GetAsString(std::string* out_value) const; |
virtual bool GetAsString(string16* out_value) const; |
virtual bool GetAsString(const StringValue** out_value) const; |
+ virtual bool GetAsInt64(int64* out_value) const; |
+ virtual bool GetAsUint64(uint64* out_value) const; |
virtual bool GetAsList(ListValue** out_value); |
virtual bool GetAsList(const ListValue** out_value) const; |
virtual bool GetAsDictionary(DictionaryValue** out_value); |
@@ -147,6 +149,14 @@ class BASE_EXPORT FundamentalValue : public Value { |
}; |
}; |
+// A Value to store strings or (u)int64s internally represented as strings. |
+// Note that while a primitive value could be used for (u)int64s, they would |
+// still have to be serialized as strings (for legacy reasons) and the parser |
+// would need to make a decision as to which type it is on read (which it can't |
+// do deterministically in the current format if we also have legitimate reasons |
+// to want to explicitly store strings representing integers). In order to avoid |
+// extra complexity, simply store (u)int64s as strings and let callers |
+// explicitly state whether they want the value as (u)int64 or as string. |
class BASE_EXPORT StringValue : public Value { |
public: |
// Initializes a StringValue with a UTF-8 narrow character string. |
@@ -155,6 +165,12 @@ class BASE_EXPORT StringValue : public Value { |
// Initializes a StringValue with a string16. |
explicit StringValue(const string16& in_value); |
+ // Initializes a StringValue with an int64. |
+ explicit StringValue(int64 in_value); |
+ |
+ // Initializes a StringValue with a uint64. |
+ explicit StringValue(uint64 in_value); |
+ |
virtual ~StringValue(); |
// Returns |value_| as a pointer or reference. |
@@ -165,6 +181,8 @@ class BASE_EXPORT StringValue : public Value { |
virtual bool GetAsString(std::string* out_value) const OVERRIDE; |
virtual bool GetAsString(string16* out_value) const OVERRIDE; |
virtual bool GetAsString(const StringValue** out_value) const OVERRIDE; |
+ virtual bool GetAsInt64(int64* out_value) const OVERRIDE; |
+ virtual bool GetAsUint64(uint64* out_value) const OVERRIDE; |
virtual StringValue* DeepCopy() const OVERRIDE; |
virtual bool Equals(const Value* other) const OVERRIDE; |
@@ -248,6 +266,12 @@ class BASE_EXPORT DictionaryValue : public Value { |
void SetDouble(const std::string& path, double in_value); |
void SetString(const std::string& path, const std::string& in_value); |
void SetString(const std::string& path, const string16& in_value); |
+ // Int64 helper methods that actually store the given value as a string. |
+ // Note that if obtaining the named value via Get, the Value type will be |
+ // TYPE_STRING. |
+ void SetInt64(const std::string& path, int64 value); |
+ // As above, but for unsigned values. |
+ void SetUint64(const std::string& path, uint64 value); |
// Like Set(), but without special treatment of '.'. This allows e.g. URLs to |
// be used as paths. |
@@ -261,6 +285,8 @@ class BASE_EXPORT DictionaryValue : public Value { |
const std::string& in_value); |
void SetStringWithoutPathExpansion(const std::string& path, |
const string16& in_value); |
+ void SetInt64WithoutPathExpansion(const std::string& path, int64 value); |
+ void SetUint64WithoutPathExpansion(const std::string& path, uint64 value); |
// Gets the Value associated with the given path starting from this object. |
// A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
@@ -285,6 +311,8 @@ class BASE_EXPORT DictionaryValue : public Value { |
bool GetString(const std::string& path, std::string* out_value) const; |
bool GetString(const std::string& path, string16* out_value) const; |
bool GetStringASCII(const std::string& path, std::string* out_value) const; |
+ bool GetInt64(const std::string& path, int64* out_value) const; |
+ bool GetUint64(const std::string& path, uint64* out_value) const; |
bool GetBinary(const std::string& path, const BinaryValue** out_value) const; |
bool GetBinary(const std::string& path, BinaryValue** out_value); |
bool GetDictionary(const std::string& path, |
@@ -308,6 +336,10 @@ class BASE_EXPORT DictionaryValue : public Value { |
std::string* out_value) const; |
bool GetStringWithoutPathExpansion(const std::string& key, |
string16* out_value) const; |
+ bool GetInt64WithoutPathExpansion(const std::string& path, |
+ int64* out_value) const; |
+ bool GetUint64WithoutPathExpansion(const std::string& path, |
+ uint64* out_value) const; |
bool GetDictionaryWithoutPathExpansion( |
const std::string& key, |
const DictionaryValue** out_value) const; |
@@ -421,6 +453,8 @@ class BASE_EXPORT ListValue : public Value { |
bool GetDouble(size_t index, double* out_value) const; |
bool GetString(size_t index, std::string* out_value) const; |
bool GetString(size_t index, string16* out_value) const; |
+ bool GetInt64(size_t index, int64* out_value) const; |
+ bool GetUint64(size_t index, uint64* out_value) const; |
bool GetBinary(size_t index, const BinaryValue** out_value) const; |
bool GetBinary(size_t index, BinaryValue** out_value); |
bool GetDictionary(size_t index, const DictionaryValue** out_value) const; |
@@ -457,6 +491,12 @@ class BASE_EXPORT ListValue : public Value { |
void AppendString(const string16& in_value); |
void AppendStrings(const std::vector<std::string>& in_values); |
void AppendStrings(const std::vector<string16>& in_values); |
+ // Int64 helper methods that actually store the given value as a string. |
+ // Note that if obtaining the named value via Get, the Value type will be |
+ // TYPE_STRING. |
+ void AppendInt64(int64 value); |
+ // As above, but for unsigned values. |
+ void AppendUint64(uint64 value); |
// Appends a Value if it's not already present. Takes ownership of the |
// |in_value|. Returns true if successful, or false if the value was already |