aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Model
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-03-05 11:30:59 -0500
committerGravatar GitHub <noreply@github.com>2018-03-05 11:30:59 -0500
commit1c40e7aada6b32bbc621f06fb5f380149606a58d (patch)
tree6dee81f74f8a33d1beae915d9227caf28b8e2598 /Firestore/Source/Model
parent9b5b4d876eb77e65b3246614855088be101eebf3 (diff)
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
Diffstat (limited to 'Firestore/Source/Model')
-rw-r--r--Firestore/Source/Model/FSTPath.h26
-rw-r--r--Firestore/Source/Model/FSTPath.mm43
2 files changed, 69 insertions, 0 deletions
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 <Foundation/Foundation.h>
+#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 <string>
+
#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<NSString *> *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<std::string> 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<NSString *> *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<std::string> 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