summaryrefslogtreecommitdiffstats
path: root/chromium/base/values.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/values.h')
-rw-r--r--chromium/base/values.h57
1 files changed, 50 insertions, 7 deletions
diff --git a/chromium/base/values.h b/chromium/base/values.h
index 38e4f37d68a..ccf87bfd88c 100644
--- a/chromium/base/values.h
+++ b/chromium/base/values.h
@@ -32,6 +32,7 @@
#include <vector>
#include "base/base_export.h"
+#include "base/containers/checked_iterators.h"
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/macros.h"
@@ -111,6 +112,8 @@ class BASE_EXPORT Value {
// Adaptors for converting from the old way to the new way and vice versa.
static Value FromUniquePtrValue(std::unique_ptr<Value> val);
static std::unique_ptr<Value> ToUniquePtrValue(Value val);
+ static const DictionaryValue& AsDictionaryValue(const Value& val);
+ static const ListValue& AsListValue(const Value& val);
Value(Value&& that) noexcept;
Value() noexcept {} // A null value
@@ -144,7 +147,7 @@ class BASE_EXPORT Value {
explicit Value(const DictStorage& in_dict);
explicit Value(DictStorage&& in_dict) noexcept;
- explicit Value(const ListStorage& in_list);
+ explicit Value(span<const Value> in_list);
explicit Value(ListStorage&& in_list) noexcept;
Value& operator=(Value&& that) noexcept;
@@ -176,7 +179,46 @@ class BASE_EXPORT Value {
const BlobStorage& GetBlob() const;
ListStorage& GetList();
- const ListStorage& GetList() const;
+ span<const Value> GetList() const;
+
+ // Transfers ownership of the the underlying list to the caller. Subsequent
+ // calls to GetList() will return an empty list.
+ // Note: This CHECKs that type() is Type::LIST.
+ ListStorage TakeList();
+
+ // Appends |value| to the end of the list.
+ // Note: These CHECK that type() is Type::LIST.
+ void Append(bool value);
+ void Append(int value);
+ void Append(double value);
+ void Append(const char* value);
+ void Append(StringPiece value);
+ void Append(std::string&& value);
+ void Append(const char16* value);
+ void Append(StringPiece16 value);
+ void Append(Value&& value);
+
+ // Erases the Value pointed to by |iter|. Returns false if |iter| is out of
+ // bounds.
+ // Note: This CHECKs that type() is Type::LIST.
+ bool EraseListIter(ListStorage::const_iterator iter);
+ bool EraseListIter(CheckedContiguousConstIterator<Value> iter);
+
+ // Erases all Values that compare equal to |val|. Returns the number of
+ // deleted Values.
+ // Note: This CHECKs that type() is Type::LIST.
+ size_t EraseListValue(const Value& val);
+
+ // Erases all Values for which |pred| returns true. Returns the number of
+ // deleted Values.
+ // Note: This CHECKs that type() is Type::LIST.
+ template <typename Predicate>
+ size_t EraseListValueIf(Predicate pred) {
+ CHECK(is_list());
+ const size_t old_size = list_.size();
+ base::EraseIf(list_, pred);
+ return old_size - list_.size();
+ }
// |FindKey| looks up |key| in the underlying dictionary. If found, it returns
// a pointer to the element. Otherwise it returns nullptr.
@@ -723,7 +765,7 @@ class BASE_EXPORT ListValue : public Value {
static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value);
ListValue();
- explicit ListValue(const ListStorage& in_list);
+ explicit ListValue(span<const Value> in_list);
explicit ListValue(ListStorage&& in_list) noexcept;
// Clears the contents of this ListValue
@@ -803,24 +845,25 @@ class BASE_EXPORT ListValue : public Value {
// DEPRECATED, use GetList()::erase() instead.
iterator Erase(iterator iter, std::unique_ptr<Value>* out_value);
+ using Value::Append;
// Appends a Value to the end of the list.
- // DEPRECATED, use GetList()::push_back() instead.
+ // DEPRECATED, use Value::Append() instead.
void Append(std::unique_ptr<Value> in_value);
// Convenience forms of Append.
- // DEPRECATED, use GetList()::emplace_back() instead.
+ // DEPRECATED, use Value::Append() instead.
void AppendBoolean(bool in_value);
void AppendInteger(int in_value);
void AppendDouble(double in_value);
void AppendString(StringPiece in_value);
void AppendString(const string16& in_value);
- // DEPRECATED, use GetList()::emplace_back() in a loop instead.
+ // DEPRECATED, use Value::Append() in a loop instead.
void AppendStrings(const std::vector<std::string>& in_values);
void AppendStrings(const std::vector<string16>& in_values);
// Appends a Value if it's not already present. Returns true if successful,
// or false if the value was already
- // DEPRECATED, use std::find() with GetList()::push_back() instead.
+ // DEPRECATED, use std::find() with Value::Append() instead.
bool AppendIfNotPresent(std::unique_ptr<Value> in_value);
// Insert a Value at index.