converters.mm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #import <FirebaseCore/FIRTimestamp.h>
  17. #include <utility>
  18. #include "Firestore/Source/API/converters.h"
  19. #import "FIRGeoPoint.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. #import "Firestore/core/src/api/listen_source.h"
  25. #include "Firestore/core/src/model/document_key.h"
  26. NS_ASSUME_NONNULL_BEGIN
  27. namespace firebase {
  28. namespace firestore {
  29. namespace api {
  30. GeoPoint MakeGeoPoint(FIRGeoPoint* geo_point) {
  31. return GeoPoint(geo_point.latitude, geo_point.longitude);
  32. }
  33. FIRGeoPoint* MakeFIRGeoPoint(const GeoPoint& geo_point) {
  34. return [[FIRGeoPoint alloc] initWithLatitude:geo_point.latitude()
  35. longitude:geo_point.longitude()];
  36. }
  37. Timestamp MakeTimestamp(FIRTimestamp* timestamp) {
  38. return Timestamp(timestamp.seconds, timestamp.nanoseconds);
  39. }
  40. Timestamp MakeTimestamp(NSDate* date) {
  41. FIRTimestamp* timestamp = [FIRTimestamp timestampWithDate:date];
  42. return MakeTimestamp(timestamp);
  43. }
  44. FIRTimestamp* MakeFIRTimestamp(const Timestamp& timestamp) {
  45. return [[FIRTimestamp alloc] initWithSeconds:timestamp.seconds()
  46. nanoseconds:timestamp.nanoseconds()];
  47. }
  48. FIRDocumentReference* MakeFIRDocumentReference(const model::DocumentKey& key,
  49. std::shared_ptr<Firestore> firestore) {
  50. return [[FIRDocumentReference alloc] initWithKey:key firestore:std::move(firestore)];
  51. }
  52. ListenSource MakeListenSource(const FIRListenSource& source) {
  53. switch (source) {
  54. case FIRListenSourceDefault:
  55. return ListenSource::Default;
  56. case FIRListenSourceCache:
  57. return ListenSource::Cache;
  58. default:
  59. return ListenSource::Default;
  60. }
  61. }
  62. } // namespace api
  63. } // namespace firestore
  64. } // namespace firebase
  65. NS_ASSUME_NONNULL_END