From 1c40e7aada6b32bbc621f06fb5f380149606a58d Mon Sep 17 00:00:00 2001 From: zxu Date: Mon, 5 Mar 2018 11:30:59 -0500 Subject: add converters and port paths to FSTQuery (#869) * add converters and fix FSTQuery.{h,m} only * address changes * a change forget to address * add a dummy function to make inline-only-library buildable --- Firestore/Source/Model/FSTPath.h | 26 +++++++++++++++++++++++ Firestore/Source/Model/FSTPath.mm | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) (limited to 'Firestore/Source/Model') diff --git a/Firestore/Source/Model/FSTPath.h b/Firestore/Source/Model/FSTPath.h index 1f63f17..f127156 100644 --- a/Firestore/Source/Model/FSTPath.h +++ b/Firestore/Source/Model/FSTPath.h @@ -16,6 +16,9 @@ #import +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" + NS_ASSUME_NONNULL_BEGIN /** @@ -113,6 +116,17 @@ NS_ASSUME_NONNULL_BEGIN /** Returns YES if this is the `FSTFieldPath.keyFieldPath` field path. */ - (BOOL)isKeyFieldPath; +/** Creates and returns a new path from C++ FieldPath. + * + * @param fieldPath A C++ FieldPath. + */ ++ (instancetype)fieldPathWithCPPFieldPath:(const firebase::firestore::model::FieldPath &)fieldPath; + +/** + * Creates and returns a new C++ FieldPath. + */ +- (firebase::firestore::model::FieldPath)toCPPFieldPath; + @end /** A slash-separated path for navigating resources (documents and collections) within Firestore. */ @@ -136,6 +150,18 @@ NS_ASSUME_NONNULL_BEGIN * @param resourcePath A slash-separated string representing the path. */ + (instancetype)pathWithString:(NSString *)resourcePath; + +/** Creates and returns a new path from C++ ResourcePath. + * + * @param resourcePath A C++ ResourcePath. + */ ++ (instancetype)resourcePathWithCPPResourcePath: + (const firebase::firestore::model::ResourcePath &)resourcePath; + +/** + * Creates and returns a new C++ ResourcePath. + */ +- (firebase::firestore::model::ResourcePath)toCPPResourcePath; @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Model/FSTPath.mm b/Firestore/Source/Model/FSTPath.mm index 636c322..b91e428 100644 --- a/Firestore/Source/Model/FSTPath.mm +++ b/Firestore/Source/Model/FSTPath.mm @@ -16,11 +16,21 @@ #import "Firestore/Source/Model/FSTPath.h" +#include + #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTClasses.h" #import "Firestore/Source/Util/FSTUsageValidation.h" +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" + +namespace util = firebase::firestore::util; +using firebase::firestore::model::FieldPath; +using firebase::firestore::model::ResourcePath; + NS_ASSUME_NONNULL_BEGIN @interface FSTPath () @@ -313,6 +323,22 @@ NS_ASSUME_NONNULL_BEGIN return result; } ++ (instancetype)fieldPathWithCPPFieldPath:(const FieldPath &)fieldPath { + NSMutableArray *segments = [NSMutableArray arrayWithCapacity:fieldPath.size()]; + for (int i = 0; i < fieldPath.size(); i++) { + segments[i] = util::WrapNSString(fieldPath[i]); + } + return [FSTFieldPath pathWithSegments:segments]; +} + +- (FieldPath)toCPPFieldPath { + std::vector segments(self.length); + for (int i = 0; i < self.length; i++) { + segments[i] = [[self segmentAtIndex:i] UTF8String]; + } + return FieldPath(segments.begin(), segments.end()); +} + @end @implementation FSTResourcePath @@ -351,6 +377,23 @@ NS_ASSUME_NONNULL_BEGIN } return result; } + ++ (instancetype)resourcePathWithCPPResourcePath:(const ResourcePath &)resourcePath { + NSMutableArray *segments = [NSMutableArray arrayWithCapacity:resourcePath.size()]; + for (int i = 0; i < resourcePath.size(); i++) { + segments[i] = util::WrapNSString(resourcePath[i]); + } + return [FSTResourcePath pathWithSegments:segments]; +} + +- (ResourcePath)toCPPResourcePath { + std::vector segments(self.length); + for (int i = 0; i < self.length; i++) { + segments[i] = [[self segmentAtIndex:i] UTF8String]; + } + return ResourcePath(segments.begin(), segments.end()); +} + @end NS_ASSUME_NONNULL_END -- cgit v1.2.3