diff options
Diffstat (limited to 'Firestore/Source/API/FIRFieldPath.mm')
-rw-r--r-- | Firestore/Source/API/FIRFieldPath.mm | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/Firestore/Source/API/FIRFieldPath.mm b/Firestore/Source/API/FIRFieldPath.mm index f4e532f..c651160 100644 --- a/Firestore/Source/API/FIRFieldPath.mm +++ b/Firestore/Source/API/FIRFieldPath.mm @@ -16,11 +16,28 @@ #import "Firestore/Source/API/FIRFieldPath+Internal.h" -#import "Firestore/Source/Model/FSTPath.h" +#include <functional> +#include <string> +#include <utility> +#include <vector> + #import "Firestore/Source/Util/FSTUsageValidation.h" +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" + +namespace util = firebase::firestore::util; +using firebase::firestore::model::FieldPath; + NS_ASSUME_NONNULL_BEGIN +@interface FIRFieldPath () { + /** Internal field path representation */ + firebase::firestore::model::FieldPath _internalValue; +} + +@end + @implementation FIRFieldPath - (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames { @@ -28,22 +45,25 @@ NS_ASSUME_NONNULL_BEGIN FSTThrowInvalidArgument(@"Invalid field path. Provided names must not be empty."); } + std::vector<std::string> field_names{}; + field_names.reserve(fieldNames.count); for (int i = 0; i < fieldNames.count; ++i) { if (fieldNames[i].length == 0) { FSTThrowInvalidArgument(@"Invalid field name at index %d. Field names must not be empty.", i); } + field_names.emplace_back(util::MakeString(fieldNames[i])); } - return [self initPrivate:[FSTFieldPath pathWithSegments:fieldNames]]; + return [self initPrivate:FieldPath(std::move(field_names))]; } + (instancetype)documentID { - return [[FIRFieldPath alloc] initPrivate:FSTFieldPath.keyFieldPath]; + return [[FIRFieldPath alloc] initPrivate:FieldPath::KeyFieldPath()]; } -- (instancetype)initPrivate:(FSTFieldPath *)fieldPath { +- (instancetype)initPrivate:(FieldPath)fieldPath { if (self = [super init]) { - _internalValue = fieldPath; + _internalValue = std::move(fieldPath); } return self; } @@ -77,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN } - (id)copyWithZone:(NSZone *__nullable)zone { - return [[[self class] alloc] initPrivate:self.internalValue]; + return [[[self class] alloc] initPrivate:_internalValue]; } - (BOOL)isEqual:(nullable id)object { @@ -89,11 +109,15 @@ NS_ASSUME_NONNULL_BEGIN return NO; } - return [self.internalValue isEqual:((FIRFieldPath *)object).internalValue]; + return _internalValue == ((FIRFieldPath *)object)->_internalValue; } - (NSUInteger)hash { - return [self.internalValue hash]; + return _internalValue.Hash(); +} + +- (const firebase::firestore::model::FieldPath &)internalValue { + return _internalValue; } @end |