mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-11 22:55:59 +05:45
Clean up GeoPoint port to C++ (#3153)
... based on things learned porting Timestamps. There's no good way to include conversions equivalent to toGeoPoint in FIRTimestamp, so pull out separate conversion functions that match other similar things.
This commit is contained in:
7 files changed
+98
-22
No files matched your search
@@ -18,21 +18,11 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
namespace firebase {
|
||||
namespace firestore {
|
||||
class GeoPoint;
|
||||
} // namespace firestore
|
||||
} // namespace firebase
|
||||
|
||||
namespace firestore = firebase::firestore;
|
||||
|
||||
/** Internal FIRGeoPoint API we don't want exposed in our public header files. */
|
||||
@interface FIRGeoPoint (Internal)
|
||||
|
||||
- (NSComparisonResult)compare:(FIRGeoPoint *)other;
|
||||
|
||||
- (firestore::GeoPoint)toGeoPoint;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -88,10 +88,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
- (firestore::GeoPoint)toGeoPoint {
|
||||
return firestore::GeoPoint(self.latitude, self.longitude);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -30,6 +30,7 @@
|
||||
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
|
||||
#import "Firestore/Source/API/FIRFirestore+Internal.h"
|
||||
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
|
||||
#import "Firestore/Source/API/converters.h"
|
||||
#import "Firestore/Source/Model/FSTFieldValue.h"
|
||||
#import "Firestore/Source/Model/FSTMutation.h"
|
||||
|
||||
@@ -49,6 +50,7 @@
|
||||
#include "absl/strings/match.h"
|
||||
|
||||
namespace util = firebase::firestore::util;
|
||||
using firebase::firestore::GeoPoint;
|
||||
using firebase::firestore::api::ThrowInvalidArgument;
|
||||
using firebase::firestore::core::ParsedSetData;
|
||||
using firebase::firestore::core::ParsedUpdateData;
|
||||
@@ -455,8 +457,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return [FSTTimestampValue timestampValue:truncatedTimestamp];
|
||||
|
||||
} else if ([input isKindOfClass:[FIRGeoPoint class]]) {
|
||||
FIRGeoPoint *geoPoint = input;
|
||||
return FieldValue::FromGeoPoint([geoPoint toGeoPoint]).Wrap();
|
||||
return FieldValue::FromGeoPoint(api::MakeGeoPoint(input)).Wrap();
|
||||
|
||||
} else if ([input isKindOfClass:[NSData class]]) {
|
||||
NSData *inputData = input;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
#ifndef FIRESTORE_SOURCE_API_CONVERTERS_H_
|
||||
#define FIRESTORE_SOURCE_API_CONVERTERS_H_
|
||||
|
||||
#if !defined(__OBJC__)
|
||||
#error "This header only supports Objective-C++"
|
||||
#endif // !defined(__OBJC__)
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class FIRGeoPoint;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
namespace firebase {
|
||||
namespace firestore {
|
||||
|
||||
class GeoPoint;
|
||||
|
||||
namespace api {
|
||||
|
||||
/** Converts a user-supplied FIRGeoPoint to the equivalent C++ GeoPoint. */
|
||||
GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point);
|
||||
|
||||
/** Converts a C++ GeoPoint to the equivalent Objective-C FIRGeoPoint. */
|
||||
FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point);
|
||||
|
||||
} // namespace api
|
||||
} // namespace firestore
|
||||
} // namespace firebase
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif // FIRESTORE_SOURCE_API_CONVERTERS_H_
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
#include "Firestore/Source/API/converters.h"
|
||||
|
||||
#import "FIRGeoPoint.h"
|
||||
|
||||
#include "Firestore/core/include/firebase/firestore/geo_point.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
namespace firebase {
|
||||
namespace firestore {
|
||||
namespace api {
|
||||
|
||||
GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point) {
|
||||
return GeoPoint(geo_point.latitude, geo_point.longitude);
|
||||
}
|
||||
|
||||
FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point) {
|
||||
return [[FIRGeoPoint alloc] initWithLatitude:geo_point.latitude()
|
||||
longitude:geo_point.longitude()];
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace firestore
|
||||
} // namespace firebase
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "Firestore/core/src/firebase/firestore/model/field_value_options.h"
|
||||
|
||||
@class FIRTimestamp;
|
||||
@class FIRGeoPoint;
|
||||
|
||||
namespace model = firebase::firestore::model;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#import "FIRTimestamp.h"
|
||||
|
||||
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
|
||||
#import "Firestore/Source/API/converters.h"
|
||||
#import "Firestore/Source/Model/FSTDocumentKey.h"
|
||||
#import "Firestore/Source/Util/FSTClasses.h"
|
||||
|
||||
@@ -35,7 +36,7 @@
|
||||
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
|
||||
|
||||
namespace util = firebase::firestore::util;
|
||||
using firebase::firestore::GeoPoint;
|
||||
using firebase::firestore::api::MakeFIRGeoPoint;
|
||||
using firebase::firestore::model::DatabaseId;
|
||||
using firebase::firestore::model::FieldMask;
|
||||
using firebase::firestore::model::FieldPath;
|
||||
@@ -685,10 +686,8 @@ static const NSComparator StringComparator = ^NSComparisonResult(NSString *left,
|
||||
return MakeNSData(self.internalValue.blob_value());
|
||||
case FieldValue::Type::Reference:
|
||||
HARD_FAIL("TODO(rsgowman): implement");
|
||||
case FieldValue::Type::GeoPoint: {
|
||||
GeoPoint value = self.internalValue.geo_point_value();
|
||||
return [[FIRGeoPoint alloc] initWithLatitude:value.latitude() longitude:value.longitude()];
|
||||
}
|
||||
case FieldValue::Type::GeoPoint:
|
||||
return MakeFIRGeoPoint(self.internalValue.geo_point_value());
|
||||
case FieldValue::Type::Array:
|
||||
case FieldValue::Type::Object:
|
||||
HARD_FAIL("TODO(rsgowman): implement");
|
||||
|
||||
Reference in new issue
Block a user