-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
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 176975a
refactoring to use union type instead of poly
zxu123 b75cb7e
refactor using union design intead of poly
zxu123 f1bb0f4
refactoring to use anonymous union and fix styles
zxu123 adf7a6b
small fix
zxu123 11a03f6
add field_value_test to the project
zxu123 c5728e4
Merge branch 'master' into cpp/fieldvalue
zxu123 9630117
fix warning of cmake and fix style
zxu123 7defa1f
Implement number and string FieldValue.
zxu123 1371191
Implement object FieldValue.
zxu123 1694745
implement timestamp FieldValue
zxu123 0a854c6
Implement number and string FieldValue.
zxu123 b2ff448
Merge branch 'cpp/fieldvaluesss' of https://github.com/firebase/fireb…
zxu123 5cf366b
implement public type `Blob` and `GeoPoint`
zxu123 ef2d431
implement Blob FieldValue
zxu123 bc73829
Implement GeoPoint FieldValue
zxu123 0581290
Merge branch 'master' into cpp/fieldvaluesss
zxu123 2fae448
refactoring `Blob`
zxu123 388524c
utilize util/comparison.h
zxu123 af21081
Merge branch 'cpp/fieldvaluesss' of https://github.com/firebase/fireb…
zxu123 2244090
fix style and some small change
zxu123 0605a4d
address changes
zxu123 4011465
address changes
zxu123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isnan
inmath.h
. The other std library is not used and removed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry missed that.