aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Model
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-04-04 12:40:46 -0400
committerGravatar GitHub <noreply@github.com>2018-04-04 12:40:46 -0400
commit5fa10a914334562564a26298f128bc852269077f (patch)
treed3529b649230fdf617e492544670ced1191ca5d3 /Firestore/Source/Model
parentfbe9f9c30c025842a3657055f8dfabbc77f65bf2 (diff)
port FieldMask to C++ (#998)
* port FieldMask to C++ * address changes * address changes * fix test * address change * fix lint * address changes * Revert "address changes" This reverts commit c75bb42851b785ab0838bb23679f87dfad9df4bb.
Diffstat (limited to 'Firestore/Source/Model')
-rw-r--r--Firestore/Source/Model/FSTMutation.h38
-rw-r--r--Firestore/Source/Model/FSTMutation.mm64
2 files changed, 24 insertions, 78 deletions
diff --git a/Firestore/Source/Model/FSTMutation.h b/Firestore/Source/Model/FSTMutation.h
index 4e4357d..2b81af6 100644
--- a/Firestore/Source/Model/FSTMutation.h
+++ b/Firestore/Source/Model/FSTMutation.h
@@ -19,6 +19,7 @@
#include <vector>
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
@class FSTDocument;
@@ -30,31 +31,6 @@
NS_ASSUME_NONNULL_BEGIN
-#pragma mark - FSTFieldMask
-
-/**
- * Provides a set of fields that can be used to partially patch a document. FieldMask is used in
- * conjunction with ObjectValue.
- *
- * Examples:
- * foo - Overwrites foo entirely with the provided value. If foo is not present in the companion
- * ObjectValue, the field is deleted.
- * foo.bar - Overwrites only the field bar of the object foo. If foo is not an object, foo is
- * replaced with an object containing bar.
- */
-@interface FSTFieldMask : NSObject
-- (id)init __attribute__((unavailable("Use initWithFields:")));
-
-/**
- * Initializes the field mask with the given field paths. Caller is expected to either copy or
- * or release the array of fields.
- */
-- (instancetype)initWithFields:(std::vector<firebase::firestore::model::FieldPath>)fields
- NS_DESIGNATED_INITIALIZER;
-
-- (const std::vector<firebase::firestore::model::FieldPath> &)fields;
-@end
-
#pragma mark - FSTFieldTransform
/** Represents a transform within a TransformMutation. */
@@ -267,7 +243,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE;
/**
- * Initializes a new patch mutation with an explicit FSTFieldMask and FSTObjectValue representing
+ * Initializes a new patch mutation with an explicit FieldMask and FSTObjectValue representing
* the updates to perform
*
* @param key Identifies the location of the document to mutate.
@@ -278,18 +254,18 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
* @param precondition The precondition for this mutation.
*/
- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(firebase::firestore::model::FieldMask)fieldMask
value:(FSTObjectValue *)value
precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER;
-/** The fields and associated values to use when patching the document. */
-@property(nonatomic, strong, readonly) FSTObjectValue *value;
-
/**
* A mask to apply to |value|, where only fields that are in both the fieldMask and the value
* will be updated.
*/
-@property(nonatomic, strong, readonly) FSTFieldMask *fieldMask;
+- (const firebase::firestore::model::FieldMask &)fieldMask;
+
+/** The fields and associated values to use when patching the document. */
+@property(nonatomic, strong, readonly) FSTObjectValue *value;
@end
diff --git a/Firestore/Source/Model/FSTMutation.mm b/Firestore/Source/Model/FSTMutation.mm
index 253a853..df95155 100644
--- a/Firestore/Source/Model/FSTMutation.mm
+++ b/Firestore/Source/Model/FSTMutation.mm
@@ -27,51 +27,15 @@
#import "Firestore/Source/Util/FSTClasses.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldPath;
NS_ASSUME_NONNULL_BEGIN
-#pragma mark - FSTFieldMask
-
-@implementation FSTFieldMask {
- std::vector<FieldPath> _fields;
-}
-
-- (instancetype)initWithFields:(std::vector<FieldPath>)fields {
- if (self = [super init]) {
- _fields = std::move(fields);
- }
- return self;
-}
-
-- (BOOL)isEqual:(id)other {
- if (other == self) {
- return YES;
- }
- if (![other isKindOfClass:[FSTFieldMask class]]) {
- return NO;
- }
-
- FSTFieldMask *otherMask = (FSTFieldMask *)other;
- return _fields == otherMask->_fields;
-}
-
-- (NSUInteger)hash {
- NSUInteger hashResult = 0;
- for (const FieldPath &field : _fields) {
- hashResult = hashResult * 31u + field.Hash();
- }
- return hashResult;
-}
-
-- (const std::vector<FieldPath> &)fields {
- return _fields;
-}
-@end
-
#pragma mark - FSTServerTimestampTransform
@implementation FSTServerTimestampTransform
@@ -354,20 +318,26 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - FSTPatchMutation
-@implementation FSTPatchMutation
+@implementation FSTPatchMutation {
+ FieldMask _fieldMask;
+}
- (instancetype)initWithKey:(DocumentKey)key
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(FieldMask)fieldMask
value:(FSTObjectValue *)value
precondition:(FSTPrecondition *)precondition {
self = [super initWithKey:std::move(key) precondition:precondition];
if (self) {
- _fieldMask = fieldMask;
+ _fieldMask = std::move(fieldMask);
_value = value;
}
return self;
}
+- (const firebase::firestore::model::FieldMask &)fieldMask {
+ return _fieldMask;
+}
+
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
@@ -377,7 +347,7 @@ NS_ASSUME_NONNULL_BEGIN
}
FSTPatchMutation *otherMutation = (FSTPatchMutation *)other;
- return [self.key isEqual:otherMutation.key] && [self.fieldMask isEqual:otherMutation.fieldMask] &&
+ return [self.key isEqual:otherMutation.key] && self.fieldMask == otherMutation.fieldMask &&
[self.value isEqual:otherMutation.value] &&
[self.precondition isEqual:otherMutation.precondition];
}
@@ -385,15 +355,15 @@ NS_ASSUME_NONNULL_BEGIN
- (NSUInteger)hash {
NSUInteger result = [self.key hash];
result = 31 * result + [self.precondition hash];
- result = 31 * result + [self.fieldMask hash];
+ result = 31 * result + self.fieldMask.Hash();
result = 31 * result + [self.value hash];
return result;
}
- (NSString *)description {
- return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%@ value=%@ precondition=%@>",
- self.key.ToString().c_str(), self.fieldMask, self.value,
- self.precondition];
+ return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%s value=%@ precondition=%@>",
+ self.key.ToString().c_str(), self.fieldMask.ToString().c_str(),
+ self.value, self.precondition];
}
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
@@ -434,7 +404,7 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTObjectValue *)patchObjectValue:(FSTObjectValue *)objectValue {
FSTObjectValue *result = objectValue;
- for (const FieldPath &fieldPath : self.fieldMask.fields) {
+ for (const FieldPath &fieldPath : self.fieldMask) {
FSTFieldValue *newValue = [self.value valueForPath:fieldPath];
if (newValue) {
result = [result objectBySettingValue:newValue forPath:fieldPath];