aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Model
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-02-06 13:51:11 -0500
committerGravatar GitHub <noreply@github.com>2018-02-06 13:51:11 -0500
commita441190635d494f128cf02e07566ae2003af4e08 (patch)
tree618e6b0ecdb5d243f6e97f319f98f09dc9ca0a7e /Firestore/Source/Model
parent7cac9dc47a8c6b7321ebf5fc13fa7140e784c8ca (diff)
Implement Firestore DatabaseInfo and port both Database{Id,Info} C++ to the iOS code (#738)
* implement Firestore DatabaseInfo in C++ * temporary stash changes; blocking on the massive renaming of .m to .mm * add database_info_test to project * finish port DatabaseId and fix style, modular fixing DatabaseInfo * port DatabaseInfo * remove FSTDatabase{ID,Info} and their tests from project * fix unit test * use namespace alias * use namespace alias, leftover * address more changes * refactoring to use raw pointer instead of value for property * address changes * remove self-> * fix style * remove the name suffix Alloc * fix a bug
Diffstat (limited to 'Firestore/Source/Model')
-rw-r--r--Firestore/Source/Model/FSTDatabaseID.h48
-rw-r--r--Firestore/Source/Model/FSTDatabaseID.mm90
-rw-r--r--Firestore/Source/Model/FSTFieldValue.h9
-rw-r--r--Firestore/Source/Model/FSTFieldValue.mm23
4 files changed, 22 insertions, 148 deletions
diff --git a/Firestore/Source/Model/FSTDatabaseID.h b/Firestore/Source/Model/FSTDatabaseID.h
deleted file mode 100644
index 442e764..0000000
--- a/Firestore/Source/Model/FSTDatabaseID.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-/** FSTDatabaseID represents a particular database in the datastore. */
-@interface FSTDatabaseID : NSObject
-
-/**
- * Creates and returns a new FSTDatabaseID.
- * @param projectID The project for the database.
- * @param databaseID The database in the project to use.
- * @return A new instance of FSTDatabaseID.
- */
-+ (instancetype)databaseIDWithProject:(NSString *)projectID database:(NSString *)databaseID;
-
-/** The project. */
-@property(nonatomic, copy, readonly) NSString *projectID;
-
-/** The database. */
-@property(nonatomic, copy, readonly) NSString *databaseID;
-
-/** Whether this is the default database of the project. */
-- (BOOL)isDefaultDatabase;
-
-- (NSComparisonResult)compare:(FSTDatabaseID *)other;
-- (BOOL)isEqualToDatabaseId:(FSTDatabaseID *)databaseID;
-
-@end
-
-extern NSString *const kDefaultDatabaseID;
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Model/FSTDatabaseID.mm b/Firestore/Source/Model/FSTDatabaseID.mm
deleted file mode 100644
index bff5855..0000000
--- a/Firestore/Source/Model/FSTDatabaseID.mm
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import "Firestore/Source/Model/FSTDatabaseID.h"
-
-#import "Firestore/Source/Util/FSTAssert.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-/** The default name for "unset" database ID in resource names. */
-NSString *const kDefaultDatabaseID = @"(default)";
-
-#pragma mark - FSTDatabaseID
-
-@implementation FSTDatabaseID
-
-+ (instancetype)databaseIDWithProject:(NSString *)projectID database:(NSString *)databaseID {
- return [[FSTDatabaseID alloc] initWithProject:projectID database:databaseID];
-}
-
-/**
- * Designated initializer.
- *
- * @param projectID The project for the database.
- * @param databaseID The database in the datastore.
- */
-- (instancetype)initWithProject:(NSString *)projectID database:(NSString *)databaseID {
- if (self = [super init]) {
- FSTAssert(databaseID, @"databaseID cannot be nil");
- _projectID = [projectID copy];
- _databaseID = [databaseID copy];
- }
- return self;
-}
-
-- (BOOL)isEqual:(id)other {
- if (other == self) return YES;
- if (![[other class] isEqual:[self class]]) return NO;
-
- return [self isEqualToDatabaseId:other];
-}
-
-- (NSUInteger)hash {
- NSUInteger hash = [self.projectID hash];
- hash = hash * 31u + [self.databaseID hash];
- return hash;
-}
-
-- (NSString *)description {
- return [NSString
- stringWithFormat:@"<FSTDatabaseID: project:%@ database:%@>", self.projectID, self.databaseID];
-}
-
-- (NSComparisonResult)compare:(FSTDatabaseID *)other {
- NSComparisonResult cmp = [self.projectID compare:other.projectID];
- return cmp == NSOrderedSame ? [self.databaseID compare:other.databaseID] : cmp;
-}
-
-- (BOOL)isDefaultDatabase {
- return [self.databaseID isEqualToString:kDefaultDatabaseID];
-}
-
-- (BOOL)isEqualToDatabaseId:(FSTDatabaseID *)databaseID {
- if (self == databaseID) return YES;
- if (databaseID == nil) return NO;
- if (self.projectID != databaseID.projectID &&
- ![self.projectID isEqualToString:databaseID.projectID])
- return NO;
- if (self.databaseID != databaseID.databaseID &&
- ![self.databaseID isEqualToString:databaseID.databaseID])
- return NO;
- return YES;
-}
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Model/FSTFieldValue.h b/Firestore/Source/Model/FSTFieldValue.h
index 93fd5c4..c8118c6 100644
--- a/Firestore/Source/Model/FSTFieldValue.h
+++ b/Firestore/Source/Model/FSTFieldValue.h
@@ -18,7 +18,8 @@
#import "Firestore/third_party/Immutable/FSTImmutableSortedDictionary.h"
-@class FSTDatabaseID;
+#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+
@class FSTDocumentKey;
@class FSTFieldPath;
@class FSTTimestamp;
@@ -208,9 +209,11 @@ typedef NS_ENUM(NSInteger, FSTServerTimestampBehavior) {
* A reference value stored in Firestore.
*/
@interface FSTReferenceValue : FSTFieldValue <FSTDocumentKey *>
-+ (instancetype)referenceValue:(FSTDocumentKey *)value databaseID:(FSTDatabaseID *)databaseID;
++ (instancetype)referenceValue:(FSTDocumentKey *)value
+ databaseID:(const firebase::firestore::model::DatabaseId *)databaseID;
- (FSTDocumentKey *)valueWithOptions:(FSTFieldValueOptions *)options;
-@property(nonatomic, strong, readonly) FSTDatabaseID *databaseID;
+// Does not own this DatabaseId.
+@property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
@end
/**
diff --git a/Firestore/Source/Model/FSTFieldValue.mm b/Firestore/Source/Model/FSTFieldValue.mm
index 8ffc98e..3f3548c 100644
--- a/Firestore/Source/Model/FSTFieldValue.mm
+++ b/Firestore/Source/Model/FSTFieldValue.mm
@@ -22,12 +22,16 @@
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
#import "Firestore/Source/API/FIRSnapshotOptions+Internal.h"
#import "Firestore/Source/Core/FSTTimestamp.h"
-#import "Firestore/Source/Model/FSTDatabaseID.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTPath.h"
#import "Firestore/Source/Util/FSTAssert.h"
#import "Firestore/Source/Util/FSTClasses.h"
+#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+
+namespace util = firebase::firestore::util;
+using firebase::firestore::model::DatabaseId;
using firebase::firestore::util::Comparator;
using firebase::firestore::util::CompareMixedNumber;
using firebase::firestore::util::DoubleBitwiseEquals;
@@ -650,11 +654,11 @@ static NSComparisonResult CompareBytes(NSData *left, NSData *right) {
@implementation FSTReferenceValue
-+ (instancetype)referenceValue:(FSTDocumentKey *)value databaseID:(FSTDatabaseID *)databaseID {
++ (instancetype)referenceValue:(FSTDocumentKey *)value databaseID:(const DatabaseId *)databaseID {
return [[FSTReferenceValue alloc] initWithValue:value databaseID:databaseID];
}
-- (id)initWithValue:(FSTDocumentKey *)value databaseID:(FSTDatabaseID *)databaseID {
+- (id)initWithValue:(FSTDocumentKey *)value databaseID:(const DatabaseId *)databaseID {
self = [super init];
if (self) {
_key = value;
@@ -680,12 +684,11 @@ static NSComparisonResult CompareBytes(NSData *left, NSData *right) {
}
FSTReferenceValue *otherRef = (FSTReferenceValue *)other;
- return [self.key isEqualToKey:otherRef.key] &&
- [self.databaseID isEqualToDatabaseId:otherRef.databaseID];
+ return [self.key isEqualToKey:otherRef.key] && *self.databaseID == *otherRef.databaseID;
}
- (NSUInteger)hash {
- NSUInteger result = [self.databaseID hash];
+ NSUInteger result = self.databaseID->Hash();
result = 31 * result + [self.key hash];
return result;
}
@@ -693,7 +696,13 @@ static NSComparisonResult CompareBytes(NSData *left, NSData *right) {
- (NSComparisonResult)compare:(FSTFieldValue *)other {
if ([other isKindOfClass:[FSTReferenceValue class]]) {
FSTReferenceValue *ref = (FSTReferenceValue *)other;
- NSComparisonResult cmp = [self.databaseID compare:ref.databaseID];
+ NSComparisonResult cmp = [util::WrapNSStringNoCopy(self.databaseID->project_id())
+ compare:util::WrapNSStringNoCopy(ref.databaseID->project_id())];
+ if (cmp != NSOrderedSame) {
+ return cmp;
+ }
+ cmp = [util::WrapNSStringNoCopy(self.databaseID->database_id())
+ compare:util::WrapNSStringNoCopy(ref.databaseID->database_id())];
return cmp != NSOrderedSame ? cmp : [self.key compare:ref.key];
} else {
return [self defaultCompare:other];