FIRSnapshotMetadata.mm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "FIRSnapshotMetadata.h"
  17. #include <utility>
  18. #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
  19. #include "Firestore/core/src/api/snapshot_metadata.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @implementation FIRSnapshotMetadata {
  22. api::SnapshotMetadata _metadata;
  23. }
  24. - (instancetype)initWithMetadata:(api::SnapshotMetadata)metadata {
  25. if (self = [super init]) {
  26. _metadata = std::move(metadata);
  27. }
  28. return self;
  29. }
  30. - (instancetype)initWithPendingWrites:(bool)pendingWrites fromCache:(bool)fromCache {
  31. api::SnapshotMetadata wrapped(pendingWrites, fromCache);
  32. return [self initWithMetadata:std::move(wrapped)];
  33. }
  34. // NSObject Methods
  35. - (BOOL)isEqual:(nullable id)other {
  36. if (other == self) return YES;
  37. if (![other isKindOfClass:[FIRSnapshotMetadata class]]) return NO;
  38. FIRSnapshotMetadata *otherMetadata = other;
  39. return _metadata == otherMetadata->_metadata;
  40. }
  41. - (NSUInteger)hash {
  42. return _metadata.Hash();
  43. }
  44. - (BOOL)hasPendingWrites {
  45. return _metadata.pending_writes();
  46. }
  47. - (BOOL)isFromCache {
  48. return _metadata.from_cache();
  49. }
  50. @end
  51. NS_ASSUME_NONNULL_END