-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ObjectValue changes #8007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectValue changes #8007
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -37,26 +37,33 @@ namespace firestore { | |||
namespace model { | ||||
|
||||
/** A structured object value stored in Firestore. */ | ||||
// TODO(mutabledocuments): Rename to ObjectValue once other ObjectValue class | ||||
// is removed | ||||
class MutableObjectValue { | ||||
class ObjectValue { | ||||
public: | ||||
MutableObjectValue(); | ||||
ObjectValue(); | ||||
|
||||
/** Creates a new MutableObjectValue and takes ownership of `value`. */ | ||||
explicit MutableObjectValue(const google_firestore_v1_Value& value) | ||||
: value_(value) { | ||||
HARD_ASSERT( | ||||
value.which_value_type == google_firestore_v1_Value_map_value_tag, | ||||
"ObjectValues should be backed by a MapValue"); | ||||
} | ||||
explicit ObjectValue(const google_firestore_v1_Value& value); | ||||
|
||||
MutableObjectValue(MutableObjectValue&& other) noexcept = default; | ||||
MutableObjectValue& operator=(MutableObjectValue&& other) = default; | ||||
ObjectValue(ObjectValue&& other) noexcept = default; | ||||
ObjectValue& operator=(ObjectValue&& other) noexcept = default; | ||||
ObjectValue(const ObjectValue& other); | ||||
|
||||
/** `MutableObjectValue` models unique ownership. */ | ||||
MutableObjectValue(const MutableObjectValue&) = delete; | ||||
MutableObjectValue& operator=(const MutableObjectValue&) = delete; | ||||
ObjectValue& operator=(const ObjectValue&) = delete; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this class copy constructible but not copy assignable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would need this operator:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||||
|
||||
/** | ||||
* Creates a new ObjectValue that is backed by the given `map_value`. | ||||
* ObjectValue takes on ownership of the data. | ||||
*/ | ||||
static ObjectValue FromMapValue(google_firestore_v1_MapValue map_value); | ||||
var-const marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
/** | ||||
* Creates a new ObjectValue that is backed by the provided document fields. | ||||
* ObjectValue takes on ownership of the data and zeroes out the pointers in | ||||
* `fields_entry`. This allows the callsite to destruct the Document proto | ||||
* without affecting the fields data. | ||||
*/ | ||||
static ObjectValue FromFieldsEntry( | ||||
var-const marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
google_firestore_v1_Document_FieldsEntry* fields_entry, pb_size_t count); | ||||
|
||||
/** Recursively extracts the FieldPaths that are set in this ObjectValue. */ | ||||
FieldMask ToFieldMask() const; | ||||
|
@@ -69,6 +76,11 @@ class MutableObjectValue { | |||
*/ | ||||
absl::optional<google_firestore_v1_Value> Get(const FieldPath& path) const; | ||||
|
||||
/** | ||||
* Returns the ObjectValue in its Protobuf representation. | ||||
*/ | ||||
google_firestore_v1_Value Get() const; | ||||
|
||||
/** | ||||
* Sets the field to the provided value. | ||||
* | ||||
|
@@ -85,7 +97,7 @@ class MutableObjectValue { | |||
* @param field_mask The field mask that controls which fields to modify. | ||||
* @param data A MutableObjectValue that contains the field values. | ||||
*/ | ||||
void SetAll(const FieldMask& field_mask, const MutableObjectValue& data); | ||||
void SetAll(const FieldMask& field_mask, const ObjectValue& data); | ||||
|
||||
/** | ||||
* Removes the field at the specified path. If there is no field at the | ||||
|
@@ -95,10 +107,13 @@ class MutableObjectValue { | |||
*/ | ||||
void Delete(const FieldPath& path); | ||||
|
||||
friend bool operator==(const MutableObjectValue& lhs, | ||||
const MutableObjectValue& rhs); | ||||
std::string ToString() const; | ||||
|
||||
size_t Hash() const; | ||||
|
||||
friend bool operator==(const ObjectValue& lhs, const ObjectValue& rhs); | ||||
friend std::ostream& operator<<(std::ostream& out, | ||||
const MutableObjectValue& object_value); | ||||
const ObjectValue& object_value); | ||||
|
||||
private: | ||||
/** Returns the field mask for the provided map value. */ | ||||
|
@@ -113,13 +128,12 @@ class MutableObjectValue { | |||
nanopb::Message<google_firestore_v1_Value> value_; | ||||
}; | ||||
|
||||
inline bool operator==(const MutableObjectValue& lhs, | ||||
const MutableObjectValue& rhs) { | ||||
inline bool operator==(const ObjectValue& lhs, const ObjectValue& rhs) { | ||||
return *lhs.value_ == *rhs.value_; | ||||
} | ||||
|
||||
inline std::ostream& operator<<(std::ostream& out, | ||||
const MutableObjectValue& object_value) { | ||||
const ObjectValue& object_value) { | ||||
return out << "ObjectValue(" << *object_value.value_ << ")"; | ||||
} | ||||
|
||||
|
Uh oh!
There was an error while loading. Please reload this page.