diff options
author | Gil <mcg@google.com> | 2018-01-31 11:23:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-31 11:23:55 -0800 |
commit | 729b8d176c75ecc0cbbd137cc6811116a64e310a (patch) | |
tree | 22b793b03611ce5ad615b7c7d9579f5ba5206b4a /Firestore/Source/Core | |
parent | 693d0649bfcc9c32201e2431ae08ea85fdbdb617 (diff) |
Move all Firestore Objective-C to Objective-C++ (#734)
* Move all Firestore files to Objective-C++
* Update project file references
* Don't use module imports from Objective-C++
* Use extern "C" for C-accessible globals
* Work around more stringent type checking in Objective-C++
* NSMutableDictionary ivars aren't implicitly casted to NSDictionary
* FSTMaybeDocument callback can't be passed a function that accepts
FSTDocument
* NSComparisonResult can't be multiplied by -1 without casting
* Add a #include <inttypes.h> where needed
* Avoid using C++ keywords as variables
* Remove #if __cplusplus guards
Diffstat (limited to 'Firestore/Source/Core')
-rw-r--r-- | Firestore/Source/Core/FSTDatabaseInfo.mm (renamed from Firestore/Source/Core/FSTDatabaseInfo.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTEventManager.mm (renamed from Firestore/Source/Core/FSTEventManager.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTFirestoreClient.mm (renamed from Firestore/Source/Core/FSTFirestoreClient.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTListenSequence.mm (renamed from Firestore/Source/Core/FSTListenSequence.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTQuery.mm (renamed from Firestore/Source/Core/FSTQuery.m) | 22 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTSnapshotVersion.mm (renamed from Firestore/Source/Core/FSTSnapshotVersion.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTTransaction.mm (renamed from Firestore/Source/Core/FSTTransaction.m) | 32 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTView.mm (renamed from Firestore/Source/Core/FSTView.m) | 0 | ||||
-rw-r--r-- | Firestore/Source/Core/FSTViewSnapshot.mm (renamed from Firestore/Source/Core/FSTViewSnapshot.m) | 0 |
9 files changed, 33 insertions, 21 deletions
diff --git a/Firestore/Source/Core/FSTDatabaseInfo.m b/Firestore/Source/Core/FSTDatabaseInfo.mm index 2dbe61a..2dbe61a 100644 --- a/Firestore/Source/Core/FSTDatabaseInfo.m +++ b/Firestore/Source/Core/FSTDatabaseInfo.mm diff --git a/Firestore/Source/Core/FSTEventManager.m b/Firestore/Source/Core/FSTEventManager.mm index bc204a0..bc204a0 100644 --- a/Firestore/Source/Core/FSTEventManager.m +++ b/Firestore/Source/Core/FSTEventManager.mm diff --git a/Firestore/Source/Core/FSTFirestoreClient.m b/Firestore/Source/Core/FSTFirestoreClient.mm index fff644d..fff644d 100644 --- a/Firestore/Source/Core/FSTFirestoreClient.m +++ b/Firestore/Source/Core/FSTFirestoreClient.mm diff --git a/Firestore/Source/Core/FSTListenSequence.m b/Firestore/Source/Core/FSTListenSequence.mm index 6f50d35..6f50d35 100644 --- a/Firestore/Source/Core/FSTListenSequence.m +++ b/Firestore/Source/Core/FSTListenSequence.mm diff --git a/Firestore/Source/Core/FSTQuery.m b/Firestore/Source/Core/FSTQuery.mm index 13657f7..8c98687 100644 --- a/Firestore/Source/Core/FSTQuery.m +++ b/Firestore/Source/Core/FSTQuery.mm @@ -27,6 +27,13 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - FSTRelationFilterOperator functions +/** + * Returns the reverse order (i.e. Ascending => Descending) etc. + */ +static constexpr NSComparisonResult ReverseOrder(NSComparisonResult result) { + return static_cast<NSComparisonResult>(-static_cast<NSInteger>(result)); +} + NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOperator) { switch (filterOperator) { case FSTRelationFilterOperatorLessThan: @@ -287,16 +294,20 @@ NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOpe #pragma mark - Public methods - (NSComparisonResult)compareDocument:(FSTDocument *)document1 toDocument:(FSTDocument *)document2 { - int modifier = self.isAscending ? 1 : -1; + NSComparisonResult result; if ([self.field isEqual:[FSTFieldPath keyFieldPath]]) { - return (NSComparisonResult)(modifier * FSTDocumentKeyComparator(document1.key, document2.key)); + result = FSTDocumentKeyComparator(document1.key, document2.key); } else { FSTFieldValue *value1 = [document1 fieldForPath:self.field]; FSTFieldValue *value2 = [document2 fieldForPath:self.field]; FSTAssert(value1 != nil && value2 != nil, @"Trying to compare documents on fields that don't exist."); - return modifier * [value1 compare:value2]; + result = [value1 compare:value2]; + } + if (!self.isAscending) { + result = ReverseOrder(result); } + return result; } - (NSString *)canonicalID { @@ -377,7 +388,8 @@ NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOpe if ([sortOrderComponent.field isEqual:[FSTFieldPath keyFieldPath]]) { FSTAssert([fieldValue isKindOfClass:[FSTReferenceValue class]], @"FSTBound has a non-key value where the key path is being used %@", fieldValue); - comparison = [fieldValue.value compare:document.key]; + FSTReferenceValue *refValue = (FSTReferenceValue *)fieldValue; + comparison = [refValue.value compare:document.key]; } else { FSTFieldValue *docValue = [document fieldForPath:sortOrderComponent.field]; FSTAssert(docValue != nil, @"Field should exist since document matched the orderBy already."); @@ -385,7 +397,7 @@ NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOpe } if (!sortOrderComponent.isAscending) { - comparison = comparison * -1; + comparison = ReverseOrder(comparison); } if (comparison != 0) { diff --git a/Firestore/Source/Core/FSTSnapshotVersion.m b/Firestore/Source/Core/FSTSnapshotVersion.mm index 980ae52..980ae52 100644 --- a/Firestore/Source/Core/FSTSnapshotVersion.m +++ b/Firestore/Source/Core/FSTSnapshotVersion.mm diff --git a/Firestore/Source/Core/FSTTransaction.m b/Firestore/Source/Core/FSTTransaction.mm index c4c5f27..f97888a 100644 --- a/Firestore/Source/Core/FSTTransaction.m +++ b/Firestore/Source/Core/FSTTransaction.mm @@ -104,22 +104,22 @@ NS_ASSUME_NONNULL_BEGIN FSTThrowInvalidUsage(@"FIRIllegalStateException", @"All reads in a transaction must be done before any writes."); } - [self.datastore - lookupDocuments:keys - completion:^(NSArray<FSTDocument *> *_Nullable documents, NSError *_Nullable error) { - if (error) { - completion(nil, error); - return; - } - for (FSTMaybeDocument *doc in documents) { - NSError *recordError = nil; - if (![self recordVersionForDocument:doc error:&recordError]) { - completion(nil, recordError); - return; - } - } - completion(documents, nil); - }]; + [self.datastore lookupDocuments:keys + completion:^(NSArray<FSTMaybeDocument *> *_Nullable documents, + NSError *_Nullable error) { + if (error) { + completion(nil, error); + return; + } + for (FSTMaybeDocument *doc in documents) { + NSError *recordError = nil; + if (![self recordVersionForDocument:doc error:&recordError]) { + completion(nil, recordError); + return; + } + } + completion(documents, nil); + }]; } /** Stores mutations to be written when commitWithCompletion is called. */ diff --git a/Firestore/Source/Core/FSTView.m b/Firestore/Source/Core/FSTView.mm index d6b4558..d6b4558 100644 --- a/Firestore/Source/Core/FSTView.m +++ b/Firestore/Source/Core/FSTView.mm diff --git a/Firestore/Source/Core/FSTViewSnapshot.m b/Firestore/Source/Core/FSTViewSnapshot.mm index e60b785..e60b785 100644 --- a/Firestore/Source/Core/FSTViewSnapshot.m +++ b/Firestore/Source/Core/FSTViewSnapshot.mm |