FIRDocumentChange.mm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2017 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 "Firestore/Source/API/FIRDocumentChange+Internal.h"
  17. #import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
  18. #include "Firestore/core/src/firebase/firestore/api/document_change.h"
  19. #include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
  20. using firebase::firestore::api::DocumentChange;
  21. NS_ASSUME_NONNULL_BEGIN
  22. @implementation FIRDocumentChange {
  23. DocumentChange _documentChange;
  24. }
  25. - (instancetype)initWithDocumentChange:(DocumentChange &&)documentChange {
  26. if (self = [super init]) {
  27. _documentChange = std::move(documentChange);
  28. }
  29. return self;
  30. }
  31. - (BOOL)isEqual:(nullable id)other {
  32. if (other == self) return YES;
  33. if (![other isKindOfClass:[FIRDocumentChange class]]) return NO;
  34. FIRDocumentChange *change = (FIRDocumentChange *)other;
  35. return _documentChange == change->_documentChange;
  36. }
  37. - (NSUInteger)hash {
  38. return _documentChange.Hash();
  39. }
  40. - (FIRDocumentChangeType)type {
  41. switch (_documentChange.type()) {
  42. case DocumentChange::Type::Added:
  43. return FIRDocumentChangeTypeAdded;
  44. case DocumentChange::Type::Modified:
  45. return FIRDocumentChangeTypeModified;
  46. case DocumentChange::Type::Removed:
  47. return FIRDocumentChangeTypeRemoved;
  48. }
  49. HARD_FAIL("Unknown DocumentChange::Type: %s", _documentChange.type());
  50. }
  51. - (FIRQueryDocumentSnapshot *)document {
  52. return [[FIRQueryDocumentSnapshot alloc] initWithSnapshot:_documentChange.document()];
  53. }
  54. - (NSUInteger)oldIndex {
  55. return _documentChange.old_index();
  56. }
  57. - (NSUInteger)newIndex {
  58. return _documentChange.new_index();
  59. }
  60. @end
  61. NS_ASSUME_NONNULL_END