Skip to content

Commit df06ad9

Browse files
authored
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.
1 parent f0f9d70 commit df06ad9

File tree

7 files changed

+98
-22
lines changed

7 files changed

+98
-22
lines changed

Firestore/Source/API/FIRGeoPoint+Internal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,11 @@
1818

1919
NS_ASSUME_NONNULL_BEGIN
2020

21-
namespace firebase {
22-
namespace firestore {
23-
class GeoPoint;
24-
} // namespace firestore
25-
} // namespace firebase
26-
27-
namespace firestore = firebase::firestore;
28-
2921
/** Internal FIRGeoPoint API we don't want exposed in our public header files. */
3022
@interface FIRGeoPoint (Internal)
3123

3224
- (NSComparisonResult)compare:(FIRGeoPoint *)other;
3325

34-
- (firestore::GeoPoint)toGeoPoint;
35-
3626
@end
3727

3828
NS_ASSUME_NONNULL_END

Firestore/Source/API/FIRGeoPoint.mm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ - (NSComparisonResult)compare:(FIRGeoPoint *)other {
8888
}
8989
}
9090

91-
- (firestore::GeoPoint)toGeoPoint {
92-
return firestore::GeoPoint(self.latitude, self.longitude);
93-
}
94-
9591
@end
9692

9793
NS_ASSUME_NONNULL_END

Firestore/Source/API/FSTUserDataConverter.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
3131
#import "Firestore/Source/API/FIRFirestore+Internal.h"
3232
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
33+
#import "Firestore/Source/API/converters.h"
3334
#import "Firestore/Source/Model/FSTFieldValue.h"
3435
#import "Firestore/Source/Model/FSTMutation.h"
3536

@@ -49,6 +50,7 @@
4950
#include "absl/strings/match.h"
5051

5152
namespace util = firebase::firestore::util;
53+
using firebase::firestore::GeoPoint;
5254
using firebase::firestore::api::ThrowInvalidArgument;
5355
using firebase::firestore::core::ParsedSetData;
5456
using firebase::firestore::core::ParsedUpdateData;
@@ -455,8 +457,7 @@ - (nullable FSTFieldValue *)parseScalarValue:(nullable id)input context:(ParseCo
455457
return [FSTTimestampValue timestampValue:truncatedTimestamp];
456458

457459
} else if ([input isKindOfClass:[FIRGeoPoint class]]) {
458-
FIRGeoPoint *geoPoint = input;
459-
return FieldValue::FromGeoPoint([geoPoint toGeoPoint]).Wrap();
460+
return FieldValue::FromGeoPoint(api::MakeGeoPoint(input)).Wrap();
460461

461462
} else if ([input isKindOfClass:[NSData class]]) {
462463
NSData *inputData = input;

Firestore/Source/API/converters.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIRESTORE_SOURCE_API_CONVERTERS_H_
18+
#define FIRESTORE_SOURCE_API_CONVERTERS_H_
19+
20+
#if !defined(__OBJC__)
21+
#error "This header only supports Objective-C++"
22+
#endif // !defined(__OBJC__)
23+
24+
#import <Foundation/Foundation.h>
25+
26+
@class FIRGeoPoint;
27+
28+
NS_ASSUME_NONNULL_BEGIN
29+
30+
namespace firebase {
31+
namespace firestore {
32+
33+
class GeoPoint;
34+
35+
namespace api {
36+
37+
/** Converts a user-supplied FIRGeoPoint to the equivalent C++ GeoPoint. */
38+
GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point);
39+
40+
/** Converts a C++ GeoPoint to the equivalent Objective-C FIRGeoPoint. */
41+
FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point);
42+
43+
} // namespace api
44+
} // namespace firestore
45+
} // namespace firebase
46+
47+
NS_ASSUME_NONNULL_END
48+
49+
#endif // FIRESTORE_SOURCE_API_CONVERTERS_H_

Firestore/Source/API/converters.mm

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "Firestore/Source/API/converters.h"
18+
19+
#import "FIRGeoPoint.h"
20+
21+
#include "Firestore/core/include/firebase/firestore/geo_point.h"
22+
23+
NS_ASSUME_NONNULL_BEGIN
24+
25+
namespace firebase {
26+
namespace firestore {
27+
namespace api {
28+
29+
GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point) {
30+
return GeoPoint(geo_point.latitude, geo_point.longitude);
31+
}
32+
33+
FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point) {
34+
return [[FIRGeoPoint alloc] initWithLatitude:geo_point.latitude()
35+
longitude:geo_point.longitude()];
36+
}
37+
38+
} // namespace api
39+
} // namespace firestore
40+
} // namespace firebase
41+
42+
NS_ASSUME_NONNULL_END

Firestore/Source/Model/FSTFieldValue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "Firestore/core/src/firebase/firestore/model/field_value_options.h"
2727

2828
@class FIRTimestamp;
29-
@class FIRGeoPoint;
3029

3130
namespace model = firebase::firestore::model;
3231

Firestore/Source/Model/FSTFieldValue.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "FIRTimestamp.h"
2424

2525
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
26+
#import "Firestore/Source/API/converters.h"
2627
#import "Firestore/Source/Model/FSTDocumentKey.h"
2728
#import "Firestore/Source/Util/FSTClasses.h"
2829

@@ -35,7 +36,7 @@
3536
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
3637

3738
namespace util = firebase::firestore::util;
38-
using firebase::firestore::GeoPoint;
39+
using firebase::firestore::api::MakeFIRGeoPoint;
3940
using firebase::firestore::model::DatabaseId;
4041
using firebase::firestore::model::FieldMask;
4142
using firebase::firestore::model::FieldPath;
@@ -685,10 +686,8 @@ - (id)value {
685686
return MakeNSData(self.internalValue.blob_value());
686687
case FieldValue::Type::Reference:
687688
HARD_FAIL("TODO(rsgowman): implement");
688-
case FieldValue::Type::GeoPoint: {
689-
GeoPoint value = self.internalValue.geo_point_value();
690-
return [[FIRGeoPoint alloc] initWithLatitude:value.latitude() longitude:value.longitude()];
691-
}
689+
case FieldValue::Type::GeoPoint:
690+
return MakeFIRGeoPoint(self.internalValue.geo_point_value());
692691
case FieldValue::Type::Array:
693692
case FieldValue::Type::Object:
694693
HARD_FAIL("TODO(rsgowman): implement");

0 commit comments

Comments
 (0)