Skip to content

Implement the rest of FieldValue types for C++ #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8ea005d
implement FieldValue for null and boolean.
zxu123 Jan 10, 2018
176975a
refactoring to use union type instead of poly
zxu123 Jan 11, 2018
b75cb7e
refactor using union design intead of poly
zxu123 Jan 12, 2018
f1bb0f4
refactoring to use anonymous union and fix styles
zxu123 Jan 13, 2018
adf7a6b
small fix
zxu123 Jan 16, 2018
11a03f6
add field_value_test to the project
zxu123 Jan 16, 2018
c5728e4
Merge branch 'master' into cpp/fieldvalue
zxu123 Jan 16, 2018
9630117
fix warning of cmake and fix style
zxu123 Jan 16, 2018
7defa1f
Implement number and string FieldValue.
zxu123 Jan 17, 2018
1371191
Implement object FieldValue.
zxu123 Jan 17, 2018
1694745
implement timestamp FieldValue
zxu123 Jan 18, 2018
0a854c6
Implement number and string FieldValue.
zxu123 Jan 17, 2018
b2ff448
Merge branch 'cpp/fieldvaluesss' of https://github.com/firebase/fireb…
zxu123 Jan 19, 2018
5cf366b
implement public type `Blob` and `GeoPoint`
zxu123 Jan 19, 2018
ef2d431
implement Blob FieldValue
zxu123 Jan 20, 2018
bc73829
Implement GeoPoint FieldValue
zxu123 Jan 20, 2018
0581290
Merge branch 'master' into cpp/fieldvaluesss
zxu123 Jan 20, 2018
2fae448
refactoring `Blob`
zxu123 Jan 23, 2018
388524c
utilize util/comparison.h
zxu123 Jan 23, 2018
af21081
Merge branch 'cpp/fieldvaluesss' of https://github.com/firebase/fireb…
zxu123 Jan 23, 2018
2244090
fix style and some small change
zxu123 Jan 23, 2018
0605a4d
address changes
zxu123 Jan 24, 2018
4011465
address changes
zxu123 Jan 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@
AB356EF7200EA5EB0089B766 /* field_value_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB356EF6200EA5EB0089B766 /* field_value_test.cc */; };
AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */; };
AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */; };
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB7BAB332012B519001E0872 /* geo_point_test.cc */; };
AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */; };
AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */; };
AB99452A1FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */; };
AB99452C1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */; };
AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */; };
ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; };
ABF341051FE860CA00C48322 /* FSTAPIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF341021FE8593500C48322 /* FSTAPIHelpers.m */; };
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF6506B201131F8005F2C74 /* timestamp_test.cc */; };
AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; };
C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; };
D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */; };
Expand Down Expand Up @@ -250,6 +252,7 @@
AB356EF6200EA5EB0089B766 /* field_value_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = field_value_test.cc; sourceTree = "<group>"; };
AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentReferenceTests.m; sourceTree = "<group>"; };
AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRFieldPathTests.m; sourceTree = "<group>"; };
AB7BAB332012B519001E0872 /* geo_point_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = geo_point_test.cc; path = ../../core/test/firebase/firestore/geo_point_test.cc; sourceTree = "<group>"; };
AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRCollectionReferenceTests.m; sourceTree = "<group>"; };
AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRSnapshotMetadataTests.m; sourceTree = "<group>"; };
AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentSnapshotTests.m; sourceTree = "<group>"; };
Expand All @@ -258,6 +261,7 @@
ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = "<group>"; };
ABF341011FE858B500C48322 /* FSTAPIHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTAPIHelpers.h; sourceTree = "<group>"; };
ABF341021FE8593500C48322 /* FSTAPIHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FSTAPIHelpers.m; sourceTree = "<group>"; };
ABF6506B201131F8005F2C74 /* timestamp_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = timestamp_test.cc; sourceTree = "<group>"; };
B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = "<group>"; };
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -415,6 +419,7 @@
54764FAD1FAA0C650085E60A /* Port */,
54740A561FC913EB00713A1A /* util */,
54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */,
AB7BAB332012B519001E0872 /* geo_point_test.cc */,
);
name = GoogleTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -548,6 +553,7 @@
isa = PBXGroup;
children = (
AB356EF6200EA5EB0089B766 /* field_value_test.cc */,
ABF6506B201131F8005F2C74 /* timestamp_test.cc */,
);
name = model;
path = ../../core/test/firebase/firestore/model;
Expand Down Expand Up @@ -1251,6 +1257,7 @@
54764FAB1FAA0C320085E60A /* string_util_test.cc in Sources */,
54E9282C1F339CAD00C1953E /* XCTestCase+Await.m in Sources */,
AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */,
AB7BAB342012B519001E0872 /* geo_point_test.cc in Sources */,
DE51B1DF1F0D490D0013853F /* FSTMemoryMutationQueueTests.m in Sources */,
DE51B1F31F0D491B0013853F /* FSTDatastoreTests.m in Sources */,
DE51B1D01F0D48CD0013853F /* FSTQueryTests.m in Sources */,
Expand All @@ -1266,6 +1273,7 @@
AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */,
DE51B1E31F0D490D0013853F /* FSTPersistenceTestHelpers.m in Sources */,
AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */,
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */,
DE51B1CF1F0D48CD0013853F /* FSTQueryListenerTests.m in Sources */,
DE51B1DA1F0D490D0013853F /* FSTLevelDBLocalStoreTests.m in Sources */,
DE51B1FA1F0D492C0013853F /* FSTLevelDBSpecTests.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

add_subdirectory(src/firebase/firestore)
add_subdirectory(src/firebase/firestore/model)
add_subdirectory(src/firebase/firestore/remote)
add_subdirectory(src/firebase/firestore/util)

add_subdirectory(test/firebase/firestore)
add_subdirectory(test/firebase/firestore/model)
add_subdirectory(test/firebase/firestore/remote)
add_subdirectory(test/firebase/firestore/util)
89 changes: 89 additions & 0 deletions Firestore/core/include/firebase/firestore/geo_point.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2018 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_CORE_INCLUDE_FIREBASE_FIRESTORE_GEO_POINT_H_
#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_GEO_POINT_H_

namespace firebase {
namespace firestore {

/**
* An immutable object representing a geographical point in Firestore. The point
* is represented as a latitude/longitude pair.
*
* Latitude values are in the range of [-90, 90].
* Longitude values are in the range of [-180, 180].
*/
class GeoPoint {
public:
/**
* Creates a `GeoPoint` with both latitude and longitude being 0.
*/
GeoPoint();

/**
* Creates a `GeoPoint` from the provided latitude and longitude degrees.
*
* @param latitude The latitude as number between -90 and 90.
* @param longitude The longitude as number between -180 and 180.
*/
GeoPoint(double latitude, double longitude);

GeoPoint(const GeoPoint& other) = default;
GeoPoint(GeoPoint&& other) = default;
GeoPoint& operator=(const GeoPoint& other) = default;
GeoPoint& operator=(GeoPoint&& other) = default;

double latitude() const {
return latitude_;
}

double longitude() const {
return longitude_;
}

private:
double latitude_;
double longitude_;
};

/** Compares against another GeoPoint. */
bool operator<(const GeoPoint& lhs, const GeoPoint& rhs);

inline bool operator>(const GeoPoint& lhs, const GeoPoint& rhs) {
return rhs < lhs;
}

inline bool operator>=(const GeoPoint& lhs, const GeoPoint& rhs) {
return !(lhs < rhs);
}

inline bool operator<=(const GeoPoint& lhs, const GeoPoint& rhs) {
return !(lhs > rhs);
}

inline bool operator!=(const GeoPoint& lhs, const GeoPoint& rhs) {
return lhs < rhs || lhs > rhs;
}

inline bool operator==(const GeoPoint& lhs, const GeoPoint& rhs) {
return !(lhs != rhs);
}

} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_GEO_POINT_H_
22 changes: 22 additions & 0 deletions Firestore/core/src/firebase/firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2018 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.

# Public types to be used both internally and externally.
cc_library(
firebase_firestore_types
SOURCES
geo_point.cc
DEPENDS
firebase_firestore_util
)
50 changes: 50 additions & 0 deletions Firestore/core/src/firebase/firestore/geo_point.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018 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/core/include/firebase/firestore/geo_point.h"

#include <math.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like any of these headers are used (besides firebase_assert)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnan in math.h. The other std library is not used and removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry missed that.


#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"

namespace firebase {
namespace firestore {

GeoPoint::GeoPoint() : GeoPoint(0, 0) {
}

GeoPoint::GeoPoint(double latitude, double longitude)
: latitude_(latitude), longitude_(longitude) {
FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
!isnan(latitude) && -90 <= latitude && latitude <= 90,
-90 <= latitude && latitude <= 90,
"Latitude must be in the range of [-90, 90]");
FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
!isnan(longitude) && -180 <= longitude && longitude <= 180,
-180 <= longitude && longitude <= 180,
"Latitude must be in the range of [-180, 180]");
}

bool operator<(const GeoPoint& lhs, const GeoPoint& rhs) {
if (lhs.latitude() == rhs.latitude()) {
return lhs.longitude() < rhs.longitude();
} else {
return lhs.latitude() < rhs.latitude();
}
}

} // namespace firestore
} // namespace firebase
2 changes: 2 additions & 0 deletions Firestore/core/src/firebase/firestore/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ cc_library(
firebase_firestore_model
SOURCES
field_value.cc
timestamp.cc
DEPENDS
firebase_firestore_util
firebase_firestore_types
)
Loading