converters.mm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "Firestore/Source/API/converters.h"
  17. #include <utility>
  18. #import "FIRGeoPoint.h"
  19. #import "FIRTimestamp.h"
  20. #include "Firestore/Source/API/FIRDocumentReference+Internal.h"
  21. #include "Firestore/core/include/firebase/firestore/geo_point.h"
  22. #include "Firestore/core/include/firebase/firestore/timestamp.h"
  23. #include "Firestore/core/src/api/firestore.h"
  24. #include "Firestore/core/src/model/document_key.h"
  25. NS_ASSUME_NONNULL_BEGIN
  26. namespace firebase {
  27. namespace firestore {
  28. namespace api {
  29. GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point) {
  30. return GeoPoint(geo_point.latitude, geo_point.longitude);
  31. }
  32. FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point) {
  33. return [[FIRGeoPoint alloc] initWithLatitude:geo_point.latitude()
  34. longitude:geo_point.longitude()];
  35. }
  36. Timestamp MakeTimestamp(FIRTimestamp* timestamp) {
  37. return Timestamp(timestamp.seconds, timestamp.nanoseconds);
  38. }
  39. Timestamp MakeTimestamp(NSDate* date) {
  40. FIRTimestamp* timestamp = [FIRTimestamp timestampWithDate:date];
  41. return MakeTimestamp(timestamp);
  42. }
  43. FIRTimestamp* MakeFIRTimestamp(const Timestamp& timestamp) {
  44. return [[FIRTimestamp alloc] initWithSeconds:timestamp.seconds()
  45. nanoseconds:timestamp.nanoseconds()];
  46. }
  47. FIRDocumentReference* MakeFIRDocumentReference(const model::DocumentKey& key,
  48. std::shared_ptr<Firestore> firestore) {
  49. return [[FIRDocumentReference alloc] initWithKey:key firestore:std::move(firestore)];
  50. }
  51. } // namespace api
  52. } // namespace firestore
  53. } // namespace firebase
  54. NS_ASSUME_NONNULL_END